Skip to content

Instantly share code, notes, and snippets.

Avatar

Yuchen Ying yegle

  • Google
  • San Francisco Bay Area
View GitHub Profile
@yegle
yegle / opt.py
Created Jul 3, 2014
USCIS OPT application status query
View opt.py
#!/usr/bin/env python
# vim: set fileencoding=utf-8 ts=4 sw=4 tw=79 :
from __future__ import (unicode_literals, absolute_import,
division, print_function)
import requests
from lxml import etree
from io import StringIO
@yegle
yegle / appengine_config.py
Last active Aug 29, 2015
Use VirtualEnv to manage dependencies on GAE project
View appengine_config.py
import os
from google.appengine.ext import vendor
"""
1. Create a virtualenv directory at the root of your project, name it "venv"
2. Install packages needed in your project
3. Freeze it and save the package list into requirements.txt file, add it to
version control
4. Exclude "venv" directory from version control
5. Save the content of this file as "appengine_config.py", and put it at the
@yegle
yegle / list_reference_copy.py
Last active Aug 29, 2015
Create reference slice to a list in Python
View list_reference_copy.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
class MyList(list):
def __init__(self, raw_list, start=None, stop=None):
self.raw_list = raw_list
self.start = start or 0
self.stop = stop or len(raw_list)-1
@yegle
yegle / mkdir.sh
Created Oct 7, 2015
Create a directory that cannot be deleted in OS X
View mkdir.sh
mkdir -p confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14B---/confdir-14
@yegle
yegle / webpy-django-rest-api.py
Created Nov 2, 2012
REST API based on Django ORM and web.py
View webpy-django-rest-api.py
class API(app.page):
pass
class DjangoAPI(API):
model = None
def __init__(self):
self.qs = self.model.objects
self.exclude = []
@yegle
yegle / gist:4098405
Created Nov 17, 2012
python itertools
View gist:4098405
from itertools import product
import string
print(list(product(string.lowercase[:13],repeat=2)))
[('a', 'a'), ('a', 'b'), ('a', 'c'), ('a', 'd'), ('a', 'e'), ('a', 'f'), ('a', 'g'), ('a', 'h'), ('a', 'i'), ('a', 'j'), ('a', 'k'), ('a', 'l'), ('a', 'm'), ('b', 'a'), ('b', 'b'), ('b', 'c'), ('b', 'd'), ('b', 'e'), ('b', 'f'), ('b', 'g'), ('b', 'h'), ('b', 'i'), ('b', 'j'), ('b', 'k'), ('b', 'l'), ('b', 'm'), ('c', 'a'), ('c', 'b'), ('c', 'c'), ('c', 'd'), ('c', 'e'), ('c', 'f'), ('c', 'g'), ('c', 'h'), ('c', 'i'), ('c', 'j'), ('c', 'k'), ('c', 'l'), ('c', 'm'), ('d', 'a'), ('d', 'b'), ('d', 'c'), ('d', 'd'), ('d', 'e'), ('d', 'f'), ('d', 'g'), ('d', 'h'), ('d', 'i'), ('d', 'j'), ('d', 'k'), ('d', 'l'), ('d', 'm'), ('e', 'a'), ('e', 'b'), ('e', 'c'), ('e', 'd'), ('e', 'e'), ('e', 'f'), ('e', 'g'), ('e', 'h'), ('e', 'i'), ('e', 'j'), ('e', 'k'), ('e', 'l'), ('e', 'm'), ('f', 'a'), ('f', 'b'), ('f', 'c'), ('f', 'd'), ('f', 'e'), ('f', 'f'), ('f', 'g'), ('f', 'h'), ('f', 'i'), ('f', 'j'), ('f', 'k'), ('f', 'l'),
@yegle
yegle / bash-read-variable
Created Dec 11, 2012
bash read varaible
View bash-read-variable
#!/bin/bash
# FAIL!
echo a| read i
echo $i
# WORKS
read i <<<$(echo a)
echo $i
@yegle
yegle / runme.sh
Last active Nov 30, 2015
document problem in beancount
View runme.sh
#!/usr/bin/env bash
echo "Because gist doesn't support directory"
dir=$(dirname "$0")
mkdir -p "$dir/stmts/Assets/US/BoA"
touch "$dir/stmts/Assets/US/BoA/2015-01-31.statement"
@yegle
yegle / accounts.bean
Created Dec 1, 2015
include doesn't work with booking method
View accounts.bean
2014-09-03 open Assets:Vanguard:VXX VXX "NONE"
2014-09-03 open Expenses:Vanguard:Fee USD
2014-09-03 open Income:Hooli:Paycheck USD
@yegle
yegle / example.py
Created Jan 21, 2013
How to use Django's get_readonly_fields
View example.py
def get_readonly_fields(self, request, obj=None):
if obj and obj.is_processed:
return ('csv_file',) + self.readonly_fields
else:
return self.readonly_fields
You can’t perform that action at this time.