Skip to content

Instantly share code, notes, and snippets.

@zetter
zetter / default_whenever.rb
Last active December 19, 2015 02:49 — forked from evizitei/default_whenever.rb
Setup whenever on engineyard for all deployed applications that have the whenever gem bundled on the util instance called 'util'
#
# Cookbook Name:: whenever
# Recipe:: default
#
# for the until instance named 'util'
if node[:name] == 'util'
ey_cloud_report "whenever" do
message "Starting whenever recipe"
end
@zetter
zetter / linkconverter.js
Created November 9, 2012 12:05
Why links should not say 'click here'. Requires jQuery
$('a').each(function(i, a){a=$(a);var t=a.text();a.text('here');a.before('click ');a.after(' to go to '+t);})
@zetter
zetter / for_sale.markdown
Created September 13, 2012 08:31
For Sale

For Sale

Make me an offer!

Plug & Battery

Books

  • Ten Stories About Smoking
@zetter
zetter / SuperReCSS.markdown
Created March 21, 2012 18:35
Modified ReCSS to reload styles on window focus

Only tested in chrome, shove this in a bookmarklet:

javascript:void(function(){var r=(function(){var i,a,s;a=document.getElementsByTagName('link');for(i=0;i=0&&s.href) {var h=s.href.replace(/(&|%5C?)forceReload=\d+/,'');s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf())}}}); window.addEventListener('focus',r,false)})();

@zetter
zetter / ruby-parsing-bug.markdown
Created March 9, 2012 23:12
Ruby parsing bug

A parsing bug in ruby 1.9.2 allowed you to pass blocks to methods preceded by a comma. The bug only affected blocks with do/end and was fixed in 1.9.3.

http://bugs.ruby-lang.org/issues/5540

$ rvm use ruby 1.8.7

[1].inject :+, do |x| 1 end
# => SyntaxError: compile error
@zetter
zetter / deconstruct.markdown
Created January 31, 2012 21:10
therubygame deconstruct by @czetter

therubygame deconstruct by @czetter

This is a deconstuction of matematikaadit's submission to therubygame challenge 5; 'Roman numerals. What are they good IV?'. The goal of the challenge is to take a string representing a roman numeral as input and return the integer that the numeral represents.

matematikaadit currently has the honour of the shortest (by character count) submission for this challenge. At first glance I didn't understand how it worked so I re-wrote and analyzed it until I did.

Making it readable

matematikaadit's original submission:

@zetter
zetter / Bubble Free Click
Created March 26, 2011 20:39
jquery extension to register click events that won't bubble. Call instead of click(func).
jQuery.fn.preventDefaultClick = function(f) {
this.click(function(e){
f.call(this, e);
e.preventDefault();
});
return this;
}
@zetter
zetter / Slow queries
Created February 8, 2011 09:23
Find the slowest queries lines in a rails development log
file=''
slow = []
File.readlines(file).each do |line|
if line =~ /Load\ \(([\d\.]*)ms\)/
time = $1.to_f
if time >= 500.0
slow << [time, line]
end
end
# Hacked from http://github.com/dball/zoomifier/blob/master/lib/zoomifier.rb
require 'fileutils'
require 'open-uri'
require 'rubygems'
require 'rmagick'
require 'rexml/document'
class Zoomify
TILESIZE = 256
#! /usr/bin/ruby
# Saves two random and contiguous cropped images from a larger image
# Written so an image that is too big can be displayed on a dual screen desktop
IMAGE_NAME = "file_small.png"
IMAGE_WIDTH, IMAGE_HEIGHT = IO.read(IMAGE_NAME)[0x10..0x18].unpack('NN')
# # For non-pngs:
# IMAGE_WIDTH, IMAGE_HEIGHT = [12304, 8605]