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
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 (、。’) |
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
#!/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 |
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
[ | |
{ | |
"state":"Alaska", | |
"latitude":61.3850, | |
"longitude":-152.2683 | |
}, | |
{ | |
"state":"Alabama", | |
"latitude":32.7990, | |
"longitude":-86.8073 |
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
""" 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'), |
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
{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', |
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
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'; |
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
// 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() |
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
#%% (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. |
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
// 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--) { |
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 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): |
OlderNewer