Skip to content

Instantly share code, notes, and snippets.

@kakuno
kakuno / calling ec2 api without Net::Amazon::EC2
Last active December 13, 2015 18:58
no Net::Amazon::EC2
#!/usr/bin/env perl
use strict;
use warnings;
use Digest::SHA qw(hmac_sha256);
use Furl;
use MIME::Base64;
use Time::Piece;
use URI;
use URI::Escape;
#!/usr/bin/perl
use strict;
use DBI;
use Getopt::Long;
use constant {
OK => 0,
WARNING => 1,
CRITICAL => 2,
if ( window.addEventListener ) {
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
window.addEventListener("keydown", function(e){
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 )
window.location = "http://ejohn.org/apps/hero/";
}, true);
}
@kakuno
kakuno / gist:1267498
Created October 6, 2011 14:16
portable event object
// document listener
golgo.event = {
listener: {},
__listener: {},
callback: function(type) {
return function(e) {
var listener = golgo.event.listener[type];
if (listener) {
for (var i=0,len=listener.length; i<len; i++) {
@kakuno
kakuno / gist:1193349
Created September 4, 2011 19:05
Simple JavaScript Templating
// original code
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
window.$T = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
/*
var ta = new ToggleAction({
on: function(obj) {
setClass(obj, "on");
}
off: function(obj) {
removeClass(obj);
}
});
*/
/*
var ex = new ExclusiveAction({
target: {
b1: $("button1"),
b2: $("button2"),
b3: $("button3"),
b4: $("button4")
},
activeAction: function(obj) {
// for selected obj
@kakuno
kakuno / tab control
Created November 17, 2008 10:27
tab
// require: $(), bindListener()
var Tab = function() {
this.initialize.apply(this, arguments);
}
Tab.prototype = {
prefix: "tab_",
initialize: function(opt) {
this.active = opt.active || 'active';
this.inactive = opt.inactive || 'inactive';
this.tab = opt.tab;
@kakuno
kakuno / gist:19539
Created October 24, 2008 18:28
js: correct obstructive link
(function(){
var links = document.getElementsByTagName("a");
for (var i=0,len=links.length; i<len; i++) {
try {
var link = decodeURIComponent(links[i].getAttribute('href'));
} catch(e) {
var link = links[i].getAttribute('href');
}
var urls = /^.+(http:\/\/\S+)$/.exec(link) || new Array();
if (urls[1]) {
@kakuno
kakuno / term class (javascript)
Created October 22, 2008 15:29
term class (javascript)
var Class = {
create: function(base) {
var fn = function() {
this.initialize.apply(this, arguments);
};
// inheritance
if (base)
fn.prototype = new base;
if (!fn.prototype.initialize)
fn.prototype = function(){};