Skip to content

Instantly share code, notes, and snippets.

class Modul # "module" is a keyword in ruby
attr_accessor :name, :size
def initialize(name, size=1)
@name = name
@size = size
end
def inspect
"#{name}(#{size})"
end
foo = %w{demo coda dome doom mode}
foo.each do |w|
if foo[0].bytes.sort == w.bytes.sort
puts w
end
end
@ikataitsev
ikataitsev / gist:2903042
Created June 9, 2012 23:33
Add "Sakhalin" to World Clock widget
// /Library/Widgets/World Clock.wdgt/WorldClock.js
{city:'Sakhalin', offset:660, timezone:'Asia/Vladivostok', id:"2119441"}
// /Library/Widgets/World Clock.wdgt/English.lproj/localizedStrings.js
localizedCityNames['Sakhalin'] = 'Sakhalin';
@ikataitsev
ikataitsev / gist:3005260
Created June 27, 2012 16:33
Keep SSH connections alive on OS X
# /etc/ssh_config
ServerAliveInterval 100
@ikataitsev
ikataitsev / gist:3798133
Created September 28, 2012 05:50
Calculating Fibonacci series with dictionary
def fib n, dict = []
if n < 2
dict[0] = 1
else
dict[n-1] = ( dict[n-2] || fib(n-1, dict).last ) + ( dict[n-3] || fib(n-2, dict).last )
end
dict
end
@ikataitsev
ikataitsev / gist:4078716
Created November 15, 2012 13:42
Useful OS X commands
# Move dock to the corner
defaults write com.apple.Dock pinning end
@ikataitsev
ikataitsev / gist:4352000
Created December 21, 2012 10:27
Remove duplicates from Open with dialog in OS X
1. Copy and paste this to Terminal.app:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/\
LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local\
-domain system -domain user
2. Relaunch Finder (Cmd+Option+Click on Finder icon and then Relaunch)
@ikataitsev
ikataitsev / gist:5300689
Created April 3, 2013 12:17
counting q
class Activity < ActiveRecord::Base
# Activity#result is a boolean
end
# Let's say
Activity.all.pluck(:result) # => [false, true, false, false, false, true]
# How can I calculate the number of the false results before that true one?
@ikataitsev
ikataitsev / gist:6038132
Created July 19, 2013 10:11
HTTP caching reading list
- http://tools.ietf.org/html/rfc2616#section-13
- http://tomayko.com/writings/things-caches-do
- http://www.mnot.net/cache_docs/
require 'active_record'
require 'yaml'
require 'mysql'
require 'logger'
task :default => :migrate
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )