Skip to content

Instantly share code, notes, and snippets.

@fumingshih
fumingshih / android_AlarmManager_example.java
Created December 13, 2011 16:22
How to user AlarmManager to set the application running at scheduled time
Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());//set the current time and date for this calendar
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_YEAR, cur_cal.get(Calendar.DAY_OF_YEAR));
cal.set(Calendar.HOUR_OF_DAY, 18);
cal.set(Calendar.MINUTE, 32);
cal.set(Calendar.SECOND, cur_cal.get(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cur_cal.get(Calendar.MILLISECOND));
cal.set(Calendar.DATE, cur_cal.get(Calendar.DATE));
@fumingshih
fumingshih / Importing posts from Wordpress into Jekyll.rb
Created February 14, 2012 03:52 — forked from vitobotta/Importing posts from Wordpress into Jekyll.rb
The script I used to import posts from my Wordpress blog into a new Jekyll one.
%w(rubygems sequel fileutils yaml active_support/inflector).each{|g| require g}
require File.join(File.dirname(__FILE__), "downmark_it")
module WordPress
def self.import(database, user, password, table_prefix = "wp", host = 'localhost')
db = Sequel.mysql(database, :user => user, :password => password, :host => host, :encoding => 'utf8')
%w(_posts _drafts images/posts/featured).each{|folder| FileUtils.mkdir_p folder}
@fumingshih
fumingshih / gen_id_passwd
Created February 14, 2012 05:22
generating id/passwd
import string
from random import sample, choice
chars = string.letters + string.digits
length = 8
''.join(sample(chars,length)) # way 1
''.join([choice(chars) for i in range(length)]) # way 2
@fumingshih
fumingshih / gist:2230787
Created March 28, 2012 21:34
How to print a list of tuples to file as csv
open('tuples.csv', 'w').write('\n'.join('%s %s' % x for x in your_lst))
# suppose you have a lst of tuples like
# lst = [(item11, item12), (item21, item22), ...(item_n1, item_n2)]
import os
import sys
import sys
print sys.path
@fumingshih
fumingshih / gist:2422301
Created April 19, 2012 16:59 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
def get_loc_data(self):
return [x for x in self.numeric_lst if x[9] == 0]
def get_sit_data(self):
return [x for x in self.numeric_lst if x[9] == 1]
def get_bluetooth_data(self):
return [x for x in self.numeric_lst if x[9] == 2]
def get_location(self, idx):
return self.name_map['loc'][idx]
@fumingshih
fumingshih / gist:2970112
Created June 22, 2012 03:50
Fix FunfManager.unrequestAllData
public void unrequestAllData2(DataListener listener){
Map<IJsonObject,List<DataRequestInfo>> changedEntrySet = new HashMap<IJsonObject, List<DataRequestInfo>>();
synchronized (dataRequests) {
for (Entry<IJsonObject,List<DataRequestInfo>> entry : dataRequests.entrySet()) {
IJsonObject probeConfig = entry.getKey();
List<DataRequestInfo> dataRequestInfos = entry.getValue();
@fumingshih
fumingshih / gist:4942199
Created February 13, 2013 04:10
A shell script that allows you to install recommended fonts for texlive on Mac
curl http://packages.ubuntu.com/quantal/all/texlive-fonts-recommended/filelist | sed -En 's!/usr/share/texlive/texmf-dist/fonts/tfm/.*/([^/]+)/[^/]+\.tfm$!\1!p'
*.aux
*.glo
*.idx
*.log
*.toc
*.ist
*.acn
*.acr
*.alg
*.bbl