Skip to content

Instantly share code, notes, and snippets.

@fredrick
fredrick / String.format.js
Created May 16, 2011 22:28
printf()/format() for JavaScript String
/*
* Extend JavaScript String object with printf() like functionality
* "{0} is dead, but {1} is alive!".format("This", "that");
*/
String.prototype.format = function() {
var formatted = this;
for(arg in arguments) {
formatted = formatted.replace("{" + arg + "}", arguments[arg]);
}
return formatted;
@fredrick
fredrick / wc.js
Created May 17, 2011 22:26
Node.js Async I/O POC [equivalent of wc -l filename]
#!/usr/bin/env node
/**
* Node.js Async I/O POC [equivalent of wc -l filename]
* Run me: node wc.js [filename]
*/
var sys = require('sys'),
fs = require('fs');
@fredrick
fredrick / flot.benchmark.js
Created May 26, 2011 15:08
Load time series data via AJAX, graph it
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'query/',
data: ({
type: 'responses',
limit: 5000,
order: 'asc'
}),
dataType: 'json',
@fredrick
fredrick / README.txt
Created June 24, 2011 17:23
An annotated guide to basic HTML.
learn.html
An annotated guide to basic HTML.
Created by Fredrick Galoso (Updated 2011-06-24)
Public domain, but I'd love some credit. Remix, add, enjoy.
<!----> Are comments.
--- pyinotify.py.orig 2011-06-26 12:57:41.000000000 +0100
+++ pyinotify.py.new6 2011-06-26 17:17:56.000000000 +0100
@@ -69,6 +69,7 @@
import re
import asyncore
import glob
+import hashlib
try:
from functools import reduce
@fredrick
fredrick / ab-varnish-t1-micro.txt
Created June 27, 2011 20:41
Apache Bench: Varnish 2.1 + nginx 1.0 on t1.micro (x64)
$ ab -n 1000 -c 250 http://ec2-xx-xx-xx-xx.compute-1.amazonaws.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking ec2-xx-xx-xx-xx.compute-1.amazonaws.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
@fredrick
fredrick / ec2-manage-snapshots.rb
Created June 28, 2011 21:21 — forked from corck/AWS - EBS Snapshot Management
Simple script for creating snapshots of an EBS volume and keeping a certain number of those
#!/usr/local/bin/ruby
require 'AWS'
require 'yaml'
class SnapshotManagement
# initalize class, optional override path to yml file
# * options [String] :path ('')
#
def initialize(params = {})
@fredrick
fredrick / gist:1082811
Created July 14, 2011 16:31 — forked from tpitale/gist:162954
MongoDB init script
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the mongodb data-store
# Description: starts mongodb using start-stop-daemon
@fredrick
fredrick / gist:1085467
Created July 15, 2011 20:15
Seat-Python, Python 3.x.x compatibility issues
# See: http://bugs.python.org/issue10976
EEEEEEE
======================================================================
ERROR: test_database_exists (__main__.testSeat)
Database exists
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.1/dist-packages/seat.py", line 86, in __send
result = json.loads(request.read())
File "/usr/lib/python3.1/json/__init__.py", line 291, in loads
@fredrick
fredrick / axe.js
Created July 21, 2011 04:23
Axe JavaScript
/**
* Inspired by http://d24w6bsrhbeh9d.cloudfront.net/photo/172219_460s.jpg
*/
function Understand() {
this.this = 'loser';
}
function A() {
this.girlfriend = true;