Skip to content

Instantly share code, notes, and snippets.

@gleecology
gleecology / ex.postMessage.js
Created October 16, 2013 22:09
demo of postMessage() for resolving CORS.
# HOW-TO: cross-domain communication with postmessage
## with iframes, CORS is a pita, this works instead
window parent is on foo.com:
var iframeHost = 'http://bar.com',
@gleecology
gleecology / OpenRTB.pm
Created August 2, 2013 06:37
Open RTB metadata. Extracted, parsed, massaged (not much tho') as of Nov. 2012.
our(%Type,%Enum);
use constant {
str => '',
int => '',
float => '',
array => '',
# find a message in skype DB yo
# usage:
# skype_grep hello%world
# skype_grep hello%world -i << case insensitive
# skype_grep | cat -n << all msgs.
# skype_grep | grep 'Group Name' | less << all msgs in a particular chat
#
# main.db found on macos at Library/Application Support/Skype/<skype_username>
TARGET='body_xml'
[ $2 ] && TARGET='LOWER(body_xml)'
@gleecology
gleecology / git-log-json.pl
Created February 28, 2013 14:25
git log as json --with status msg FTW
#!/usr/bin/env perl
use common::sense;
use JSON::XS;
my @msg;
my $cmd = qq! git log --name-status --pretty=format:'{ \"sha\":\"%h\", \"commit\": \"%H\", \"author\": \"%an <%ae>\", \"date\": \"%ad\",\"message\": \"%s\",\"timestamp\":%at }'!;
my $fh;
@gleecology
gleecology / furballs.sql
Created December 5, 2012 21:43
postgres import/export
create table furballs ( name varchar, data OID);
insert into furballs values('aaa', lo_import('/tmp/blah.tgz'));
select * from furballs;
select lo_export(furballs.data, '/tmp/aaa.tgz') from furballs where name = 'aaa';
-- md5sum /tmp/*.tgz <-- are they the same?
@gleecology
gleecology / ga_track_hacks.js
Created December 5, 2012 18:26
GA tracking hacks
<!-- source: http://news.ycombinator.com/item?id=4876221 -->
<!-- Async Tracking Code - http://code.google.com/intl/en-US/apis/analytics/docs/tracking/asyncTracking.html -->
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'YOUR ANALYTICS ID GOES HERE']);
_gaq.push(['_trackPageview']);
//*******************
// Trick #1: Track page load time in Google Analytics
// (note: only works for HTML5 browsers)
@gleecology
gleecology / ipv4_cidr.pl
Created November 15, 2012 00:49
ipv4 cidr to block in perl; yet another calculator
#!/bin/env perl
use strict;
use warnings;
sub cidr($) { (2**(32- shift) ) };
sub dec2ip($) {
join '.', unpack 'C4' => pack 'N' => shift;
}
@gleecology
gleecology / bench.hash_inits.pl
Created September 26, 2012 18:33
Perl bench Q: fastest hash init?
# Q: what is the fastest way to init. hash vars?
# $^ = 5.14.2
use Benchmark qw(:all) ;
my $op_x = sub {
my %r = (
foo => 100,
bar => 101,
);
@gleecology
gleecology / gist:3758770
Created September 20, 2012 22:35 — forked from phillro/gist:1126799
Easy Document Searching with Jquery, jquery-templates and Elastic Search
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
<script id="searchResultTemplate" type="text/x-jquery-tmpl">
{{each(i,result) hits}}
@gleecology
gleecology / UPDATE_GIT.sh
Created September 19, 2012 17:53
Git 'er done
#!/bin/bash
# this lives wherever all your repos are; eg. ~/sandbox
#
D=`date`;
LOG=LOG.git_update
echo "============update $D==============" |tee -a $LOG;
for i in `ls`; do