Skip to content

Instantly share code, notes, and snippets.

View orsonadams's full-sized avatar
💭
💞

Orson Adams orsonadams

💭
💞
View GitHub Profile
@orsonadams
orsonadams / basic_lru_cache.py
Last active March 13, 2020 23:05
Not so correct implementation of LRU Cache
# @parsethis
# Basic LRU Cache implementation using a dictionary and a queue
# Goes without saying that you'd not use this, functools.lru_cache is what you want
# TODO, is not threadsafe, not nearly use locking (see functools.lru_cache )
# hashing keys could be flattened, properly hashed
# maybe you want a doubly linked list and not a python queue
#
#
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN
# h/t @makmanalp for the updated syntax!
@orsonadams
orsonadams / lstm_classification_example.py
Last active April 2, 2018 22:00
A quick demo of lstms used for classification with dummy data all in keras
import numpy as np
from keras.preprocessing.sequence import pad_sequences
from keras.utils import to_categorical
from keras.models import Sequential
from keras.layers import Embedding, Dense, LSTM
def main():
@orsonadams
orsonadams / newsites.sql
Last active March 30, 2018 20:31
Query news sites submission to hacker news
SELECT
title, timestamp, score, url
FROM
[bigquery-public-data.hacker_news.full]
WHERE
(REGEXP_MATCH(url,r'nytimes.com|cnn.com|hufftingtonpost.com|usatoday.com|reuters.com|politico.com|yahoo.com
|npr.org|latimes.com|nbcnews.com|cbsnews.com|nypost.com|abcnews.com|breitbart.com|theonion.com
|newsmax.com|washingtontimes.com|newsweek.com|observer.com|chicago.suntimes.com|theguardian.com
|buzzfeed.com|wjs.com|abcnews.go.com|news.bbc.co.uk|usatoday.com|bloomberg.com|news.google.com'))
AND deleted IS null AND type='story'
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@orsonadams
orsonadams / large_svg.svg
Created May 1, 2017 22:05
Example Large svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from keras.engine.topology import Layer
from keras import initializations
from keras import backend as K
class Attention(Layer):
'''Attention operation for temporal data.
# Input shape
3D tensor with shape: `(samples, steps, features)`.
# Output shape
2D tensor with shape: `(samples, features)`.
@orsonadams
orsonadams / acs_tableid2name.py
Last active June 20, 2016 18:39
Simple script I used to get make a map from ACS survey data variable names to their descriptive table names.
#!bin/env/python
# Simple script I used to get make a map from ACS
# survey data variable names to the descriptive table names.
# It made my life a bit easier when searching for table names
# programmatically
# here is the ACS varibles site:
# http://api.census.gov/data/2014/acs5/variables.html
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.