This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| from collections import defaultdict | |
| def longest_common_substring(a, b): | |
| index = defaultdict(list) | |
| for i, c in enumerate(b): | |
| index[c].append(i) | |
| mxi, mxj, mxsz = 0, 0, 0 | |
| matches = defaultdict(int) | |
| for i, c in enumerate(a): | |
| new_matches = defaultdict(int) |
| use Net::GitHub::V2::Issues; | |
| use URI; | |
| # Examples: | |
| # http://github.com/schwern/test-more/tree/master | |
| # http://github.com/sukria/Dancer | |
| sub num_github_issues { | |
| my $url = URI->new(shift); | |
| return unless $url->host =~ m{\.?github.com$}; |
| /* Tiny web server in Golang for sharing a folder | |
| Copyright (c) 2010-2014 Alexis ROBERT <[email protected]> | |
| Contains some code from Golang's http.ServeFile method, and | |
| uses lighttpd's directory listing HTML template. */ | |
| package main | |
| import "net/http" | |
| import "net/url" |
| #!/usr/bin/env python | |
| import sys | |
| from math import sqrt | |
| from random import random | |
| """ | |
| Naive python translation of https://gist.github.com/995804 | |
| Public domain. | |
| """ |
| require 'rubygems' | |
| require 'mechanize' | |
| MAX_PAGES = 6 | |
| def each_google_result_page(query, max_pages=MAX_PAGES) | |
| i = 0 | |
| a = Mechanize.new do |a| | |
| a.get('http://google.com/') do |page| | |
| search_result = page.form_with(:name => 'f') do |search| |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| package main | |
| import "fmt" | |
| import "sort" | |
| func main() { | |
| m := map[string]int{ | |
| "One": 1, | |
| "Two": 2, | |
| "Three": 3, |
| # Response to challenge at http://beust.com/weblog/2011/10/30/a-new-coding-challenge/ | |
| # Further (braintwistingly) compact version of the same logic : https://gist.github.com/1326654 | |
| import itertools | |
| n = 40 | |
| weights = tuple((w1,w2,w3,n-(w1+w2+w3)) for w1 in range(1,n) for w2 in range(w1,n - w1) for w3 in range(w2, n-w1-w2) if n-(w1+w2+w3) -w3 >= 0) | |
| for weight in weights : | |
| allvals = list(val for val in range(1,n + 1)) | |
| for clength in range(1,5) : | |
| for combo in itertools.combinations(weight,clength) : | |
| other = list(weight) |
| #!perl -w | |
| use strict; | |
| # Solution to http://beust.com/weblog/2011/10/30/a-new-coding-challenge/ | |
| # Chris Dolan | |
| # Iterate over all combinations of weights, rejecting cases where they don't sum to 40 | |
| for my $w1 (1..37) { | |
| for my $w2 ($w1..37) { | |
| for my $w3 ($w2..37) { |
| #!/usr/bin/python | |
| # Response to challenge at http://beust.com/weblog/2011/10/30/a-new-coding-challenge/ | |
| import sys | |
| from itertools import combinations, chain | |
| N = 40 | |
| def powerset(iterable): | |
| "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)" | |
| s = list(iterable) |