Skip to content

Instantly share code, notes, and snippets.

@0xnbk
0xnbk / natsort.php
Created August 7, 2010 09:22
natsort()
<?php
$items = array(
"100 apples", "5 apples", "110 apples", "55 apples"
);
// normal sorting:
sort($items);
print_r($items);
# Outputs:
# Array
@0xnbk
0xnbk / glob.php
Created August 7, 2010 09:26
glob()
<?php
foreach (glob("*.php") as $file)
echo "$file\n";
?>
@0xnbk
0xnbk / gchat.py
Created August 7, 2010 15:34
catch invisible friends on gtalk
#gtalk.py
import xmpp
# Google Talk constants
FROM_GMAIL_ID = "username@gmail.com"
GMAIL_PASS = "secret passwd"
GTALK_SERVER = "gmail.com"
jid=xmpp.protocol.JID(FROM_GMAIL_ID)
require 'net/http'
require 'uri'
# /api/v1/:format/new
# /api/v1/:format/gists/:user
# /api/v1/:format/:gist_id
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'),
{ 'files[file1.ab]' => 'CONTNETS',
'files[file2.ab]' => 'contents' })
@0xnbk
0xnbk / Target blank links Jquery.js
Created September 13, 2010 04:12
Target blank links
@0xnbk
0xnbk / jquery_tips.js
Created September 13, 2010 04:14
Get the total number of matched elements
$('element').size();
@0xnbk
0xnbk / preload_images.js
Created September 13, 2010 04:14
Preloading images
jQuery.preloadImages = function()
{
for(var i = 0; i").attr("src", arguments[i]);
}
};
// Usage
$.preloadImages("image1.gif", "/path/to/image2.png", "some/image3.jpg");
@0xnbk
0xnbk / detect_browser.js
Created September 13, 2010 04:15
Detect browser
//A. Target Safari
if( $.browser.safari ) $("#menu li a").css("padding", "1em 1.2em" );
//B. Target anything above IE6
if ($.browser.msie && $.browser.version > 6 ) $("#menu li a").css("padding", "1em 1.8em" );
//C. Target IE6 and below
if ($.browser.msie && $.browser.version <= 6 ) $("#menu li a").css("padding", "1em 1.8em" );
//D. Target Firefox 2 and above
@0xnbk
0xnbk / remove_word.js
Created September 13, 2010 04:16
Remove a word in a text
var el = $('#id');
el.html(el.html().replace(/word/ig, ""));
@0xnbk
0xnbk / equal_height_columns.js
Created September 13, 2010 04:17
Columns of equal height
function equalHeight(group) {
tallest = 0;
group.each(function() {
thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
}