DIY Snoot from Pringles can

July 4th, 2010

Here’s a simple way to make a snoot. Pressure fits on Nikon SB-25 (SB-24, SB-26 and so on) and Canon 580EX (430EX, etc) probably others as well.

What you need:

1 x Pringles can (wash it and dry before proceeding)
1 x Electrical tape

Optional:
1 x Transparent scotch tape

Read the rest of this entry »

Take a screenshot over ssh in leopard

June 22nd, 2010

First you need to get PID of the login window:

ps ax | grep [l]oginwindow

this gives you something like
26 ?? Ss 10:23.68 loginwindow.app/Contents/MacOS/loginwindow

where 26 is the PID

then get the actual screenshot:

sudo launchctl bsexec PID screencapture [options]

and voila! in fact you can set up a crontab to take screenshots remotely at specific periods

Time your PHP functions

June 22nd, 2010

this code will let you time your function in microseconds, am too lazy to write more comments, but you can play around.
have fun.

Read the rest of this entry »

Recursively parse a directory and mark new or recently changed directories

June 20th, 2010

This script is particularly useful if you’re building any kind of web app that requires directory tree with sub directories/files and requires to mark directories containing new files or with files recently removed as such.
I also wrote this function for my gallery

This specific example grabs only jpegs

Read the rest of this entry »

.clonePosition for $jQuery (from prototype.js)

June 20th, 2010

So I was converting my gallery to jQuery. But I found that $jq doesn’t have the nifty .clonePosition() that Prototype does. so here’s a little plugin:
(save it as jquery.cloneposition.js and do a standard include)

(function($){
  $.fn.clonePosition = function(element, options){
	var options = $.extend({
		setLeft : true,
		setTop  : true,
		setWidth: false,
		setHeight: false,
		offsetLeft: 0,
		offsetTop: 0
	}, (options || {}));

	var el = $(this); //what to position
	var src = $(element); //where to position
	var offsets = el.offset();
	var p = [src.offset().left, src.offset().top];
	var delta = [0, 0];
	//difference in size between element and source (to align centers, not top-left corners)
	var delta_size =[0, 0];
	var parent = null;

	if(el.css('position') == 'absolute') {
		d = el.offset();//relative to the parent
		delta[0]=d.left;
		delta[1]=d.top;
	}
	//use outer width to account for borders and padding
	delta_size[0] = (el.outerWidth()-src.outerWidth())/2;
	delta_size[1] = (el.outerHeight()-src.outerHeight())/2;

	if(parent == document.body){
		delta[0] -= document.body.offsetLeft;
		delta[1] -= document.body.offsetTop;
	}

	if(options.setLeft)   el.css('left',(p[0] - delta[0] + options.offsetLeft - delta_size[0]) + 'px');
	if(options.setTop)    el.css('top', (p[1] - delta[1] + options.offsetTop - delta_size[1]) + 'px');
	if(options.setWidth)  el.width(src.width() + 'px');
	if(options.setHeight) el.height(src.height() + 'px');
	
	return el;
  }
})(jQuery);

Download here