Skip to content

Instantly share code, notes, and snippets.

View yuanfeiz's full-sized avatar

YuanfΞi Zhu yuanfeiz

  • The Homestead Arcology
View GitHub Profile
@yuanfeiz
yuanfeiz / safe_min.rb
Created May 23, 2013 05:14
Both `pos_e` and `pos_c` can be `nil`, if one is `nil` then return the other.
pos_beg = [pos_e || pos_c, pos_c || pos_e].min
@yuanfeiz
yuanfeiz / retry_me_and_exception_me.rb
Created March 26, 2013 08:37
Experiment on exception and `retry` of Ruby: what scope does the `retry` call effect? Answer is the method that invokes `retry_me`.
def retry_me(&block)
begin
yield
rescue
retry
end
end
def say_hi
retry_me do
@yuanfeiz
yuanfeiz / macro.sty
Created March 15, 2013 07:31
misc latex macro
% general
\newcommand{\intro}[1]{{\em #1}\/}
\def\mynote#1{$\clubsuit$ {\sf #1 } $\clubsuit$}
\newcommand{\myparagraph}[1]{\medskip \noindent{\bf #1}}
%\def\dpar{{c}}
%\def\dval{\alpha}
\def\prop{{r}} % an atomic proposition
\def\prob{\mathrm{Pr}} % probability measure
observable_body_parts__target(eye).
observable_body_parts__body_part(eye).
leadership__target(head).
leadership__leader(head).
state_of_entity__target(conditions).
state_of_entity__state(conditions).
getting__target(get).
getting__theme(gaze_on_target).
getting__recipient(the_eye).
capability__target(can).
@yuanfeiz
yuanfeiz / comment_js.md
Created December 31, 2012 17:01
my farbox extension

status:part

<div class="ds-thread"></div>
<script type="text/javascript">
var duoshuoQuery = {short_name:"stranbird"};
(function() {
	var ds = document.createElement('script');
	ds.type = 'text/javascript';ds.async = true;
	ds.src = 'http://static.duoshuo.com/embed.js';

ds.charset = 'UTF-8';

@yuanfeiz
yuanfeiz / elect.rb
Created December 29, 2012 12:50
electsys login
# encoding: utf-8
require 'mechanize'
def doit
agent = Mechanize.new
# agent.set_proxy "localhost", 8001
page = agent.get url
form = page.form("frm")
form.txtUserName = username
form.txtPwd = password

Directory Tree:

  NLP/
    pipeline.rb
    stanford-segmenter-2012-11-11/
      test.simp.utf8
      segment.sh
    stanford-postagger-full-2012-11-11/
      models/
 stanford-postagger.sh
@yuanfeiz
yuanfeiz / get_pdf.rake
Created November 17, 2012 08:02
Download PDF files from a WebPage
require 'nokogiri'
require 'open-uri'
require 'cocaine'
task :default do
pattern = ':url'
line = Cocaine::CommandLine.new('wget', pattern)
base_url = 'http://www.cs.sjtu.edu.cn/~jdyu/teaching/SE/fall2012/'
file = 'index.html'
@yuanfeiz
yuanfeiz / MailToReminders.scpt
Created November 14, 2012 16:08
mail to reminders
tell application "Mail"
using terms from application "Mail"
set selectedMails to selection
set theMessage to first item of selectedMails
set theBody to "message:%3C" & message id of theMessage & "%3E"
set theSubject to the subject of theMessage & " (From " & the sender of theMessage & ")"
tell application "Reminders"
set theList to list "Inbox"
set newToDo to make new reminder with properties {name:theSubject, body:theBody, container:theList}
end tell
@yuanfeiz
yuanfeiz / Gemfile
Created November 8, 2012 09:59
blueprint for simple ruby script
source "http://ruby.taobao.org"
group :development do
gem "guard-ruby"
gem 'rb-fsevent', '~> 0.9.1'
end