Skip to content

Instantly share code, notes, and snippets.

View kennethzfeng's full-sized avatar

Kenneth Feng kennethzfeng

View GitHub Profile
@kennethzfeng
kennethzfeng / analysis_import.py
Last active May 15, 2018 17:40
IPython Notebook Data Analysis Boilerplate
import numpy as np
import pandas as pd
from pandas import DataFrame, Series
pd.set_option("display.max_rows", 100)
pd.set_option("display.max_columns", 400)
@kennethzfeng
kennethzfeng / walk.py
Created March 28, 2014 05:30
Demo on Python's os module's walk function
#!/usr/bin/python
import os
def walk(dir):
for (root, dirs, files) in os.walk(dir):
for file in files:
path = os.path.join(root, file)
print(repr(path))
if __name__ == "__main__":
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@kennethzfeng
kennethzfeng / .gitconfig
Last active August 29, 2015 14:04
Command Line Git Log Visualization
[alias]
lg = log --graph --pretty='%C(yellow)%h%Creset%C(blue)%d %Creset%C(white bold)%s %Creset%C(white dim)(by %cn %cr)'
@kennethzfeng
kennethzfeng / dynamic.js
Created August 13, 2014 03:11
Dynamically Create Javascript Classes
function AccountFactory(name) {
function AccountClass(accountNumber) {
this.accountNumber = accountNumber;
}
AccountClass.getClassName = function() {
return name + 'Account';
};
return AccountClass;
@kennethzfeng
kennethzfeng / text_cleanup.R
Created August 29, 2014 14:18
Clean up comma, period, etc & lowercase the text
# Clean comma and lower case text
cleanup <- function (text) {
temp <- text
# Clean up comma and period
temp <- gsub('[,.! ]', '', temp)
# To Lowercase
temp <- tolower(temp)
return(temp)
@kennethzfeng
kennethzfeng / parse_rst.py
Created August 31, 2014 22:16
rsStructureText to Node Tree using docutils
"""
Parse reStructureText into Node Tree
"""
from docutils.parsers.rst import Parser
from docutils.utils import new_document
from docutils.frontend import OptionParser
import logging
@kennethzfeng
kennethzfeng / fix_column_name.py
Last active August 29, 2015 14:06
Fix DataFrame Column Names
import re
def fix_column_name(column_name):
temp = column_name.strip()
temp = re.sub('[.,]', '', temp)
temp = temp.replace(' ', '_')
return temp.lower()
@kennethzfeng
kennethzfeng / split.py
Created October 1, 2014 15:47
Python Tips
# http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python
def chunks(l, n):
""" Yield successive n-sized chunks from l."""
for i in xrange(0, len(l), n):
yield l[i:i+n]