Skip to content

Instantly share code, notes, and snippets.

@zhangsen
zhangsen / android-unlock.c
Created May 13, 2012 11:01
number of patterns of android unlock screen
#include <stdio.h>
int visited[9] = {0};
int nsteps = 0;
/* alternate can_connect */
int max(int x, int y)
{
return x >= y? x: y;
}
@zhangsen
zhangsen / import.rb
Created June 14, 2012 07:55 — forked from dnagir/import.rb
Import a blogger archive to jekyll (octopress version, allows quotes in titles)
require 'rubygems'
require 'nokogiri'
require 'fileutils'
require 'date'
require 'uri'
# usage: ruby import.rb my-blog.xml
# my-blog.xml is a file from Settings -> Basic -> Export in blogger.
data = File.read ARGV[0]
@zhangsen
zhangsen / 0-1-knapsack.py
Created June 17, 2012 02:37
0-1 knapsack with exact total weight and minimal total value
# http://programmers.stackexchange.com/questions/117136/converting-a-bounded-knapsack-problem-to-0-1-knapsack-problem
# weight: cable length
# total weight: target span
# value: 1 for each cable
# want minimum number of cables, i.e. minimum total value
def knapsack_01_exact_min(weights, values, W):
# 0-1 knapsack, exact total weight W, minimizing total value
n = len(weights)
@zhangsen
zhangsen / gist:3082270
Created July 10, 2012 09:26
braindead downloader
import threading, sys
import urlparse, httplib
is_done = False
class Downloader(threading.Thread):
def __init__(self, url, buf, n, semin, semout):
self.buf = buf
self.bufn = n
self.semin = semin
@zhangsen
zhangsen / simple-template.rb
Created January 7, 2013 15:09
rails template
#
# Rails template: rspec, guard, spork, libnotify, capybara
# $ rails -T -m <path-to-me>
gem_group :development, :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'guard-spork'
gem 'spork'
end