Skip to content

Instantly share code, notes, and snippets.

View motivic's full-sized avatar

Johnson Jia motivic

View GitHub Profile
@motivic
motivic / keybase.md
Created December 3, 2018 04:54
Keybase identity verification

Keybase proof

I hereby claim:

  • I am motivic on github.
  • I am motivic (https://keybase.io/motivic) on keybase.
  • I have a public key whose fingerprint is B77E 6212 9274 6C04 47C9 A42D EA79 3DCC A0C4 8858

To claim this, I am signing this object:

@motivic
motivic / ethermining.sh
Last active December 30, 2017 20:03
ethminer start/stop shell script for crontab
#!/usr/bin/env bash
# Inspired by https://forum.ethereum.org/discussion/13723/cron-the-miner
ethminer=/opt/ethminer
wallet=08adb68e47e6552f23a5d34feb0d7b47852522b6
log="$HOME/log/ethminer_$(date "+%Y%m%d_%H%M%S").log"
case $1 in
start)
$ethminer --farm-recheck 200 --cuda --stratum us1.ethermine.org:4444 -SF us1.ethermine.org:14444 --userpass $wallet > $log 2>&1 &
@motivic
motivic / tmux_local_install.sh
Last active November 22, 2016 19:32 — forked from sharjeelsayed/tmux_local_install.sh
bash script for installing tmux without root access.Updated to include latest Tmux version and some other minor changes
#!/bin/bash
# Source: https://gist.github.com/ryin/3106801
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# Updated to install TMUX_VERSION 2.3 from https://tmux.github.io/
# exit on error
set -e
@motivic
motivic / regularization.py
Created November 7, 2016 03:27
Learning from Data: Regularization with Weight Decay Exercise
import numpy as np
# Read in the data
data = []
with open('in.dta', 'r') as input:
row = [float(x) for x in input.readline().strip().split(' ') if x != '']
while row:
data.append(row)
row = [float(x) for x in input.readline().strip().split(' ') if x != '']
training_x = np.array([p[:2] for p in data])
@motivic
motivic / logistic.py
Created October 31, 2016 18:05
Learning from Data: Logistic Regression Exercise
import numpy as np
# Find f(x), where f is the line through p1 and p2
def f(p1, p2, x):
return (p2[1]-p1[1])/(p2[0]-p1[0])*(x-p1[0])+p1[1]
epochs = []
Eouts = []
N = 100
@motivic
motivic / nn_activation_plot.py
Created October 30, 2016 16:13
Comparing neural network activation units: tanh, relu, sigmoid/softmax, softplus
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-2, 2, 0.1)
# Hyperbolic Tangent
y_tanh = np.tanh(x)
# Sigmoid/Softmax
sigmoid = lambda t: 1/(1+np.exp(-t))
sigmoid_vec = np.vectorize(sigmoid, otypes=[np.float])
@motivic
motivic / git-show-objects.sh
Created October 27, 2016 20:50
Print out uncompressed contents of `.git/objects`
#!/usr/bin/env bash
base_dir=".git/objects"
blue=$(tput setaf 4)
normal=$(tput sgr0)
for d in $(ls -R $base_dir); do
if [[ -d "$base_dir/$d" ]]; then
for f in $(ls -R $base_dir/$d); do
file="$base_dir/$d/$f"
@motivic
motivic / perceptron.py
Last active October 31, 2016 18:05
Learning from Data: Perceptron Exercise
import numpy as np
# Find f(x), where f is the line through p1 and p2
def f(p1, p2, x):
return (p2[1]-p1[1])/(p2[0]-p1[0])*(x-p1[0])+p1[1]
# Get random points p1 and p2
p1, p2 = np.random.rand(2, 2)
line = lambda x: f(p1, p2, x)
@motivic
motivic / const.py
Created August 30, 2016 13:05
Alex Martelli's constants in Python
# http://code.activestate.com/recipes/65207-constants-in-python/?in=user-97991
# Put in const.py...:
class _const:
class ConstError(TypeError): pass
def __setattr__(self,name,value):
if self.__dict__.has_key(name):
raise self.ConstError, "Can't rebind const(%s)"%name
self.__dict__[name]=value
import sys
sys.modules[__name__]=_const()
@motivic
motivic / lexical_scoping.py
Created August 26, 2016 00:41
Python lexical scoping
# https://google.github.io/styleguide/pyguide.html
i = 4
def foo(x):
def bar():
print i,
# ...
# A bunch of code here
# ...
for i in x: # Ah, i *is* local to Foo, so this is what Bar sees
print i,