Skip to content

Instantly share code, notes, and snippets.

@ericjang
ericjang / globalValues.py
Created August 19, 2014 00:06
Python script that retrieves a pandas dataframe containing fundamental stock market valuation ratios
import requests
from bs4 import BeautifulSoup
import pandas as pd
import re
import sys
def globalValues:
url = 'http://www.starcapital.de/research/stockmarketvaluation?SortBy=Shiller_PE'
r = requests.get(url)
if r.status_code != 200:
@ericjang
ericjang / dollarcostaveraging.m
Created September 7, 2014 03:38
Dollar Cost Averaging reduces variance of returns. Thanks Ben!
ticker = 'USSPX'; % s&p500 index
periods = 1:100;
nP = numel(periods);
c = yahoo;
dates = {'Jan 1 2000','Sep 6 2014'};
prices = fetch(c,ticker,'Adj Close',dates{1},dates{2}); % should I use Close instead?
nDays = size(prices,1);
nTrials = 50;
returns = zeros(nTrials,nP);
tP = 50*nDays; % total principal invested over time
@ericjang
ericjang / feigenbaum.m
Created September 12, 2014 03:58
Feigenbaum Diagram
% feigenbaum diagram
r = 1:.01:4; % r values
nr = length(r); % number of r values
nI = 600; % number of iterations to perform for each r
converge = 300;
p = nan(converge,nr);
x = zeros(1,nI);
for rx=1:nr
x(1)=.5;
for i=2:nI
@ericjang
ericjang / ForwardDiff_example.jl
Last active August 29, 2015 14:13
Automatic Differentiation Example
# testing the automatic differentiation capabilities
using Cairo;
using DataFrames;
using Gadfly;
using ForwardDiff;
f(x) = sin(x[1]);
x = [-pi:.1:pi];
outf=[f(i) for i in x];
@ericjang
ericjang / netServer.js
Created May 8, 2012 09:04
IP address and stream data logging in NodeJS using the Net module
//note that this is just basic IP address routing. XSS exploit needed for more accurate location.
var http = require('http');
var server = http.createServer(function(req,res){
res.writeHead(200);
res.end('Hello HTTP');
console.log('client connected! ip address is ' + req.socket.remoteAddress);
});
server.listen(8080);
console.log('server listening at localhost:8080. Send your victim over!');
@ericjang
ericjang / college_parser.py
Created May 30, 2012 05:24
quick and dirty parsing for naviance college admission results
#script for parsing Mrs. Cao's file.
import csv
original = csv.reader(open('/Users/Eric/Desktop/destinations.csv','rU'))
f = open('/Users/Eric/Desktop/formattedList.txt', 'w')
current = ""
for row in original:
college = row[2]
@ericjang
ericjang / voleuse.py
Last active November 7, 2015 16:15
Based Prison School Cover Image Download
import requests
from bs4 import BeautifulSoup
import re
for v in range(1,18): # update chapter numbers as needed
fname = 'Volume_%02d.jpg' % v
url = 'http://prison-school.wikia.com/wiki/Category:Volume_Cover_Images?file=%s' % fname
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
pattern = r'http:\/\/vignette\d.wikia.nocookie.net\/prison-school\/images\/\w*\/\w*\/' + fname + '\/revision\/latest\/'
r = re.compile(pattern)
@ericjang
ericjang / hailstone.py
Created June 7, 2013 04:04
Hailstone Sequence (positive and negative starting numbers)
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import pdb
N_max = int(1e3) # numbers to try out
T_max = int(200) # max iterations
sequence = np.zeros((N_max, T_max), dtype=int)
@ericjang
ericjang / selfmodifying.jl
Created August 29, 2013 01:55
Self-modifying homoiconic expression written in the Julia Language.
ex = quote
s = string(ex)
o = s
array = uint8(collect(s))
for i = 1:length(array), bit = 0:7
if rand() < 1/(length(array)*8)
array[i] $= (0x01 << bit)
end
end
s = bytestring(array)
@ericjang
ericjang / gist:33ee2ef334fd833cab85
Last active December 30, 2015 09:07
genadv_algo1
for i in range(TRAIN_ITERS):
x= np.random.normal(mu,sigma,M) # sample minibatch from p_data
z= np.linspace(-5.0,5.0,M)+np.random.random(M)*0.01 # sample minibatch from noise prior
sess.run(opt_d, {x_node: x, z_node: z}) # update discriminator D
z= np.linspace(-5.0,5.0,M)+np.random.random(M)*0.01 # sample noise prior
sess.run(opt_g, {z_node: z}) # update generator G