This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import os | |
from time import gmtime, strftime | |
import subprocess | |
BASE_URL = "http://commondatastorage.googleapis.com/books/ngrams/books/"; | |
downloading = False | |
def getCsvFileName(index): | |
return "googlebooks-eng-all-3gram-20090715-" + str(index) + ".csv" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from math import ceil | |
def FFTCompress(vals, max_mse): | |
#normalize | |
norm = np.linalg.norm(vals) | |
vals = [v / norm for v in vals] | |
#calc fft and | |
fx = np.fft.fft(vals) | |
#only the first ceil(n/2) coefficients are required as the input is real |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Conversion | |
def TwoTagSymbolToBinaryWord(A, s): | |
idx = A.index(s) | |
return ('0' * idx) + '1' + '0' * (len(A) - idx - 1) | |
def TwoTagWordToBinaryWord(A, w): | |
t = '' | |
for i in xrange(len(w)): | |
t += TwoTagSymbolToBinaryWord(A, w[i]) | |
return t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib2 | |
import urlparse | |
import re | |
from bs4 import BeautifulSoup | |
downloadQ = [] | |
downloaded = set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib2 | |
import datetime | |
from os.path import isfile, join | |
from os import getcwd | |
tFile = open("tickers.txt") | |
eYear = datetime.datetime.now().year | |
eMonth = datetime.datetime.now().month |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// A recursive simulator which uses an internal stack instead of the .NET stack. DFS traversing over the recursion. | |
/// </summary> | |
/// <typeparam name="INPUT">The input of the recursive function</typeparam> | |
/// <typeparam name="OUTPUT">The output of the recursive function</typeparam> | |
/// <example> | |
/// var fibonachi = new RecursiveIterator<int, int>() | |
/// { | |
/// Branch = n => new int[] { n - 1, n - 2 }, | |
/// TrySetTrivialResult = (n, s) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// A recursive simulator which uses an internal stack instead of the .NET stack. DFS traversing over the recursion. The simulator will cache intermediate results and avoid unnecessary calls. | |
/// </summary> | |
/// <typeparam name="INPUT">The input of the recursive function</typeparam> | |
/// <typeparam name="OUTPUT">The output of the recursive function</typeparam> | |
/// <example> | |
/// var fibonachi = new CachedRecursiveIterator<int, BigInteger>() | |
/// { | |
/// Branch = n => new int[] { n - 1, n - 2 }, | |
/// TrySetTrivialResult = (n, s) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BufferQueueStream : Stream, IDisposable | |
{ | |
private const int INTERNAL_BUFFER_SIZE = 64 * 1024; | |
private System.ServiceModel.Channels.BufferManager bufferManager = System.ServiceModel.Channels.BufferManager.CreateBufferManager(INTERNAL_BUFFER_SIZE * 100, INTERNAL_BUFFER_SIZE); | |
private Queue<byte[]> _bufferQueue = new Queue<byte[]>(); | |
private byte[] _currentReadingBuffer; | |
private int _currentBufferPosition; | |
private long _totalLengthToRead = 0; | |
private long _position = 0; |