Skip to content

Instantly share code, notes, and snippets.

View treedepth.py
import unittest
def has_branches(tree):
return len(tree) >= 1
def depth(tree):
if has_branches(tree):
return 1 + max(map(depth, tree))
else:
return 1
View SteppingStones.py
import unittest
def has_branch(tree):
return False
class DepthTest(unittest.TestCase):
#I guess, testing existence of branches might be useful to calculate the depth of tree.
def test_has_branch(self):
tree = []
self.assertFalse(has_branch(tree))
View Simplification.py
import unittest
def depth(tree):
return 1
class DepthTest(unittest.TestCase):
#Simplest tree is a tree which has just one node with no branches. In that case, the depth is 1.
def test_no_children(self):
tree = []
self.assertEquals(1, depth(tree))
View output.txt
첫째날
10:00 소개
10:10 실습
10:30 휴식
0h 40m
View ClojureServlet.java
package servlet;
import clojure.lang.RT;
import clojure.lang.Var;
import javax.servlet.ServletException;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@eungju
eungju / moin2gitit.rb
Created Dec 3, 2010
Copy pages from MoinMoin to gitit
View moin2gitit.rb
#!/usr/bin/env ruby
require 'fileutils'
if ARGV.length != 2
puts "Usages: #{$0} <moin pages directory> <gitit wikidata directory>"
exit 1
end
from_dir = File.expand_path ARGV[0]
@eungju
eungju / download.rb
Created Jan 6, 2011
Download House M.D. Transcripts
View download.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
INDEX_PAGE = "http://community.livejournal.com/clinic_duty/12225.html"
(open(INDEX_PAGE) { |f| Hpricot(f) }/"table > tbody > tr > td > a").each do |a|
#Skip season links
View FooDao.java
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import javax.sql.DataSource;
public class FooDao extends JdbcDaoSupport {
private final String COLUMNS = "id a b";
private final RowMapper<Foo> rowMapper = new RowMapper<Foo>() {
View FeatureCollectionJsonSerializer.java
package geojson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.opengis.feature.Feature;
@eungju
eungju / JdbcTemplate.java
Created Jul 8, 2011
Poor man's JdbcTemplate
View JdbcTemplate.java
import java.util.List;
import com.google.common.base.Function;
public interface JdbcTemplate {
<T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper);
<T> T queryFirst(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper);
int queryForInt(String sql, Object[] args, int[] argTypes);
<T> void eachDo(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper, Function<T, Void> block);
int update(String sql, Object[] args, int[] argTypes);