Skip to content

Instantly share code, notes, and snippets.

var sys = require('sys'),
http = require('http'),
redis = require("./redisclient");
var queuedRes = {}
var counter = 1;
http.createServer(function (req, res) {
pushOnQueue(req, res);
}).listen(8000);
@jedi4ever
jedi4ever / gist:955604
Created May 4, 2011 17:19
create AMI from instance with fog
>> aws_provider=Fog::Compute.new({ :region => "eu-west-1", :provider => "AWS"})
-> instance (running) = i-c1ac2bb7
>> ami=aws_provider.create_image("i-c1ac2bb7","name","description")
If not yet finished you might see
/Users/patrick/.rvm/gems/ruby-1.8.7-p330@mccloud/gems/excon-0.6.2/lib/excon/connection.rb:178:in `request':
InvalidAMIID.Unavailable => AMI 'ami-796d5b0d' is pending, and cannot be run (Fog::Service::Error)
@mndoci
mndoci / iam_fog.rb
Created May 29, 2011 03:48 — forked from zapnap/iam_fog.rb
Using Amazon IAM with Fog (example)
# via http://blog.zerosum.org/2011/03/02/better-aws-access-control-with-iam-and-fog.html
require 'fog'
username = 'testuser'
bucket = 'uniquebucketname1234'
aws_credentials = {
:aws_access_key_id => 'YOUR-ACCESS-KEY-ID',
:aws_secret_access_key => 'YOUR-SECRET-ACCESS-KEY'
@lpar
lpar / timeout.rb
Created June 17, 2011 20:41
Run a shell command in a separate thread, terminate it after a time limit, return its output
# Runs a specified shell command in a separate thread.
# If it exceeds the given timeout in seconds, kills it.
# Returns any output produced by the command (stdout or stderr) as a String.
# Uses Kernel.select to wait up to the tick length (in seconds) between
# checks on the command's status
#
# If you've got a cleaner way of doing this, I'd be interested to see it.
# If you think you can do it with Ruby's Timeout module, think again.
def run_with_timeout(command, timeout, tick)
output = ''
@iwasrobbed
iwasrobbed / gist:1032395
Created June 17, 2011 21:29
Amazon S3 Query String Authentication for Ruby on Rails
def generate_secure_s3_url(s3_key)
#
# s3_key would be a path (including filename) to the file like: "folder/subfolder/filename.jpg"
# but it should NOT contain the bucket name or a leading forward-slash
#
# this was built using these instructions:
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?S3_QSAuth.html
# http://aws.amazon.com/code/199?_encoding=UTF8&jiveRedirect=1
s3_base_url = MyApp::Application::S3_BASE_URL # i.e. https://mybucket.s3.amazonaws.com
@shawndumas
shawndumas / soundex.js
Last active February 21, 2024 11:47
Soundex in JavaScript
var soundex = function (s) {
var a = s.toLowerCase().split(''),
f = a.shift(),
r = '',
codes = {
a: '', e: '', i: '', o: '', u: '',
b: 1, f: 1, p: 1, v: 1,
c: 2, g: 2, j: 2, k: 2, q: 2, s: 2, x: 2, z: 2,
d: 3, t: 3,
l: 4,
@chetan
chetan / yardoc_cheatsheet.md
Last active May 10, 2024 02:53
YARD cheatsheet
@olifante
olifante / filter_through_command.py
Created February 25, 2012 20:20 — forked from jefftriplett/filter_through_command.py
Sublime Text 2: "Filter Through Command" plugin
#!/usr/bin/env python
# -*- coding: utf-8 -*-
## based on http://pastie.org/private/bclbdgxzbkb1gs2jfqzehg
import sublime
import sublime_plugin
import subprocess
class PromptRunExternalCommand(sublime_plugin.WindowCommand):
@EricLondon
EricLondon / gist:2111910
Created March 19, 2012 13:22
Rails route that works with: http://localhost:3000/posts/tag/Drupal%205.x
# I created a Post controller to accept a parameter for tag name.
# The problem is, the tag "Drupal 6.x", or anything with a period was triggering :format
get 'posts/tag/:tag' => 'posts#tag', :format => false, :constraints => {:tag => /.*/}
@psobot
psobot / example.nginx.conf
Created May 9, 2012 03:35
API proxying with nginx
proxy_cache_path /tmp/recipe_cache levels=1:2 keys_zone=RECIPE:64m inactive=3600m max_size=360m;
# Yada yada yada...
server {
# Yada yada yada, more in here...
location ^~ /recipes {
rewrite ^/recipes\??(.*) /recipes?key={your_private_api_key_here}&$1 break;