Skip to content

Instantly share code, notes, and snippets.

View ktmud's full-sized avatar
🥌
Peace and Love~

Jesse Yang ktmud

🥌
Peace and Love~
View GitHub Profile
@ktmud
ktmud / data.js
Last active October 17, 2018 20:29
MBTA Data Visualization - Brushing and Linking
var dispatch = d3.dispatch("dataLoaded", "stationHovered", "nodesUpdated");
d3.json("stations.json", function(error, stations)
{
var data = {};
data.nodes = stations.nodes;
data.links = stations.links;
for(var i = 0; i < data.nodes.length; i++)
{
@ktmud
ktmud / LDA-Explained.py
Last active October 16, 2018 16:21
LDA in 5 LOC (Explained)
import numpy as np
np.set_printoptions(precision=4)
np.random.seed(19894)
def gen_data(N=50):
X1 = np.random.uniform(0, 3, N)
X2 = np.random.uniform(0, 3, N)
pi = 1/(1+np.exp(-(-3+X1+X2)))
# a randomly selected variable between 0-1 is has the probability pi
@ktmud
ktmud / LDA.py
Last active October 16, 2018 16:23
LDA in 5 LOC
means = np.array([np.mean(X[y == k], axis=0) for k in labels]).T
pies, cov = np.array([np.mean(y == k) for k in labels]), np.cov(X.T)
cov_inv = np.linalg.inv(cov)
np.argmax(X @ cov_inv @ means - np.diag(0.5 * means.T @ cov_inv @ means) +
np.log(pies), axis=1)
@ktmud
ktmud / .block
Last active October 5, 2019 22:11
D3 Bar Chart and Scatter Plot Example
license: MIT
@ktmud
ktmud / notebook.py
Last active October 13, 2018 20:10
Jupyter Notebook Head Matters
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="ticks", color_codes=True)
@ktmud
ktmud / lldb-vagrant.md
Last active June 4, 2018 06:40
VSCode lldb remote debug from macOS to Linux in Vagrant

First, in Vagrantfile, expose enough ports for lldb and automatically spawn gdbserver processes:

  for i in 44000..44100
    config.vm.network :forwarded_port, guest: i, host: i
  end

Don't forget to vagrant reload.

@ktmud
ktmud / size.py
Created March 27, 2018 20:50 — forked from cbwar/size.py
Python: Human readable file size
def sizeof_fmt(num, suffix='o'):
"""Readable file size
:param num: Bytes value
:type num: int
:param suffix: Unit suffix (optionnal) default = o
:type suffix: str
:rtype: str
"""
for unit in ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z']:
@ktmud
ktmud / coord_to_ct.R
Created November 21, 2017 03:11
Match Geographic Coordinates with Polygons R
##
# Map businesses to census tracts
#
library(tidyverse)
library(sp)
library(spdplyr)
library(rgdal)
if (!exists('businesses')) {
# all businesses
@ktmud
ktmud / acs.R
Created November 1, 2017 04:05
Get a curated list of census data for any geographic unit
library(zipcode)
library(magrittr)
library(dplyr)
library(stringr)
library(acs)
# load all zipcodes
data(zipcode)
# as copied from the BARI's ACS indicators R syntax
cluster pt x y num_neighbors neighbors
-1 0 51.41808903 13.59361029 2 0,27
0 1 39.1323184 -4.419204415 3 1,40,75
-1 2 47.8075151 -25.82256055 1 2
-1 3 27.69970293 53.43419307 1 3
0 4 39.86099482 5.676870902 3 4,56,75
1 5 -19.89185932 10.41027381 3 5,70,74
1 6 -0.050282532 -4.032522276 3 6,14,42
-1 7 18.56251189 -28.65497991 1 7
1 8 -14.62990365 -4.887040158 5 8,11,60,63,72