This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src: http://www.hunlock.com/blogs/Mastering_Javascript_Arrays#quickIDX40 | |
Array.prototype.shuffle = function() { | |
for(var rnd, tmp, i=this.length; i; | |
rnd=parseInt(Math.random()*i), | |
tmp=this[--i], | |
this[i]=this[rnd], | |
this[rnd]=tmp); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rufus/tokyo' | |
db = Rufus::Tokyo::Table.new('data.tct') | |
date_col = 'created_at' | |
1.upto(5) { |i| db[i.to_s] = { date_col => Time.now.to_s }; sleep 1 } | |
pp db.query { |q| q.order_by date_col, :asc } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.class_eval { | |
# [1,2,3,4].each_with_previous do |el, prev| | |
# p "el:#{el}, prev:#{prev}" | |
# end | |
# | |
def each_with_previous | |
prev = nil | |
each do |el| | |
yield(el, prev) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example of inject method in ruby | |
class Foo | |
attr_accessor :title, :content, :posted_at | |
def initialize(title, content, posted_at) | |
@title, @content, @posted_at = title, content, posted_at | |
end | |
def serializeable_attributes | |
[:title, :content, :posted_at] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%w(rufus/tokyo pp ftools time).each { |l| require l } | |
file = 'data.tct' | |
FileUtils.rm file | |
db = Rufus::Tokyo::Table.new(file) | |
date_col = 'created_at' | |
data = { | |
db.genuid => 'fri jul 03 18:53:24 -0400 2009', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bash snippet to open new shells in most recently visited dir. | |
# Useful if you want to open a new terminal tab at the present | |
# tab's location. | |
# | |
# Put this in your .bashrc or whatever. | |
pathed_cd () { | |
if [ "$1" == "" ]; then | |
cd | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="favicon"> | |
<li><a href="http://twitter.com/">twitter</a></li> | |
<li><a href="http://github.com/">github</a></li> | |
<li><a href="http://microformats.org/">microformats</a></li> | |
</ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(~) > rip check | |
All systems go. | |
(~) > rip install git://github.com/defunkt/cijoe.git 0.1.0 | |
destination directory 'cijoe-3ecfbb14ec9be7ef8b8ff9a6abb7c197' already exists. | |
rip: install failed | |
-> No such file or directory - /Users/doug/.rip/rip-packages/cijoe-3ecfbb14ec9be7ef8b8ff9a6abb7c197 | |
(~) > tail -6 .profile | |
# -- start rip config -- # | |
RIPDIR=/Users/doug/.rip | |
RUBYLIB="$RUBYLIB:$RIPDIR/active/lib" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(~/code/ruby/sinatra/cabin) > rip install git://github.com/defunkt/cijoe.git 0.1.0 | |
Successfully installed cijoe (0.1.0) |