Skip to content

Instantly share code, notes, and snippets.

@zfz
zfz / guess_the_number.py
Last active August 29, 2015 14:15
Mini Projets for An Introduction to Interactive Programming in Python Session 2
# template for "Guess the number" mini-project
# input will come from buttons and an input field
# all output for the game will be printed in the console
# Mini Project 2 for An Introduction to Interactive Programming in Python
# URL http://www.codeskulptor.org/#user39_L4LKshd1tOatpPt_2.py
import random
import simplegui
# Install xcode command line tools
xcode-select --install
# Install home brew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install git
brew install git
# Install python
@zfz
zfz / install-rails-dev.sh
Last active August 29, 2015 14:17
rails env install script on vagrant ubuntu
sudo apt-get update
sudo apt-get install -y git-core curl zlib1g-dev build-essential \
libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 \
libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common nodejs
# Install rbenv
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# Install pip in for an virtualenv, from digital ocean documents
curl https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py | python2.7 -
pip install virtualenv
virtualenv venv
@zfz
zfz / reverse_geocoder_example.py
Created April 3, 2015 04:18
A Python library for offline reverse geocoding, https://github.com/thampiman/reverse-geocoder
In [1]: import reverse_geocoder as rg
In [2]: coordinates = (39.99, 116.48),
In [3]: results = rg.search(coordinates)
Loading formatted geocoded file...
In [4]: print results
[{'name': 'Wangjing', 'cc': 'CN', 'lon': '116.47284', 'admin1': 'Beijing', 'admin2': '', 'lat': '39.9933'}]
@zfz
zfz / scheduled.py
Last active August 29, 2015 14:24
schedule decorator
import schedule
import time
def scheduled(t):
def wrapper(func):
schedule.every(7).days.at(t).do(func)
while True:
schedule.run_pending()
time.sleep(1)
#!/bin/bash
unset LANG # deal with "illegal byte sequence" error
for filename in *txt; do
echo $filename
ex $filename "+set ff=unix fileencoding=utf-8" "+x"
done
#!/usr/bin/env python
#-*-coding: utf-8 -*-
import urllib2
import sys
def load_url(f):
return [line.strip() for line in open(f)]
@zfz
zfz / Tweetsheets
Created August 12, 2012 08:11 — forked from johannesnagl/Tweetsheets
Use Twitter directly in your Google Doc, so no one will ever blame you for being social
var CONSUMER_KEY = "<< YOUR KEY HERE >>";
var CONSUMER_SECRET = "<< YOUR SECRET HERE >>";
function getConsumerKey() {
return CONSUMER_KEY;
}
function getConsumerSecret() {
return CONSUMER_SECRET;
}
@zfz
zfz / Print_results.py
Created November 24, 2012 08:47
Recursive version: Depth First Search in a Graph
Graph:
{'a': {'d': 1, 'g': 1}, 'c': {'g': 1}, 'b': {'f': 1}, 'e': {'h': 1, 'f': 1}, 'd': {'a': 1, 'g': 1}, 'g': {'a': 1, 'c': 1, 'd': 1}, 'f': {'b': 1, 'e': 1}, 'h': {'e': 1}}
List example:
set(['a', 'c', 'd', 'g'])
set(['a', 'c', 'd', 'g'])
Dict example:
{'a': True, 'c': True, 'd': True, 'g': True}
{'a': True, 'c': True, 'd': True, 'g': True}