Skip to content

Instantly share code, notes, and snippets.

View sidonath's full-sized avatar
🐈
Petting cats

Damir Zekic sidonath

🐈
Petting cats
View GitHub Profile
@sidonath
sidonath / gist:58895
Created February 5, 2009 18:21 — forked from pete/gist:57898
Experiments in revision control: Curry recipe.
My personal recipe for Japanese curry, which has mutated over the years and is
now open-source thanks to github, hot damn. Some of the ingredients are not
very Japanese, but curry came to Japan from England which got it from India to
begin with, so whatever.
1.5 - 2 lbs. of meat, prefer thin-sliced beef (komagire), pork works, too.
Thin-sliced stuff is always best, but in a pinch stewing beef works. Bacon
works surprisingly well. Chicken will work, technically, but if you must,
# this goes in the $HOME dir
# needs mislav-rspactor v0.3.1 and RSpec 1.2
Runner.class_eval do
class << self
alias old_formatter_opts formatter_opts
def formatter_opts
old_formatter_opts + " -r /Users/mislav/Projects/unicode_formatter -f UnicodeFormatter"
end
end
@sidonath
sidonath / singleton.js
Created June 6, 2009 07:52
Another take on singleton pattern in JavaScript
function singleton(self, wrapper, ctor) {
// support for early failing
if (self instanceof wrapper) {
throw wrapper.name + " " +
"is a singleton, you cannot create its instance. " +
"To get the isntance: " + wrapper.name + "();";
}
if (!ctor) {
return;
# copy to your Capistrano recipe file
namespace :deploy do
task :clear_cached_assets, :roles => :web do
dir = "#{current_release}/public"
run %(rm #{dir}/javascripts/all.js #{dir}/stylesheets/master.css)
end
end
# Append to ~/.profile (or ~/.bashrc)
# append to history, not overwrite
shopt -s histappend
# append command to history file before it's executed
export PROMPT_COMMAND="history -a"
# ignore duplicate consecutive commands
export HISTCONTROL=ignoreboth
# thanks to:
# http://www.linuxforums.org/forum/linux-programming-scripting/109516-retaining-bash-history-all-sessions.html
#!/usr/bin/env ruby
require 'rubygems'
require 'osax'
require 'maruku'
doc = Appscript.app('WriteRoom').documents[0]
path = doc.file.get.path
file = File.join(
(function($) {
function print_array(obj, opts) {
var result = [];
for (var i = 0; i < Math.min(opts.max_array, obj.length); i++)
result.push($.print(obj[i], $.extend({}, opts, { max_array: 3, max_string: 40 })));
if (obj.length > opts.max_array)
result.push((obj.length - opts.max_array) + ' more...');
if (result.length == 0) return "[]"
// approach one: simply assign function to prototype
// it works, but you still need to use "apply" to make the method
// work as needed
function smallest1(array){
Array.prototype.min = Math.min;
return array.min.apply(array, array);
}
// approach two: use apply in the function assigned to Array's prototype
function smallest2(array){
# Strip leading and trailing bytes
def self.decode data, &blk
while msg = data.slice!(/\000([^\377]*)\377/)
msg.gsub!(/^\x00|\xff$/, '')
yield msg
end
end
@sidonath
sidonath / jquery.catchup.js
Created June 7, 2011 10:17
A plugin for jQuery that makes element catch up with viewport
;(function ($) {
var $elementsToCatchUp = $(),
followBased = false,
bound = false;
function startCatchingUp($catchup) {
$catchup
.before($('<div>',
{ 'class': 'catching-up-placeholder', 'height': $catchup.outerHeight() }))
.addClass('catching-up')