Skip to content

Instantly share code, notes, and snippets.

@DNNX
DNNX / gcj_solver.rb
Created May 14, 2011 13:46
GCJ 2011 CandySplitting problem
class GCJSolution
def initialize(input = STDIN, output = STDOUT)
@input = input
@output = output
end
def read_strings
@input.gets.chomp.split(' ')
end
@DNNX
DNNX / magicka.rb
Created May 15, 2011 18:26
Solution of GCJ's Magicka problem
RUN_TEST = false
require 'set'
require 'test/unit' if RUN_TEST
class Magicka
def initialize(combines, opposes)
@combs = build_combs(combines)
@opps = build_opps(opposes)
@counts = Hash.new(0)
@DNNX
DNNX / cons.rb
Created May 26, 2011 11:52
cons/car/cdr in ruby
def cons(x, y)
->(label) do
case label
when :first then x
when :second then y
else raise "Argument is neither :first nor :second -- cons"
end
end
end
@DNNX
DNNX / true.rb
Created May 26, 2011 12:20
True cons/car/cdr in ruby
def cons(x,y)
->(m) { m.call(x, y) }
end
def car(z)
z.call ->(p, q) { p }
end
def cdr(z)
z.call ->(p, q) { q }
@DNNX
DNNX / DirectoryChecker.java
Created June 29, 2011 10:50
Checks if directory exists and readable
import java.io.File;
public class DirectoryChecker
{
public static boolean isWindows()
{
String os = System.getProperty("os.name").toLowerCase();
return os.indexOf("windows") != -1;
}

This simple framework allows you to assert things that should happen tomorrow*. For example:

assert_tomorrow { Time.now.wday == 2 } # => :passed
                                       # assuming today is Monday (i.e. wday == 1)

Another example shows that the time will never be the same again:

today = Time.now
assert_tomorrow { Time.now == today } # => :failed
@DNNX
DNNX / which.cmd
Created July 19, 2011 11:23
Windows equivalent of Unix which command by Pankaj Kumar
@echo off
rem --------------------------------------------------------
rem File: which.cmd
rem Description: Windows equivalent of Unix which command
rem Author: Pankaj Kumar
rem Copyright 2004 Pankaj Kumar. All Rights Reserved.
rem License: This software is available under GPL
rem ---------------------------------------------------------
setlocal
if "%1" == "" goto noArg
%html
%ul
- (1..4).each do |x|
%p= x
require 'net/ftp'
require 'timeout'
ftp = Net::FTP.new('ftp.sra.ebi.ac.uk')
ftp.login
puts "connected!"
errors = []
samples = ["SRR016000"]
/*++
Copyright (c) 2003 Microsoft Corporation
Module Name:
UriExt.cs
Abstract:
Uri extensibility model Implementation.