Skip to content

Instantly share code, notes, and snippets.

@Slater-Victoroff
Slater-Victoroff / credentials.py
Last active August 29, 2015 14:01
AWS Credentials
import os
CREDENTIALS = ['AWSAccessKeyId', 'AWSSecretKey']
def credentials(filename=None):
"""
Generally made for standard AWS export format. Turns conf file into python dict
If no filename is given, will attempt to read environment variables instead, then global variables
@Slater-Victoroff
Slater-Victoroff / ideal.py
Created May 21, 2014 18:55
Boto Save Ideal Decorator
@BotoSave('bucketname')
def method():
return {<key>: <data>}
@Slater-Victoroff
Slater-Victoroff / skeleton.py
Created May 21, 2014 19:08
Boto Decorator Skeleton
import json
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
from boto.s3.key import Key
class BotoSave(object):
def __init__(self, bucket, filename=None):
"""
@Slater-Victoroff
Slater-Victoroff / find_key.py
Created May 21, 2014 19:56
Automatic Key Finding
class MissingKeyException(Exception):
"""
If we can't figure out what the key is of an item being saved, we just say so.
Should probably make a better error message that says what we can figure out and what they can do about it.
"""
def __init__(self, data_structure):
self.ds = data_structure
@Slater-Victoroff
Slater-Victoroff / minify.py
Created September 4, 2014 13:08
JS/CSS minification in python
import requests
import json
import urllib
URLS = {
'css': 'http://cssminifier.com/raw',
'js': 'http://javascript-minifier.com/raw'
}
def new_filepath(filepath):
def get_voter_links(outfile="voter_info.txt"):
start_urls = ("http://usavoters.directory/complete.php?id=%s" % i for i in xrange(128555, 214545))
with open(outfile, 'a') as sink:
for url in start_urls:
document = etree.HTML(requests.get(url).content)
link_selector = CSSSelector('tr>td>a')
person_links = link_selector(document)[14:]
sink.write('\n'.join(link.get('href') for link in person_links if link.get('href')))
print url
@Slater-Victoroff
Slater-Victoroff / datums.txt
Last active September 13, 2015 18:17
Sample data
id title description google_product_category product_type price sale_price sale_price_effective_date link mobile_link image_link additional_image_link brand gtin mpn identifier_exists condition availability availability_date item_group_id color material pattern size size_type size_system gender age_group tax shipping shipping_weight shipping_label multipack is_bundle adult adwords_redirect adwords_grouping adwords_labels custom_label_0 custom_label_1 custom_label_2 custom_label_3 custom_label_4 excluded_destination expiration_date promotion_id display_ads_id display_ads_link display_ads_similar_id display_ads_title display_ads_value shipping_length shipping_width shipping_height
sku152300450 Washable-Crepe Straight-Leg Pants, Petite, Size: PS (6/8), BLACK - Eileen Fisher Eileen Fisher Washable-Crepe Straight-Leg Pants, Petite Details From Eileen Fisher, bi-stretch crepe pants with elegant day-to-night texture and remarkable fit memory, great for travel. 29" approx. inseam. Regular rise; yoked waist contours t
{"http://images.neimanmarcus.com/product_assets/T/8/A/P/X/NMT8APX_mz.jpg": [0.0, 0.0, 0.7503045797348022, 0.0, 4.050353527069092, 0.0, 0.0, 3.970454454421997, 2.56343936920166, 0.0, 0.0, 0.0, 0.0, 0.8763924241065979, 2.9059646129608154, 1.7854936122894287, 0.0, 0.0, 0.0, 3.603835105895996, 0.0, 0.0, 0.0, 0.0, 2.9097509384155273, 0.6788361072540283, 0.0, 0.0, 0.0, 0.0, 0.9168252348899841, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.21072697639465332, 0.0, 2.585055112838745, 0.0, 0.18340826034545898, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.772193431854248, 0.0, 0.0, 0.0, 0.0, 1.1300804615020752, 0.0, 0.0, 0.0, 1.8126261234283447, 0.0, 0.0, 2.4351160526275635, 1.0090645551681519, 6.7620415687561035, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6218217611312866, 0.0, 3.785642385482788, 0.0, 0.0, 0.0, 0.4094317555427551, 0.0, 1.046784520149231, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5131956338882446, 0.0, 2.341181516647339, 3.7282121181488037, 2.7647757530212402, 0.0, 0.0, 0.2037421613931656, 0.0, 0.0, 2.629900932
@Slater-Victoroff
Slater-Victoroff / twentyqs.py
Last active March 8, 2019 15:25
20 questions with word embeddings
import json
from collections import OrderedDict
import numpy as np
from scipy.spatial.distance import cdist
from indicoio.custom import vectorize
from nouns import NOUNS
FEATURES = json.load(open("features.json"), object_pairs_hook=OrderedDict)
@Slater-Victoroff
Slater-Victoroff / oneliner.py
Last active November 8, 2017 06:21
Firstletter oneliner
def firstNonRepeated(s):
return ([letter for i, letter in enumerate(s) if letter not in (s[:i] + s[i+1:])] + [""])[0]
def first_non_repeated1(s):
for i, letter in enumerate(s):
if letter not in (s[:i] + s[i+1:]):
return letter
return ""
def first_non_repeated1(s):