Skip to content

Instantly share code, notes, and snippets.

View simple-template.rb
#
# 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
@zhangsen
zhangsen / gist:3082270
Created Jul 10, 2012
braindead downloader
View gist:3082270
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 / 0-1-knapsack.py
Created Jun 17, 2012
0-1 knapsack with exact total weight and minimal total value
View 0-1-knapsack.py
# 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 / import.rb
Created Jun 14, 2012 — forked from dnagir/import.rb
Import a blogger archive to jekyll (octopress version, allows quotes in titles)
View import.rb
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 / android-unlock.c
Created May 13, 2012
number of patterns of android unlock screen
View android-unlock.c
#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 / 2-devel
Created Dec 2, 2011
/etc/conary/system-model head
View 2-devel
# /etc/conary/system-model for fl:2-devel
search 'group-world=foresight.rpath.org@fl:2-devel/2.5.2+2011.11.18-0.2-2[~!bootstrap,~buildtests,~!cross,desktop,~!dom0,~!domU,~!gcc.core,~grub.static,ipv6,~kernel.debugdata,krb,ldap,pam,~!pie,readline,ssl,tcl,tk,~!vmware,~!xen is: x86(i486,i586,i686,sse,sse2) x86_64]'
install group-gnome-dist
@zhangsen
zhangsen / gist:1421895
Created Dec 2, 2011
pkgs out of group
View gist:1421895
4Suite-XML
915resolution
abby
aiksaurus
aircrack-ng
akode
amazonmp3
aMule
anaconda-templates
android-sdk
@zhangsen
zhangsen / gist:1421246
Created Dec 2, 2011
analyze fl packages
View gist:1421246
find * -type f ! \( -name '*.recipe' -o -name '*.patch' \) | while read f; do if ! file $f | grep -qi 'text\|xml\|empty'; then echo $f; fi; done > /tmp/files.bin
cat /tmp/files.bin | while read ln; do pkg=`echo "$ln" | cut -d/ -f1`; f=`echo "$ln" | cut -d/ -f2`; grep -q "$f" $pkg/$pkg.recipe && echo $ln; done > /tmp/files.bin.directly-referenced
diff -u /tmp/files.bin.directly-referenced /tmp/files.bin | grep '^+[^+]' | cut -c2- > /tmp/files.bin.un-refed
xargs -a /tmp/files.bin -d '\n' du -s | sort -nr > /tmp/files.bin-sizes-no-human
du -s * | sort -nr > /tmp/pkgs.size
cat /tmp/files.bin | grep -v 'png\|jpg\|svg\|vimrc' > /tmp/files.exclude-pics
@zhangsen
zhangsen / gist:1416742
Created Dec 1, 2011
sample use of conary api
View gist:1416742
from conary import conaryclient, conarycfg
from conary.state import ConaryStateFromFile
cfg =conarycfg.ConaryConfiguration()
client = conaryclient.ConaryClient(cfg)
repos = client.getRepos()
conaryState = ConaryStateFromFile('CONARY', repos)
You can’t perform that action at this time.