Skip to content

Instantly share code, notes, and snippets.

View sgerrand's full-sized avatar
🧑‍✈️
Manual controls

Sasha Gerrand sgerrand

🧑‍✈️
Manual controls
View GitHub Profile
@darkhelmet
darkhelmet / cscript
Created March 9, 2011 05:51
Run *.c files as scripts. Put this in ~/bin/cscript
#!/usr/bin/env bash
tail -n `wc -l $1 | awk '{ print $1 }'` $1 | gcc -xc - -o ~/.cscript && ~/.cscript
@3kwa
3kwa / .tmux.conf
Created March 23, 2012 05:02
my tmux conf
# ctrl-b -> ctrl-a
set -g prefix C-a
# ctrl-a ctrl-a last window
bind-key C-a last-window
# we are humans numbering from 1
set -g base-index 1
# faster input (not waiting for escape)
@mipearson
mipearson / unfixable.md
Created April 2, 2012 01:44
Request for Comments: Fixing Ruby, Python and Node.js packaging on Debian, Redhat and variants

Request for Comments

Fixing Ruby, Python and Node.js packaging on Debian, Redhat and variants.

Canonical URL: http://bit.ly/wtfpackages

It's unfixable.

You shouldn't be using distribution provided packages for your primary language runtime.

@wycats
wycats / 0_app.rb
Created April 19, 2012 10:22
Example of using a simple future library for parallel HTTP requests
class TicketsController < ApplicationController
def show
tickets = params[:tickets].split(",")
ticket_data = tickets.map do |ticket|
parallel { Faraday.get("http://tickets.local/#{ticket}") }
end
render json: { tickets: ticket_data.map(&:result) }
end
@havenwood
havenwood / bench.md
Last active December 12, 2015 05:49
Entirely Unscientific Benchmark of Primes in Various Ruby Implementations

Unscientific Benchmark

The Benchmark

def is_prime? n
  (2...n).all? { |i| n % i != 0 }
end

def sexy_primes n
#!/usr/bin/env ruby
gem "parser", "~> 1.4"
require "parser"
require "parser/ruby19"
require "set"
class ConstantDeclarationAndUseProcessor < Parser::AST::Processor
attr_reader :declared, :used
def initialize
@parndt
parndt / existing.rb
Last active December 19, 2015 13:29
Who wants to make this nicer? :(
def extension_path_for_nested_extension(path, apply_tmp)
if File.exist?(path.gsub(/\.erb$/, ""))
if %r{/(locales/.*\.yml)|((routes|#{gem_name})\.rb\.erb)$} === path
# put new translations into a tmp directory
path = path.split(File::SEPARATOR).insert(-2, "tmp").join(File::SEPARATOR) if apply_tmp
elsif %r{/readme.md$} === path || %r{/#{plural_name}.rb$} === path
path = nil
end
elsif %r{lib\/#{plural_name}.rb$} === path
path = nil
def with_retries(timeout = 5.seconds, retry_delay: 0.1.seconds, &blk)
start = Time.now
begin
blk.call
rescue
if Time.now > start + timeout
raise
else
sleep retry_delay
retry
@cddr
cddr / puma.clj
Last active February 15, 2017 10:48
(defn holdings-manager
"Returns a collection of kstreams, one for each different way in which
loan ownership state may be updated"
[puma-events]
(let [ownership-store (k/store "loan-ownership")]
(-> (k/kstream puma-events)
(k/transform (update-ownership ownership-store))
(k/branch [trade-result?
repayment-result?]))])
@bradfitz
bradfitz / blast.pl
Created April 16, 2012 04:56
Cognac Hacking
#!/usr/bin/perl
use strict;
my $rockettop = <<'END';
.
/ \
/ \
END