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
from sklearn.cross_validation import train_test_split | |
from keras.preprocessing import sequence, text | |
from keras.models import Sequential | |
from keras.layers import (Dense, Dropout, Activation, Embedding, LSTM, | |
Convolution1D, MaxPooling1D) | |
# Embedding | |
max_features = 20000 | |
maxlen = 100 | |
embedding_size = 32 |
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 math | |
""" | |
Get the largest factor a number that's less than a threshold. Useful for finding the | |
best number for breaking a list up into groups of equal size. | |
""" | |
def largest_factor(num, cur=1, factor=1, max_size=10): | |
factor = math.ceil(float(num) / cur) | |
if factor > max_size: | |
return best_factor(arr, cur + 1, int(factor), max_size) |
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
<!doctype html> | |
<html> | |
<head></head> | |
<body> | |
<!-- | |
Obviously this is not production code. Really I was just rendering a map so I could take a screenshot and post it on Twitter, | |
and this was faster than using some Python mapping library (and looks way nicer!). So no judgement, mkay? | |
This plots points taken from my Google Location data, formatted using this handy Python script: |
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 os | |
import json | |
import datetime | |
""" | |
I wanted to map where I'd been in the past year using DataMaps, a jQuery + D3 | |
library for visualizing geospatial data. https://github.com/markmarkoh/datamaps | |
First I downloaded my data from Google https://www.google.com/settings/takeout | |
(I let them track my Android phone), and then used the script below to | |
format the JSON the way DataMaps expects. |
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 json | |
from collections import Iterable | |
from bson import ObjectId | |
from datetime import datetime | |
class MongoengineEncoder(json.JSONEncoder): | |
""" | |
The default JSON encoder that ships with Mongoengine (the to_json method | |
exposed on Document instances) makes some odd choices. Datetime objects | |
are nested on a $date property, ObjectIds are nested on an $oid property, |
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
var takeMeTo = function(destination) { | |
var refrain = 'Won\'t you take me to ' + destination; | |
return function() { | |
alert(refrain); | |
} | |
} | |
// Nothing happens yet, you're just assigning the anonymous function returned | |
// by takeMeTo to funkyTown | |
var funkyTown = takeMeTo('Funky Town'); |
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
include('simple_html_dom.php'); // DOM parsing library. | |
$url = (isset($_GET['site'])) ? $_GET['site'] : 'http://www.yelp.com'; //just an example, clean this | |
$dom = file_get_html($url); | |
foreach ($dom->find('a') as $node) { | |
// Replace href attribute value | |
$node->href = 'http://YOURPROXYSERVER.COM?requestedurl='.urlencode($url.$node->href); | |
} | |
// Output modified DOM | |
echo $dom->outertext; |