Skip to content

Instantly share code, notes, and snippets.

View mwdchang's full-sized avatar

Daniel Chang mwdchang

View GitHub Profile
@mwdchang
mwdchang / index.html
Created June 4, 2018 02:49
Tensorflow JS core test
<!DOCTYPE html>
<html lang="en">
<head>
<script src="tf.min.js"></script>
</head>
<body>
</body>
<script>
const LEARNING_RATE = 0.07;
const UNDEF = 'undefined';
const alpha = 2;
const beta = .5;
/* Utility */
const createArray = (x, y) => {
let r = [];
if (typeof x !== UNDEF && typeof y !== UNDEF) {
for (let i=0; i < x; i++) {
r.push(createArray(y));
@mwdchang
mwdchang / scratch.rq
Created March 26, 2018 20:06
SPARQL scratch pad
##################################################################
# Get count of predicates
##################################################################
SELECT ?p (COUNT(?o) AS ?cnt)
WHERE { ?s ?p ?o }
GROUP BY ?p
ORDER BY DESC(?cnt)
##################################################################
@mwdchang
mwdchang / scraper.sh
Created March 16, 2018 11:27
Scrapes baseball reference player mug shots
#!/usr/bin/env bash
PLAYER_ID=$1
IDX=${PLAYER_ID:0:1}
URL="https://www.baseball-reference.com/players/${IDX}/${PLAYER_ID}.shtml"
echo "$URL"
curl ${URL} | grep "og:image" | egrep -o "http.*((jpg)|(png))" | xargs curl -o ${PLAYER_ID}
sips -s format jpeg ${PLAYER_ID} --out ${PLAYER_ID}.jpg
@mwdchang
mwdchang / dnn.py
Created February 9, 2018 04:47
Tensorflow DNN scratch pad
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"]="2"
import tensorflow as tf
import numpy as np
## TODO
## - Move learning rate
## - Save model, restore model
class NNModel():
@mwdchang
mwdchang / server.js
Created October 17, 2017 15:37
Simple node proxy server
const express = require('express')
const app = express()
const proxy = require('express-http-proxy')
app.use('/', proxy('proxy-destination.com'))
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
@mwdchang
mwdchang / config.json
Created February 19, 2017 04:34
OICR proxy dashboard
[
{
"cmd": "ssh -D9002 proxy-something.lalala.com",
"des": "SOCK5 Proxy to proxy-something"
},
{
"cmd": "ssh -D9003 proxy-something-else.lalala.com",
"des": "SOCK5 Proxy to hproxy-dev"
},
{
@mwdchang
mwdchang / parallel.R
Created January 20, 2017 21:10
Background R processing
library(parallel)
library(background)
cache = new.env();
cache[["t"]] <- "f"
#* @get /set
set <- function() {
@mwdchang
mwdchang / PCC.js
Last active November 1, 2016 02:05
Pearson correlation coefficient function
// Based on: https://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient
static PCC(x, y) {
let n = x.length;
let sum_xy = 0;
let sum_x2 = 0;
let sum_y2 = 0;
let meanx = 0, meany = 0;
for (let i=0; i < n; i++) {
sum_xy += x[i]*y[i];
sum_x2 += x[i]*x[i];
@mwdchang
mwdchang / index.html
Last active July 13, 2016 15:06
D3 v4 odd zoom behaviour
<!DOCTYPE HTML>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
#div1 {
width: 500px;
height: 500px;
background: #CCC;
}