Skip to content

Instantly share code, notes, and snippets.

View mlbright's full-sized avatar

Martin-Louis Bright mlbright

  • Toronto
  • 14:25 (UTC -04:00)
View GitHub Profile
@stevekrenzel
stevekrenzel / gist:845969
Created February 27, 2011 06:49
Find the longest common substring between two strings.
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)
@schwern
schwern / num_github_issues
Created March 10, 2011 14:21
Get the number of issues from a github project
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$};
@alexisrobert
alexisrobert / webserver.go
Created May 20, 2011 10:13
Tiny web server in Go for sharing a folder
/* 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"
@pims
pims / kmeans.py
Created May 29, 2011 05:19
Naive python translation of https://gist.github.com/995804
#!/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.
"""
@avdi
avdi / throw-catch.rb
Created July 11, 2011 05:55
throw/catch demo code for RubyLearning article
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|
@jasonrudolph
jasonrudolph / about.md
Last active May 2, 2025 12:20
Programming Achievements: How to Level Up as a Developer
@kylelemons
kylelemons / valsort.go
Created September 22, 2011 21:36
Sort a map by its values
package main
import "fmt"
import "sort"
func main() {
m := map[string]int{
"One": 1,
"Two": 2,
"Three": 3,
@dnene
dnene / weights.py
Created October 31, 2011 00:02
Broken Weight problem
# 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)
@chrisdolan
chrisdolan / weights.pl
Created October 31, 2011 02:09
Intentionally brute force Perl solution to http://beust.com/weblog/2011/10/30/a-new-coding-challenge/
#!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)