Skip to content

Instantly share code, notes, and snippets.

@mbostock
mbostock / .block
Last active February 1, 2020 08:29
New York Block Groups
license: gpl-3.0
@briangonzalez
briangonzalez / README.md
Created October 21, 2012 04:25
img2boxshadow - a ruby script to convert images to CSS [http://codepen.io/briangonzalez/details/AvrGI#pen-details-tab]

img2boxshadow.rb

a ruby script to convert images to CSS (box-shadows)

Installation

gem install rmagick    # you'll need ImageMagick & Ruby first
gem install colormath
gem install micro-optparse
@derwiki
derwiki / load.sh
Created June 4, 2012 22:31
Bulk loading 500m rows into MySQL
for month_table in action*.txt; do
echo "$(date) splitting $month_table..."
split -l 1000000 $month_table curmonth_
for segment in curmonth_*; do
echo "On segment $segment"
time mysql -hlocalhost action_credit_silo <<-SQL
SET FOREIGN_KEY_CHECKS = 0;
SET UNIQUE_CHECKS = 0;
SET SESSION tx_iso
@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;
@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 => /.*/}
@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):
@chetan
chetan / yardoc_cheatsheet.md
Last active May 4, 2024 11:12
YARD cheatsheet
@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,
@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
@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 = ''