Skip to content

Instantly share code, notes, and snippets.

@loopj
loopj / gist:4696332
Last active December 12, 2015 02:08
<div id="slider-value"></div>
<input type="text" data-slider="true" data-slider-values="0,100,500,800">
<script>
var sliderValues = {
0: "None",
100: "Small",
500: "Medium",
800: "Large"
};
@loopj
loopj / delayedjob-bugsnag.rb
Created January 30, 2013 20:04
A delayed_job plugin to automatically notify Bugsnag (https://bugsnag.com) of exceptions.
module Delayed
module Plugins
class Bugsnag < Plugin
module Notify
def error(job, error)
::Bugsnag.auto_notify(error)
super
end
end
@loopj
loopj / redis-sse.js
Created October 26, 2012 23:29
Connect middleware for pub/sub using server-sent events
//
// Simple pub/sub using redis and server-sent events (EventSource)
//
// Usage:
//
// // Attach the middleware
// redisSse = require("redis-sse");
// app.use(redisSse({redis: yourRedisClient}));
//
// // Set up a subscription to a channel in your route
@loopj
loopj / google-cl.sh
Created October 14, 2012 02:49
Install google command line tools on mac
#!/bin/bash
sudo pip install -Iv http://gdata-python-client.googlecode.com/files/gdata-2.0.14.tar.gz googlecl
@loopj
loopj / get-aws-instance-id.sh
Created October 11, 2012 01:14
Get the AWS instance ID for the current instance, no API credentials required
# Get the AWS instance ID for the current instance, no API credentials required
curl http://169.254.169.254/2009-04-04/meta-data/instance-id
@loopj
loopj / batman-layoutcontroller.coffee
Created October 8, 2012 21:44
Batman.js controller which adds rails-style layouts to controllers
class Batman.LayoutController extends Batman.Controller
render: (options = {}) ->
layout = options.layout ? @layout ? Batman.helpers.underscore(@get('routingKey'))
if layout
# Prefetch the action's view in parallel
source = options.source || Batman.helpers.underscore(@get('routingKey') + '/' + @get('action'))
Batman.View.store.prefetch source
# Fetch the layout's view and apply context
@loopj
loopj / smart-mailer.rb
Created September 21, 2012 03:09
Automatically generates rails plain-text emails from html templates, using premailer
# Automatically generates the plain-text version of emails from the html
# template using premailer.
class SmartMailer < ActionMailer::Base
def mail(headers={})
# Configure the premailer options
premailer_options = {
with_html_string: true,
line_length: 9999,
}
@loopj
loopj / pry-environment-name.rb
Created September 21, 2012 02:13
Show red environment name in pry prompt for non development environments
# Put this in an initializer
old_prompt = Pry.config.prompt
Pry.config.prompt = [
proc {|a,b,c| "\e[31m#{(Rails.env.upcase)}\e[0m #{old_prompt.first.call(a,b,c)}"},
proc {|a,b,c| "\e[31m#{(Rails.env.upcase)}\e[0m #{old_prompt.second.call(a,b,c)}"},
] unless Rails.env.development?
@loopj
loopj / nginx-config-spdy-example
Created August 5, 2012 22:24
Nginx SPDY configuration example
server {
listen 443 ssl spdy default_server;
server_name example.com;
ssl_certificate /etc/ssl/certs/my.ssl.crt;
ssl_certificate_key /etc/ssl/private/my.ssl.key;
root /mysite/current/public;
passenger_enabled on;
@loopj
loopj / passenger-nginx-spdy.sh
Created August 5, 2012 20:21
Install passenger and nginx with SPDY support
#!/bin/sh
NGINX_VERSION=1.3.8
TMP_PATH=/tmp
# Fetch and extract Nginx
cd $TMP_PATH
wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz
tar xvfz nginx-$NGINX_VERSION.tar.gz
cd nginx-$NGINX_VERSION