Skip to content

Instantly share code, notes, and snippets.

View aliciawyy's full-sized avatar

Alice Wang aliciawyy

  • Paris, France
  • 13:22 (UTC +02:00)
View GitHub Profile
@aliciawyy
aliciawyy / ClimbStairs
Last active August 29, 2015 14:03
LeetCode Online Judge codes
/**
* This is the solution for the test
* https://oj.leetcode.com/problems/climbing-stairs/
* It follows a cached Fibonacci startegy.
*/
public class Solution {
public void Init(int n)
{
nsteps = new int[n+1];
@aliciawyy
aliciawyy / fomc.py
Last active April 26, 2016 12:00
scrape web page with javascript
"""
Fetch all the FOMC meeting dates(since 1936) from the official website of FOMC.
The dates are separated in two parts
- 2010 - 2016 on https://www.federalreserve.gov/monetarypolicy/fomccalendars.htm
- Before 2010 on https://www.federalreserve.gov/monetarypolicy/fomc_historical.htm, this part contains some code in javascript.
"""
from urllib import urlopen
@aliciawyy
aliciawyy / plotting.py
Created June 13, 2016 13:22
plotting with slide bar
"""
Plotting functions
"""
import plotly.plotly as py
import plotly.graph_objs as go
def plot_time_series(df, title=None):
trace = go.Scatter(x=df.index, y=df)
@aliciawyy
aliciawyy / gradient_descent.py
Created June 13, 2016 13:23
gradient descent
"""
Numerical methods
"""
import numpy as np
from sklearn.datasets.samples_generator import make_regression
import pylab
from scipy import stats
def predict(x, theta):
@aliciawyy
aliciawyy / Dockerfile
Last active April 26, 2017 14:12
config files of a python project using jupyter notebook in docker (server)
## Edited on 21 June, Alice Wang
## To build the docker image
## $ cd .
## $ docker build -t fc .
FROM debian:8.3
RUN DEBIAN_FRONTEND=noninteractive apt-get update --fix-missing
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python2.7 python2.7-dev pkg-config
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y libxml2-dev libxslt-dev python-lxml
@aliciawyy
aliciawyy / stats.py
Created June 22, 2016 12:12
math functions
def autocorr(x):
# auto correlation
# from http://tinyurl.com/afz57c4
result = np.correlate(x, x, mode='full')
result = result / np.max(result)
return result[result.size / 2:]
@aliciawyy
aliciawyy / via_server.py
Created July 12, 2016 09:10
to transfer files between server and local machine
"""
To transfer and fetch the data from server
"""
import os
import paramiko
class InternalSSHClient(object):
"""
Examples
@aliciawyy
aliciawyy / Button to hide code in a python notebook
Created September 19, 2016 13:41
Button to hide code in a python notebook
import IPython.core.display as di
# This line will hide code by default when the notebook is exported as HTML
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)
# This line will add a button to toggle visibility of code blocks, for use with the HTML export version
di.display_html('''<button onclick="jQuery('.input_area').toggle(); jQuery('.prompt').toggle();">Toggle code</button>''', raw=True)
@aliciawyy
aliciawyy / count.py
Created January 29, 2017 10:36
Count the most frequent element in list
import collections
lst = [1, 3, 1, 4, 2, 5, 3, 4, 3]
cnt = collections.Counter(lst)
cnt.most_common(1)
@aliciawyy
aliciawyy / patterns.py
Last active July 14, 2017 12:15
Notes on pattern
# inheritance vs delegation
# http://www.jguru.com/faq/view.jsp?EID=27916