The wikipedia article about Law of Demeter says:
The law can be stated simply as "use only one dot".
However a simple example of a fluent interface may look like this:
static void Main(string[] args)
{
new ZRLabs.Yael.Pipeline("cat.jpg")
.Rotate(90)
.Watermark("Monkey")
.RoundCorners(100, Color.Bisque)
.Save("test.png");
}
So does this goes together?
I'd like to add a custom UIToolbar to my UIViewController. In Interface Builder I add the uitoolbar at the top of my view, and it looks just fine. However, when I run the app in the Simulator it gets hidden by the default iphone bar (this one with the clock, battery status, etc.).
Here you can see how it looks like:
Any ideas?
Hey guys, I'm solving one task and I need to create a piece of CSS what would apply only in Safari, NOT the other WebKit browser (mustn't apply in Chrome, f.e.). Please, could anyone toss in some ideas?
Hello,
I started to learn using Instrument, but I cannot figure it out.
After I start my application, the UI shows up, I do nothing and after few seconds I can see memory leak detected:
When I have a look at the second leak I can see the following stack:
When I double click on the cell related to my code I can see that it is pointing to the following line of code:
[window addSubview:newPostUIViewController.view];
from the method:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//creating view controller
newPostUIViewController = [[NewPostUIViewController alloc] initWithNibName:@"NewPostView" bundle:nil];
newPostUIViewController.title = @"Post it!";
[window addSubview:newPostUIViewController.view];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
I wonder, how this can be a reason of a leak? I release newPostUIViewController in the dealloc method of PostItAppDelegate class.
Any ideas how this could be explained?
At MSDN page for Stopwatch class I discovered link to interesting article which makes following statement about Stopwatch:
However there are some serious issues:
This can be unreliable on a PC with multiple processors. Due to a bug in
the BIOS, Start() and Stop() must be executed on the same processor to get
a correct result.
This is unreliable on processors that do not have a constant clock
speed (most processors can reduce the clock speed to conserve
energy). This is explained in detail here.
I am little confused. I've seen tons of examples of using Stopwatch and nobody mention this drawbacks. How serious is this? Should I avoid using Stopwatch?
I'm wondering whether methods of PHPs SPLFileObject are atomic (e.g. thread-safe) or not?
If they aren't, I'll implement my own class, which will use flock(), but is this enough? Is the flock function really thread-safe? What if the collision occurs after I fopen() the file, but before I flock() it?
I'm trying to research a replacement for the pathetic WIKI that comes with WSS (only wiki code it has is to create url links).
I have looked at a few but most 'replacements' I see are MOSS only? (or so it just states MOSS for requirements).
Has anyone faced this situation? What did you end up using? I would like something that I can have all in one location (not different apps, hence WSS). With LDAP / AD Integration like WSS.
Thanks appreciate any input. I would like to see ~ $3k solutions tho (nothing super expensive, hence why we don't run MOSS).
EDIT:
Anyone else have any suggestions?
EDIT2:
Actually since I haven't had much feedback (thanks to those that have). I installed mediawiki under IIS with PHP enabled, and enabled the IIS AD hack for authentication. IIS ends up prompting for authentication (user/pass) if you use a non IE browser, then it sets the $_SERVER["REMOTE_USER"] variable, and grabs some AD info (groups etc). Works rather well, only issues is the UGLY urls so far. But its fully working. Seems like a good setup. Other than having to rely on MYSQL (my company strives to be mainly SQL Server)
I have following LINQ statement and I want to rewrite it using extension methods.
from x in e
from y in e
from z in e
select new { x, z }
One possible solution is:
e.Join(e, x => 42, y => 42, (x, y) => new { x, y })
Join(e, _ => 42, z => 42, (_, z) => new { _.x, z });
However this is everything but elegant.
Do you any idea how to improve beauty of second expression?
The latest MacRuby release notes (v0.6) state that the authors have managed to get this release working with the SQLite and Nokogiri gems. However when I run sudo macgem install nokogiri I get the following errors:
ERROR: Error installing nokogiri:
extconf failed:
and then a bunch of paths followed by:
libxml2 is missing. try 'port install libxml2' or 'yum install libxml2'
/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/lib/ruby/Gems/1.9.0/gems/nokogiri-1.4.1/ext/nokogiri/extconf.rb:1:in `<main>': libxml2 is missing. try 'port install libxml2' or 'yum install libxml2' (SystemExit)
Anyone knows how to get this working? My platform is Mac OS X 10.6.3. Nokogiri normally (meaining on plain old ruby 1.8.7) installs without a problem.
I am trying to programmatically change a value of a wxRadioButton in a way the user would do it. A value change doesn't call the event corresponded to the button, and it make sense since the documentation says it clearly:
wxRadioButton::SetValue
void SetValue(const bool value)
Sets the radio button to selected or deselected status.
This does not cause a wxEVT_COMMAND_RADIOBUTTON_SELECTED event to get emitted.
So the question is how can I call an programmatically generated event for a wxRadioButton ?
I guess that it's something to do with:
wxWindow window->AddPendingEvent(wxEvent *event )
A simple example would be greatly appreciated.
There are two weird operators in C#:
the true operator
the false operator
If I understand this right these operators can be used in types which I want to use instead of a boolean expression and where I don't want to provide an implicit conversion to bool.
Let's say I have a following class:
public class MyType
{
public readonly int Value;
public MyType(int value)
{
Value = value;
}
public static bool operator true (MyType mt)
{
return mt.Value > 0;
}
public static bool operator false (MyType mt)
{
return mt.Value < 0;
}
}
So I can write the following code:
MyType mTrue = new MyType(100);
MyType mFalse = new MyType(-100);
MyType mDontKnow = new MyType(0);
if (mTrue)
{
// Do something.
}
while (mFalse)
{
// Do something else.
}
do
{
// Another code comes here.
} while (mDontKnow)
However for all the examples above only the true operator is executed. So what's the false operator in C# good for?
Note: More examples can be found here, here and here.
I have two processes: a server that should be run in background, but starts serving requests after a delay, and a client that should be started when server is ready. The server prints line containg "Acceptin connections" to its stderr when ready (server stderr is redirected to a file when running it in background).
How to delay putting server process in background until server is ready to serve requests? Alternatively, how to delay running client until server is ready?
Language: shell script (or optionally Perl).
I want to create a binary executable for a relatively simple script that would not require people to install macruby or HotCocoa. The script is here. I've understood that I want to use the --static option for the compiler and I'm using the following command:
macrubyc -o postprocessor --static postprocessor.rb
I get the following error:
ld: library not found for -lLLVMBitWriter
collect2: ld returned 1 exit status
Error when executing `/usr/bin/g++ -o "postprocessor" -arch x86_64 -L/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/lib -lmacruby-static -L/usr/local/lib -lpthread -lffi -lm -lLLVMBitWriter -lLLVMX86CodeGen -lLLVMX86Info -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMJIT -lLLVMExecutionEngine -lLLVMCodeGen -lLLVMScalarOpts -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMCore -lLLVMSupport -lLLVMSystem -lpthread -ldl -lxml2 -lobjc -lauto -licucore -framework Foundation "/var/folders/wU/wUGgoG1JGeKBgwalWLPMAU+++TI/-Tmp-/main-72203.o" "./postprocessor.o"'
What should I do to get this running?
I have an UITableViewController which I would like to add UIToolbar to with one button. In the
- (void)viewDidLoad;
method of UITableViewController I have:
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(pressButton1:)];
self.navigationItem.title = @"Some title";
self.navigationItem.leftBarButtonItem = button;
}
Unfortunately I don't see the toolbar when I run my app.
Any hints? Should I do something more?
What were the reason for chosing Mercurial as a basis of FogCreek Kiln, a source control management system with tightly integrated code review, and FogBugz integration?
Why Mercurial, and not other (distributed) version control system, like Bazaar, Git or Monotone, or creating own version control system like Fossil (distributed software configuration management, including bug tracking and wiki) did?
What were features that make FogCreek choose Mercurial as Kiln engine?
Hi guys, I'm just learning some basic programming in Objective C and Cocoa. I'm trying to get some data from NSTableView. Based on what I read in one tutorial, I wrote this:
NSArray * items = [[itemsTableView selectedRowEnumerator] allObjects];
But then I learned that selectedRowEnumerator was deprecated already in 10.3 Panther and that I should use selectedRowIndexes.
The problem is, I didn't find how to actually use the returned NSIndexSet to achieve the same result as with code written above.
So, If anyone could give me a tip, I would be very grateful. Thanks.
Does anyone know of a way to chain the proprietary filter properties in CSS.
For example I have a div.example and I want to give it a background gradient and a drop shadow. So I'd like to do something like this:
div.example {
/* gradient */
filter: progid:DXImageTransform.Microsoft.Gradient(startColorstr=#cb141e78,endColorstr=#cb1dde78);
/* shadow */
filter: progid:DXImageTransform.Microsoft.dropShadow(color=00143c, offX=0, offY=3, positive=true);
}
Except this will of course leave only the drop shadow. Anyone know a good workaround?
There are three assembly version attributes. What are differences? Is it ok if I use AssemblyVersion and ignore the rest?
MSDN says:
AssemblyVersion:
Specifies the version of the assembly being attributed.
AssemblyFileVersion:
Instructs a compiler to use a specific version number for the Win32 file version resource. The Win32 file version is not required to be the same as the assembly's version number.
AssemblyInformationalVersion:
Defines additional version information for an assembly manifest.
This is follow up to What are the best practices for using Assembly Attributes?
Hello,
I try to understand the memory management in ObjectiveC and still some things are a misery for me.
I've got an instance variable:
NSMutableArray *postResultsArray;
when a button is clicked in the UI I create new array:
self.postResultsArray = [NSMutableArray array];
then I add some objects to the array and when the whole operation is done I would like to release the array:
[self.postResultsArray release];
(I assume that all the objects stoed in the array will be released along with the array).
The problem appears when I click the button again and in the code I want to create the array again with:
self.postResultsArray = [NSMutableArray array];
I get:
[CFArray release]: message sent to deallocated instance 0x3d9e390
Can't I initialize the same instance variable for the second time? or maybe I should not release it? and if so, why?
Thanks!
I have structs templated by int derived from a Base struct.
struct Base { int i; double d; };
template< int N > struct Derv : base { static const int mN = N; };
I need to make an array of Derv< N where N can vary for each struct in that array. I know C/C++ does not allow arrays of objects of different types, but is there a way around this? I was thinking of separating the type information somehow (hints like pointers to Base struct or usage of union spring to my mind, but with all of these I don't know how to store the type information of each array element for usage DURING COMPILE TIME). As you can see, the memory pattern of each Derv< N is the same.
I need to access the type of each array element for template specialization later in my code. The general aim of this all is to have a compile-time dispatch mechanism without the need to do a runtime "type switch" somewhere in the code.
Thank you.
Hello,
I have a view with a toolbar at the top and a table view with text fields in it's cells. When I want to edit the text fields placed in the bottom of the table view the keyboard is hiding the text field being edited (as the table view is not scrolled up).
I tried to implement http://cocoawithlove.com/2008/10/sliding-uitextfields-around-to-avoid.html but this makes my whole view move up (the toolbar and the table view) while I would like to have the toobar at the top of the view for the whole time.
I modified the mentioned code to something like this:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
CGRect textFieldRect = [tableView.window convertRect:textField.bounds fromView:textField];
CGRect viewRect = [tableView.window convertRect:tmpTableView.bounds fromView:tableView];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator = (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) * viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0) {
heightFraction = 0.0;
} else if (heightFraction > 1.0) {
heightFraction = 1.0;
}
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
} else {
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
CGRect viewFrame = tableView.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[tableView setFrame:viewFrame];
[UIView commitAnimations];
}
and
- (void)textFieldDidEndEditing:(UITextField *)textField {
CGRect viewFrame = tableView.frame;
viewFrame.origin.y += animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[tableView setFrame:viewFrame];
[UIView commitAnimations];
}
This made my toolbar stay at the top, but unfortunately the table view overlays the toolbar and the toolbar is not visible.
Any ideas how to solve this?
I'm writing an app for a company that uses Google Calendar internally and would need to use events they already have in their calendar in the app. So I need to get read only access to their calendars from the app (namely I need the events title, start and end dates and attendee emails for all future events).
What is the simplest way to do this in ruby (I would need it to work relatively seamlessly on Heroku)?
I tried using the GCal4Ruby gem which seemed the least outdated of the ones I found but I'm unable to even authenticate through the library (HTTPRequestFailed - Captcha required error) let alone get the info I need.