Skip to content

Instantly share code, notes, and snippets.

View frnsys's full-sized avatar
🏠
Working from home

Francis Tseng frnsys

🏠
Working from home
View GitHub Profile
@frnsys
frnsys / markov.py
Last active August 29, 2015 13:56
A very simple Markov chain generator
# -*- coding: utf-8 -*-
text = """
The Eagle has landed. The regret on our side is, they used to say years ago, we are reading about you in science class. Now they say, we are reading about you in history class.
Never in all their history have men been able truly to conceive of the world as one: a single sphere, a globe, having the qualities of a globe, a round earth in which all the directions eventually meet, in which there is no center because every point, or none, is center, an equal earth which all men occupy as equals. The airman's earth, if free men make it, will be truly round: a globe in practice, not in theory.
For those who have seen the Earth from space, and for the hundreds and perhaps thousands more who will, the experience most certainly changes your perspective. The things that we share in our world are far more valuable than those which divide us.
"""
@frnsys
frnsys / patcher.py
Created March 6, 2014 20:02
dynamic patcher
from unittest.mock import patch
class Patcher():
"""
This class provides a central place for managing
commonly used patches for tests.
Example::
p = Patcher([
@frnsys
frnsys / tmux.conf
Created March 17, 2014 02:03
tmux.conf
# Required for vim's copy and paste to work in tmux.
# Install this first:
# brew install reattach-to-user-namespace --wrap-pbcopy-pbpaste && brew link reattach-to-user-namespace
set-option -g default-command "reattach-to-user-namespace -l bash"
# Set Ctrl-a as prefix
# (instead of Ctrl-b)
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Adapted from
# http://pytables.github.io/usersguide/libref/homogenous_storage.html#the-carray-class
import os
import numpy
import tables
from itertools import groupby
from operator import itemgetter
from time import time
@frnsys
frnsys / hac.py
Last active August 29, 2015 14:10
simple HAC implementation
import operator
from itertools import combinations
from functools import reduce
import numpy as np
def hac(vecs, sim_func, threshold):
"""
Hierarchical Agglomerative Clustering.
"""
@frnsys
frnsys / contagion.py
Created July 9, 2015 18:47
contagion model
import random
import networkx as nx
class Person():
def __init__(self, name, stance=None):
self.name = name
if stance is None:
self.stance = random.randrange(0, 2)
else:
@frnsys
frnsys / train_doc2vec.py
Last active August 29, 2015 14:25
train and infer with doc2vec
import sys
import logging
import numpy
import gensim
logging.basicConfig(level=logging.INFO)
train_sentences = gensim.models.doc2vec.LabeledLineSentence(sys.argv[1])
model = gensim.models.Doc2Vec(train_sentences, size=400, window=8, min_count=2,
@frnsys
frnsys / (client)controller.js
Created July 28, 2012 00:38 — forked from tresbailey/(client)controller.js
Chat App using nodejs for server, socket.io for passing messages to/from the browser, coffeescript for some server-side files (for now), node-redis for persisting chats, express(node) for http wrapping, and jade for templating (for now), and backbone for
var NodeChatController = {
init: function() {
this.socket = io.connect('http://localhost');
var mysocket = this.socket;
this.model = new models.NodeChatModel();
this.view = new NodeChatView({model: this.model, socket: this.socket, el: $('#content')});
var view = this.view;
this.socket.on('message', function(msg) {
@frnsys
frnsys / omniauth.rb
Created January 30, 2013 19:05
Omniauth initializer for Google Reader
require 'yaml'# Load auth config
AUTH_CONFIG = YAML.load_file("#{::Rails.root}/config/auth.yml")[::Rails.env]
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, AUTH_CONFIG["client_id"], AUTH_CONFIG["client_secret"], {
scope: 'https://www.googleapis.com/auth/userinfo.email https://www.google.com/reader/api/'
}
end
@frnsys
frnsys / auth.yml
Last active December 11, 2015 23:18
auth config for omniauth w/ google reader api
development:
client_id: [your client id]
client_secret: [your client secret]
test:
client_id: [your client id]
client_secret: [your client secret]
production: