Skip to content

Instantly share code, notes, and snippets.

View softprops's full-sized avatar
®️
Rustling

Doug Tangren softprops

®️
Rustling
View GitHub Profile
// 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);
};
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 }
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)
# 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]
%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',
# 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
<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>
(~) > 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"
(~/code/ruby/sinatra/cabin) > rip install git://github.com/defunkt/cijoe.git 0.1.0
Successfully installed cijoe (0.1.0)