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 / main.py
Created February 14, 2018 14:19
demo of finding closest point on the closest path to a given query point, see <https://spaceandtim.es/code/closest_edges/>
import numpy as np
from pyqtree import Index
from shapely import geometry
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
plt.style.use('ggplot')
# distance we expect the bus stop to be from the road
# will pad all bounding boxes accordingly
radius = 0.1
@frnsys
frnsys / index.html
Last active December 8, 2016 22:32
react setup
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>hello</title>
</head>
<body>
<div id="root">Loading...</div>
<script src="bundle.js"></script>
! Enabled modi
rofi.modi: window,run,ssh
! Window opacity
rofi.opacity: 100
! Window width
rofi.width: 50
! Number of lines
rofi.lines: 15
! Number of columns
rofi.columns: 1
@frnsys
frnsys / 2d_to_3d.py
Created May 6, 2016 02:05
take a 2d numpy array of category labels and turn it into a 3d one-hot numpy array
import numpy as np
# the 2d array of our samples,
# each component is a category label
a = np.array([[1,2,3],[4,5,6]])
# the 3d array that will be the one-hot representation
# a.max() + 1 is the number of labels we have
b = np.zeros((a.shape[0], a.shape[1], a.max() + 1))

Keybase proof

I hereby claim:

  • I am frnsys on github.
  • I am frnsys (https://keybase.io/frnsys) on keybase.
  • I have a public key ASAvmZ40BDsDnDvSA1Gk5otOjOKmLmFe-tK1dGb3S18gjAo

To claim this, I am signing this object:

@frnsys
frnsys / optics.py
Last active August 18, 2017 07:33 — forked from ryangomba/optics.py
OPTICS clustering in Python
# Copyright (c) 2012, Ryan Gomba
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
@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 / 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 / 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.
"""
# 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