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
# coding: utf-8 | |
import requests | |
import os.path | |
import time | |
def multiple_tries(func, times, timeout): | |
for cnt in xrange(1, times + 1): | |
try: | |
return func() | |
except Exception, e: |
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 string, sklearn, random | |
from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer | |
from sklearn.svm import SVC | |
from sklearn.pipeline import Pipeline | |
from sklearn.grid_search import GridSearchCV | |
from sklearn.cross_validation import StratifiedKFold | |
def tok(m): | |
return m.split() |
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
def fizzbuzz(n): | |
for i in xrange(1, n+1): print [i, 'Fizz', 'Buzz', 'FizzBuzz'][(i%3 == 0) + 2 * (i % 5 == 0)] |
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 void shuffleCards (int[] cards){ | |
int temp, index; | |
for (int i = 0; i < cards.length; i++){ | |
index = (int) (Math.random() * (cards.length - i)) + i; | |
temp = cards[i]; | |
cards[i] = cards[index]; | |
cards[index] = temp; | |
} | |
} |
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 boolean inUnique(string str) { | |
boolean[] chars = new boolean[256]; // Size only works with ASCII, increase otherwise. | |
for(int i=0; i<str.size(); i++){ | |
if(chars[str.charAt(i)]) return false; | |
chars[str.charAt(i)] = true; | |
} | |
return true; | |
} |
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
unsigned int i; | |
for(i=100; i<=0; --i) | |
print(i) |
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 boolean isUnique(string str) { | |
for(int i=0; i<str.size(); i++){ | |
for(int j=0; j<str.size(); j++) { | |
if(i==j) continue; | |
else if(str.charAt(j) == str.charAt(i)) return false; | |
} | |
} | |
return true; | |
} |
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
def validParentheses? str | |
a = [] | |
str.each_char do |x| | |
if x == '(' | |
a.push x | |
elsif x == ')' | |
return false if a.pop == nil | |
end | |
end | |
a.empty? |
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
def fizzbuzz(n): | |
print "\n".join([('Fizz'*(not i%3) + 'Buzz'*(not i%5)) if ((not i%3) or (not i%5)) else str(i) for i in xrange(1, n+1)]) |
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
""" | |
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy) | |
BSD License | |
""" | |
import numpy as np | |
# data I/O | |
data = open('input.txt', 'r').read() # should be simple plain text file | |
chars = list(set(data)) | |
data_size, vocab_size = len(data), len(chars) |