Skip to content

Instantly share code, notes, and snippets.

View seouri's full-sized avatar

Joon Lee seouri

  • Activate Care
  • Boston, MA
View GitHub Profile
@seouri
seouri / gist:8394
Created September 2, 2008 08:31 — forked from defunkt/gist:6443
# Video: http://rubyhoedown2008.confreaks.com/08-chris-wanstrath-keynote.html
Hi everyone, I'm Chris Wanstrath.
When Jeremy asked me to come talk, I said yes. Hell yes. Immediately. But
then I took a few moments and thought, Wait, why? Why me? What am I supposed
to say that's interesting? Something about Ruby, perhaps. Maybe the
future of it. The future of something, at least. That sounds
keynote-y.
def alphabetical_query_list(query)
li = link_to_unless query.blank?, "All"
list = [content_tag(:li, li)]
"A".upto("Z") do |l|
li = link_to_unless l == query, l, :q => l
list.push(content_tag(:li, li))
end
content_tag :ul, list.join("\n"), :class => "alphabetical"
end
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base
@seouri
seouri / .bashrc
Created January 28, 2009 22:49 — forked from henrik/.bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
# http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
# Given the ratings I have, there is a 95% chance that the average rating is at least what?
# Score = Lower bound of Wilson score confidence interval for a Bernoulli parameter
# pos is the number of positive rating, n is the total number of ratings, and power refers to the statistical power: I would pick 0.05.
require 'statistics2'
def ci_lower_bound(pos, n, power)
if n == 0
return 0
end
z = Statistics2.pnormaldist(1-power/2)
sub read_bin {
my $file = shift;
print STDERR "READ $file ... ";
open(FH, "< $file") or die("Can't open $file: $!\n");;
my @bin = <FH>;
close FH;
my $bin = join("", @bin);
my @record = split /\*NEWRECORD\s+/s, $bin;
my @file;
foreach my $r (@record) {
@seouri
seouri / bin2tree.pl
Created February 13, 2009 15:58
bin2tree.pl
#!/usr/bin/perl -w
use strict;
my @year = 1997 .. 2009;
my %term;
foreach my $y (@year) {
my $file = "d$y.bin";
my @file = read_bin($file);
my @tree = tree_base($y);
# touching a .gitignore file into all the empty subdirectories except the .git directory itself
find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;
find . -name "Thumbs.db" -exec rm '{}' \;
find . -name ".DS_Store" -exec rm '{}' \;
find . -name "*.THM" -exec rm '{}' \;
find . -name "*._*" -exec rm '{}' \;
@seouri
seouri / read_write.pl
Created February 20, 2009 14:04
read/write perl
sub read_file {
my $file_name = shift;
print STDERR "READ $file_name ... ";
my @file;
open(FH, "< $file_name") or die("Can't read $file_name: $!\n");
while (<FH>) {
chomp;
my @t = split /\t/;
@t = map { s/^\s+//g; s/\s+$//g; $_ } @t;
push @file, \@t;