Skip to content

Instantly share code, notes, and snippets.

View ssoper's full-sized avatar
👨‍💻

Sean Soper ssoper

👨‍💻
View GitHub Profile
@ssoper
ssoper / gist:147871
Created July 15, 2009 18:15
Useful .bash_login
PS1="\u@\h:\w$ "
export CLICOLOR=1
export LSCOLORS=gxFxCxDxBxegedabagacad
export EDITOR='mate -w'
export PATH="/usr/local/bin:$PATH"
alias l='ls -al'
alias svdc='svn diff | mate'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link href="reset.css" media="screen" rel="stylesheet" type="text/css" />
<style types="text/css" media="all">
/* Left these in here in case you want to fiddle some more with it */
ul#movie-list {
ssoper@caprica:~$ irb
irb(main):001:0> class Person
irb(main):002:1> def initialize
irb(main):003:2> @@cool = true
irb(main):004:2> end
irb(main):005:1> def cool?
irb(main):006:2> @@cool
irb(main):007:2> end
irb(main):008:1> def cool=(cool)
irb(main):009:2> @@cool = cool
@ssoper
ssoper / gist:188799
Created September 18, 2009 00:09
Tail-Call Optimized odds calculator
#import <Cocoa/Cocoa.h>
// Based on Paul Barry's Tail-Call Optimized odds calculator
// http://paulbarry.com/articles/2009/08/30/tail-call-optimization
int main(int argc, char *argv[])
{
__block double (^odds1)(int, int, double);
odds1 = ^(int n, int p, double acc) {
if (n == 0) {
# Using ruby to cleanup any pesky X instances
require 'fileutils'
Dir.glob('/tmp/xvfb-run.*').each do |entry|
pid = entry[/\d{3,5}$/].to_i rescue nil
next unless pid
Process.kill("TERM", pid) rescue Errno::ESRCH
FileUtils.rm_rf(entry)
end
@ssoper
ssoper / gist:222067
Created October 30, 2009 02:50
Throw this in your config/initializers dir for some hot tag cloud action using the is_taggable gem
# Throw this in your config/initializers dir for some hot tag cloud action using the is_taggable gem
module TaggableExtensions
def tag_cloud
result = self.find_by_sql <<-SQL
SELECT tags.id as tag_id, tags.name as tag_name, count(taggings.tag_id) as tag_count
FROM tags, taggings
WHERE tags.id = taggings.tag_id AND taggings.taggable_type = "#{self}"
GROUP BY (taggings.tag_id)
@ssoper
ssoper / gist:226540
Created November 5, 2009 00:16
random numbers
d = []
while 1 == 1
d << rand(1000)
puts d.last
end
results = {}
total = d.length.to_f
9.times do |x|
lower = x * 100
@ssoper
ssoper / gist:227168
Created November 5, 2009 16:20
Useful bash commands
# output from clipboard directly to file
sudo sh -c "pbpaste > file"
@ssoper
ssoper / fix_concat.rb
Created February 5, 2010 19:06
Ruby 1.9.1 fix for Rails 2.3.5 ActiveSupport concat and UTF8
class String
def concat_with_utf8(other_or_fixnum)
if other_or_fixnum.respond_to?(:force_encoding)
result = other_or_fixnum.force_encoding(Encoding::UTF_8)
else
result = other_or_fixnum
end
concat_without_utf8(result)
end
@ssoper
ssoper / gist:303757
Created February 14, 2010 00:05
How to do CSV in Ruby 1.9
if RUBY_VERSION >= "1.9"
require 'csv'
FasterCSV = CSV
else
require 'fastercsv'
end