Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@duien
duien / Export The Hit List database to org-mode
Created February 5, 2009 19:21
Export The Hit List database to org-mode
#!/usr/bin/ruby
# Written by Emily Price <http://duien.com> Feb 4, 2009
# Feel free to use and modify
# The code makes a few assumptions about how you use org-mode:
# Assumes you're using org-odd-levels-only and that you have the TODO keywords 'TODO', 'DONE', and 'CANCEL' defined
require 'rubygems'
require 'sqlite3'
class Time
def aprox_eql? (time2, interval)
raise ArgumentError, 'Invalid Time object' unless time2.kind_of? Time
raise ArgumentError, 'Invalid interval' unless [:year, :month, :mon, :day, :hour, :min, :sec, :usec].include? interval
case interval
when :year
self.year == time2.year
when :month, :mon
self.year == time2.year and self.month == time2.month
when :day
require 'mongo'
describe "MongoDB" do
before(:all) do
@db = Mongo::Connection.new.db('test').collection('index_test')
@db.drop
@db.create_index( 'a' )
@db.insert( { 'a' => 1 } )
@db.insert( { 'b' => 1 } )
end
@duien
duien / sl_gems_update.rb
Created February 8, 2010 22:21 — forked from coty/sl_gems_update.rb
List gems needing to be recompiled
#!/usr/bin/env ruby
require 'rubygems'
require 'set'
puts "looking for the gems to upgrade..."
gem_info = Struct.new(:name, :version)
to_reinstall = Set.new
Dir.glob("#{Gem.dir}/**/*.bundle").map do |path|
path =~ /.*1.8\/gems\/(.*)-(.*?)\/.*/
name, version = $1, $2
@duien
duien / Railscasts.tmTheme
Created March 5, 2010 19:57
Custom-tweaked version of the Railscasts theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Railscasts</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@duien
duien / mongodb
Created March 9, 2010 17:06
Mongodb init script
#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
@duien
duien / sinatra_app_instance_in_spec.rb
Created April 15, 2010 17:25
Get access to the Sinatra application instance that ran the current test in Rack::Test. Created by @bsiggelkow
describe LeadService do
# Get the Sinatra application instance that ran the current test. For instance you
# could use:
#
# it "should set an instance variable" do
# get '/'
# app_instance.instance_variable_get(:@lead).should_not be_nil
# end
#
@duien
duien / gist:817421
Created February 8, 2011 22:33
Mongo Atlanta Notes

Tweet photo with #mongoatl to win!
Fur bus will shuttle back & forth to after-party, where there are 2 free drinks

Building an application with MongoDB

Will cover:

  • Data modeling, queries, geospacial, updates, map-reduce
  • Using location-based app as an example
@duien
duien / gist:818746
Created February 9, 2011 16:24
builder fail
ruby-1.8.7-p302 > require 'builder'
=> true
ruby-1.8.7-p302 > xm = Builder::XmlMarkup.new
=> <inspect/>
ruby-1.8.7-p302 > xm.title('yada')
=> "<inspect/><title>yada</title>"
ruby-1.8.7-p302 > puts xm
TypeError: Builder::XmlMarkup#to_ary should return Array
from (irb):5:in `puts'
from (irb):5
@duien
duien / glitch_time.js
Created September 2, 2011 22:18
Glitch Date/Time calculation in JavaScript
function time_to_glitch(time){
var year, day_of_year, month_and_day, month, day_of_month, hour, minute, sec, ts ;
sec = Number(time) - 1238562000;
// there are 4435200 real seconds in a game year
// there are 14400 real seconds in a game day
// there are 600 real seconds in a game hour
// there are 10 real seconds in a game minute
year = Math.floor(sec / 4435200);