This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
M[16],X=16,W,k;main(){T(system("stty cbreak") | |
);puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i | |
,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M | |
[w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<< | |
(l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k) | |
]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d | |
-1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X] | |
*i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4; | |
)s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4|| | |
puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)]/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -name "Thumbs.db" -exec rm '{}' \; | |
find . -name ".DS_Store" -exec rm '{}' \; | |
find . -name "*.THM" -exec rm '{}' \; | |
find . -name "*._*" -exec rm '{}' \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 \; |
OlderNewer