Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
if [ -z "$1" ]; then
wdir="."
else
wdir=$1
fi
for f in $( find . -name '*erb' ); do
out="${f%.erb}.haml"
if [ -e $out ]; then
@carlthuringer
carlthuringer / coffeescript
Created June 20, 2011 15:31
Coffeescript Syntax oddities
$('div').live 'pagebeforeshow', (event, ui)->
$('#statistics').height(70)
$('#stats-grid-plus-minus a').toggle(->
$(this).parents('#statistics').animate({ height: "170px"}, 500)
->
$(this).parents('#statistics').animate({ height: "70px"}, 500)
)
$('div').live('pagebeforeshow', function(event, ui) {
$('#statistics').height(70);
@carlthuringer
carlthuringer / gist:2691146
Created May 14, 2012 01:19
While looking at 'My Library' on Audible, get it to show all titles for all time, then use this script to store a list of normalized, deduped titles.
var titles = '';
$('a[name="tdTitle"]').each(function(el){var text = $(this).html(); text = text + "\n"; titles = titles + (text.search('Part') > 0 ? (text.search('Part 1') > 0 ? text : '') : text).replace(' (Unabridged)', '').replace(' Part 1', '')});
require 'formula'
class Libstemmer < Formula
# upstream is constantly changing the tarball,
# so doing checksum verification here would require
# constant, rapid updates to this formula.
head 'http://snowball.tartarus.org/dist/libstemmer_c.tgz'
homepage 'http://snowball.tartarus.org/'
end
@carlthuringer
carlthuringer / gist:8788196
Created February 3, 2014 17:24
Ethon Segfault OS X Mavericks
/Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ethon-0.6.2/lib/ethon/easy/operations.rb:23: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin13.0.2]
-- Control frame information -----------------------------------------------
c:0098 p:---- s:0507 b:0507 l:000506 d:000506 CFUNC :easy_perform
c:0097 p:0024 s:0503 b:0503 l:000502 d:000502 METHOD /Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/ethon-0.6.2/lib/ethon/easy/operations.rb:23
c:0096 p:0036 s:0500 b:0500 l:000499 d:000499 METHOD /Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/typhoeus-0.6.7/lib/typhoeus/request/operations.rb:16
c:0095 p:0074 s:0496 b:0496 l:000495 d:000495 METHOD /Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/typhoeus-0.6.7/lib/typhoeus/request/cacheable.rb:18
c:0094 p:0050 s:0492 b:0492 l:000491 d:000491 METHOD /Users/carl/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/typhoeus-0.6.7/lib/typhoeus/requ
@carlthuringer
carlthuringer / gist:11230097
Created April 23, 2014 19:56
Composition or Decoration?
class Decorator
def self.decorate(subject)
subject.define_singleton_method(:with) do |delegate|
@delegate_list ||= []
@delegate_list << delegate
end
subject.define_singleton_method(:method_missing) do |meth, *args, &block|
begin
@delegate_list.find do |delegate|
@carlthuringer
carlthuringer / tmux.md
Last active August 29, 2015 14:09 — forked from andreyvit/tmux.md

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Sessions, windows, panes

Session is a set of windows, plus a notion of which window is current.

Window is a single screen covered with panes. (Once might compare it to a ‘virtual desktop’ or a ‘space’.)

class CalculatesTax
include LightService::Organizer
def self.for_order(order)
with(:order => order).reduce(
[FetchesTaxRangesAction, FetchesCachedTaxRangesAction],
LooksUpTaxPercentageAction,
CalculatesOrderTaxAction,
ProvidesFreeShippingAction
fallback: GenericErrorHandler
@carlthuringer
carlthuringer / integratioN_test.rb
Created May 27, 2016 15:52
Supposed to create a workflow in backbeat
it "runs a workflow from java to ruby, back to java" do
# Because our Backbeat client is set up with the ruby credentials, we cannot use it to prove this test's functionality.
# Instead, we have to craft the requests by hand.
backbeat_host = URI("http://#{ENV['BACKBEAT_SERVER_HOST']}:#{ENV['BACKBEAT_SERVER_PORT']}")
# Create the workflow
create_workflow_request = Net::HTTP::Post.new(URI.join(backbeat_host, "/workflows"))
set_client_headers(create_workflow_request, :java)
@carlthuringer
carlthuringer / bmi.php
Last active September 19, 2016 15:15
BMI
<?php
/*
* calc_bmi
* The structure of this function is misleading and overcomplicated.
* The function returns false or a value, so any program calling it must handle
* either false or a value.
* Further, the function is burdened with mistrust and has misleading default arguments.
* The default arguments suggest that the function expects integers, but it actually handles strings and many other possible values.
*/