Skip to content

Instantly share code, notes, and snippets.

View greatseth's full-sized avatar

Seth Thomas Rasmussen greatseth

View GitHub Profile
Loading development environment (Rails 2.3.2)
>> root = Rails.root
=> #<Pathname:/Users/seth/diversion/hdcloud>
>> root + "/test"
=> #<Pathname:/test>
>> wtf
NameError: undefined local variable or method `wtf'
Shoes.app do
slot_to_update = stack do
para "hi!"
end
button "go bye bye" do
slot_to_update.clear do
para "bye!"
end
end
#!/usr/local/bin/ruby
require 'rubygems'
require 'grit'
require 'choice'
Choice.options do
header 'Use one of the following options:'
option :new do
@greatseth
greatseth / ginit.bash
Created July 30, 2009 22:24
Shortcut to setup new Git project directory, inspired by Mercurial
function ginit {
mkdir $1
cd $1
git init
}
mysql> explain SELECT * FROM `jobs` WHERE (`jobs`.`user_id` = 5) AND ((`jobs`.`published` = 0) AND (`jobs`.`job_type` = 'encode')) ORDER BY priority desc, created_at asc LIMIT 1;
+----+-------------+-------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+---------+-------------------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------+---------+-------------------+------+---------------------
named_scope :created_within_range, proc { |range|
if range and [:min, :max].all? { |a| range.respond_to? a }
{ :conditions => ["created_at > ? and created_at < ?", range.min, range.max] }
else
{ }
end
}
@greatseth
greatseth / modular_arithmetic.rb
Created June 2, 2009 23:51
some Ruby code illustrating use of Modular Arithmetic
# I've been reading a book on symmetry lately(http://is.gd/MGST),
# and the other day it touched on something interesting that it
# turns out my code could have benefited from very recently:
# Modular Arithmetic
# The use case was cycling through indexes of an array.
# I had an operation that I wanted cycle through an array of values
# for use each time it was run.
# Instead of something like this...
@greatseth
greatseth / mediainfo_asserts.rb
Created April 3, 2009 15:26
I made this to help test a video metadata inspector based on mediainfo
#!/usr/local/bin/ruby
file = ARGV[0]
info = ARGV[1] ? "@#{ARGV[1]}" : "@info"
property = /^
([^:]+): # name
(.+?) # value
$/x
$ mediainfo test/videos/magnify-3_5_TOMD_-_Dave_L.mp4
General
Complete name : test/videos/magnify-3_5_TOMD_-_Dave_L.mp4
Format : MPEG-4
Format profile : Base Media / Version 2
Codec ID : mp42
File size : 11.1 MiB
Duration : 2mn 28s
Overall bit rate : 627 Kbps
Encoded date : UTC 2009-03-06 17:15:04
ffmpeg -i test/videos/magnify-3_16_Wow_outfit_day.mp4
FFmpeg version SVN-r17587, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --prefix=/usr/local --disable-vhook --enable-pthreads --enable-shared --enable-gpl --enable-libmp3lame --enable-libfaac --enable-libfaad --enable-libx264 --enable-nonfree --enable-libamr-nb --enable-libamr-wb
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.19. 0 / 52.19. 0
libavformat 52.30. 0 / 52.30. 0
libavdevice 52. 1. 0 / 52. 1. 0
built on Feb 25 2009 11:43:00, gcc: 4.0.1 (Apple Inc. build 5490)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test/videos/magnify-3_16_Wow_outfit_day.mp4':
Duration: 00:02:16.23, start: 0.000000, bitrate: 1436 kb/s