I Scheduler…

October 31, 2008 | Filed Under Linux | No Comments

In these days at work we’ve some trouble with a very slow PostgreSql Server… We need something like a Thread Pool.. but we couln’t modify the Server that call Postgres.
My Idea, that increase, in our case, more than 50% the response speed is to “limit” the postgres (postmaster for 7.4) instances.

This morning i’ve writed this PsLimit Source that do my “Scheduler” Job.

Usage:

pslimit <process name> <max number of instances>

Usage Example:

  • Only 3 instances of postgres can run at the same time, the other will be queued
    • pslimit postgres 3 (Postgres 8.x)
    • pslimit postmaster 3  (Postgres 7.x)

Qt Centre Programming Contest 2008 – Finalists

October 26, 2008 | Filed Under Qt4 | No Comments

W00t Quartica is one of the Six finalist projects at Qt Centre Programming Contest 2008.

Qt Centre Programming Contest 2008 - Finalists

Qt Centre Programming Contest 2008 - Finalists

It’s already a great success for me to be in the finalists list! I’ve learned so much from the Quartica Development and many new features and ideas are already in development to have (not so soon… due to expansive “Real” Work) in the next First (non alpha) release of the Project.

Thanks Trolls!

Cocoa: System StatusBar Item (Aka TrayBar)

October 26, 2008 | Filed Under Cocoa | 4 Comments

Today’s example is “How to add your own Item inside System Status Bar“. It’s really easy but the Apple OS X Human Interface Guidelines discourage it, at the end of the post you can find the Apple HIG notes.

Cocoa System Status Bar

Cocoa System Status Bar

Something about Names… Apple HIG call this MenuBar part “MenuBar Extra” (See Apple HIG Part III – The Menu Bar and Its Menus) using Cocoa you can get it from NSStatusBar systemStatusBar.

Continue reading Cocoa: System StatusBar Item (Aka TrayBar)…

Cocoa: Image Pattern as NSView Background

October 25, 2008 | Filed Under Cocoa | No Comments

I Really like Apple Mail Note Editor, and today I’ve tried to do something like notes of Mail.app

Mail uses html and css loaded into a WebView (WebKit) to render the background of the window. I’ve used a simple NSView, I’ve Inherited from it and I’ve added a couple of feature to render an image as background pattern. Below you can see the result and here you can Download the Source.

NSWindow with Image Pattern as Background

NSWindow with Image Pattern as Background

Late 2008: MacBooks and LED Cinema Display

October 17, 2008 | Filed Under Apple | No Comments

I think that there’re nothing else to say, this photo describe itself. Another interesting thing is the MacBook video (that you can find here http://www.apple.com/macbook/the-new-macbook/) with Jony Ive.

Late 2008 MacBook with CinemaDisplay

Late 2008 MacBook with Cinema Display

Cocoa: Notification Badge

October 11, 2008 | Filed Under Cocoa | 2 Comments

I Really like iPhone notifications… a little badge appears on the application’s icon and displays something. For example in Apple Mail it displays the number of the unread mails.

Now the Code! a simple method that take an argument that is the number to show on the badge. (IMPORTANT: Take a look at the code, there’re appIcon.tiff and starIcon.tiff that you should have in your Project’s Resources).

-(void)showNotifyCountOnApplicationIcon: (int) currentCountOfUnread
{
  NSImage *originalIcon = [NSImage imageNamed:@"appIcon.tiff"];
  NSString *countdown = [NSString stringWithFormat:@"%i", currentCountOfUnread];
  NSImage *iconImageBuffer = [originalIcon copy];
  NSSize iconSize = [originalIcon size];

  // Create attributes for drawing the count.
  NSDictionary * attributes = [[NSDictionary alloc]
       initWithObjectsAndKeys:[NSFont fontWithName:@"Helvetica-Bold" size:32],
       NSFontAttributeName, [NSColor whiteColor],
       NSForegroundColorAttributeName, nil];
  NSSize numSize = [countdown sizeWithAttributes:attributes];

  // Create a red circle in the icon large enough to hold the count.
  [iconImageBuffer lockFocus];
  [originalIcon drawAtPoint:NSMakePoint(0, 0)
                    fromRect:NSMakeRect(0, 0, iconSize.width, iconSize.height)
                    operation:NSCompositeSourceOver
                    fraction:1.0f];

  float max = (numSize.width > numSize.height) ? numSize.width : numSize.height;
  max += 28;
  NSRect circleRect = NSMakeRect(iconSize.width - max,
                                 iconSize.height - max, max, max);

  // Draw the star image and scale it so the unread count will fit inside.
  NSImage * starImage = [NSImage imageNamed:@"starIcon.tiff"];
  [starImage setScalesWhenResized:YES];
  [starImage setSize:circleRect.size];
  [starImage compositeToPoint:circleRect.origin operation:NSCompositeSourceOver];

  // Draw the count in the red circle
  NSPoint point = NSMakePoint(NSMidX(circleRect) - numSize.width / 2.0f + 2.0f,
                            NSMidY(circleRect) - numSize.height / 2.0f + 2.0f);
  [countdown drawAtPoint:point withAttributes:attributes];

  // Now set the new app icon and clean up.
  [iconImageBuffer unlockFocus];
  [NSApp setApplicationIconImage:iconImageBuffer];
  [iconImageBuffer release];
  [attributes release];
}

With Mac OS X Leopard was introduced NSDockTile class that lets you customize the visual representation for your application’s miniaturized windows and application icon as they appear in the dock. So with this class you can easily add Notification Badge in this way.

   NSDockTile *dockTile = [NSApp dockTile];

   // setup our image view for the dock tile
   NSRect frame = NSMakeRect(0, 0, dockTile.size.width, dockTile.size.height);
   NSImageView *dockImageView = [[NSImageView alloc] initWithFrame: frame];
   [dockImageView setImage: [NSImage imageNamed:@"appIcon.tiff"]];

   // by default, add it to the NSDockTile
   [dockTile setContentView: dockImageView];
   [dockTile display];

   // Show Notification Badge '45'
   [dockTile setShowsApplicationBadge:YES];
   [dockTile setBadgeLabel:@"45"];