Skip to content

Instantly share code, notes, and snippets.

View ramcandrews's full-sized avatar
🏠
Working from home

Ryan McAndrews ramcandrews

🏠
Working from home
View GitHub Profile
@terrancesnyder
terrancesnyder / regex-japanese.txt
Created November 7, 2011 14:05
Regex for Japanese
Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!
([一-龯])
Regex for matching Hirgana or Katakana
([ぁ-んァ-ン])
Regex for matching Non-Hirgana or Non-Katakana
([^ぁ-んァ-ン])
Regex for matching Hirgana or Katakana or basic punctuation (、。’)
@minrk
minrk / nbstripout
Last active June 6, 2023 06:23
git pre-commit hook for stripping output from IPython notebooks
#!/usr/bin/env python
"""strip outputs from an IPython Notebook
Opens a notebook, strips its output, and writes the outputless version to the original file.
Useful mainly as a git filter or pre-commit hook for users who don't want to track output in VCS.
This does mostly the same thing as the `Clear All Output` command in the notebook UI.
LICENSE: Public Domain
@meiqimichelle
meiqimichelle / USstates_avg_latLong
Created December 1, 2013 02:08
JSON of US states (full names) and their average lat/long
[
{
"state":"Alaska",
"latitude":61.3850,
"longitude":-152.2683
},
{
"state":"Alabama",
"latitude":32.7990,
"longitude":-86.8073
@doobeh
doobeh / bulk_updates_sqlalchemy.py
Created September 8, 2015 18:24
SQLAlchemy bulk updates.
""" Quick example showing how to do a bulk update into the database
using SQLAlchemy, without interacting heavily with the ORM.
"""
from sqlalchemy.sql.expression import bindparam
stmt = addresses.update().\
where(addresses.c.id == bindparam('_id')).\
values({
'user_id': bindparam('user_id'),
'email_address': bindparam('email_address'),
@yrevar
yrevar / imagenet1000_clsidx_to_labels.txt
Last active November 8, 2024 06:50
text: imagenet 1000 class idx to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
@webbower
webbower / generate-text-image.js
Last active October 2, 2021 06:30
Generate an image from text using the Canvas API
function generateImageFromText(text, width, height) {
// TODO Add auto-wrapping logic when text is too wide
// TODO Add tiered text scaling (if height > 200: font-size = 36; else if height > 100: font-size = 18; etc)
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
const fontSize = Math.min(height, 36);
ctx.fillStyle = '#212121';
@ericls
ericls / async-await-fetch-map.js
Created July 19, 2017 04:03
async/await with fetch and map
// Use hacker news API as example
async function getData() {
const ids = await (await fetch('https://hacker-news.firebaseio.com/v0/topstories.json')).json()
const data = Promise.all(
ids.map(async (i) => await (await fetch(`https://hacker-news.firebaseio.com/v0/item/${i}.json?print=pretty`)).json())
)
return data
}
getData()
@kmjjacobs
kmjjacobs / gru_tensorflow.py
Last active August 14, 2022 17:10
GRU (Gated Recurrent Unit) implementation in TensorFlow and used in a simple Machine Learning task. The corresponding tutorial is found on Data Blogger: https://www.data-blogger.com/2017/08/27/gru-implementation-tensorflow/.
#%% (0) Important libraries
import tensorflow as tf
import numpy as np
from numpy import random
import matplotlib.pyplot as plt
from IPython import display
% matplotlib inline
#%% (1) Dataset creation.
@webbower
webbower / shuffle-durstenfeld.js
Created December 2, 2017 22:02
Durstenfeld shuffle
// http://en.wikipedia.org/wiki/Fisher-Yates_shuffle#The_modern_algorithm
// https://stackoverflow.com/a/12646864/2684520
// Pre-ES6
/**
* Randomize array element order in-place.
* Using Durstenfeld shuffle algorithm.
*/
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
@andrewjong
andrewjong / pytorch_image_folder_with_file_paths.py
Last active October 31, 2024 11:13
PyTorch Image File Paths With Dataset Dataloader
import torch
from torchvision import datasets
class ImageFolderWithPaths(datasets.ImageFolder):
"""Custom dataset that includes image file paths. Extends
torchvision.datasets.ImageFolder
"""
# override the __getitem__ method. this is the method that dataloader calls
def __getitem__(self, index):