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
<?php | |
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/ | |
# Install requirements: | |
# composer require ifsnop/mysqldump-php | |
# composer require google/cloud-storage | |
require_once __DIR__ . '/vendor/autoload.php'; | |
require_once __DIR__ . '/config.php'; |
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
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/ | |
# Prepare with: pip install fasttext | |
# Tested with Python 3.9 | |
import urllib.request | |
import fasttext | |
# Download small model (917KB) | |
# Other options: https://fasttext.cc/docs/en/language-identification.html |
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
# Make * work in bash or zsh: | |
# zsh | |
setopt extendedglob | |
# bash | |
shopt -s extglob | |
# Resize all images (in-place) in a folder | |
# to 1200 pixels on the longest side | |
mogrify -resize 1200 *.jpg |
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
-- Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/ | |
-- Calculate the probability of k successes for n trials with probability of success k, | |
-- using the binomial distribution. | |
-- Calculate the binomial coefficient using the "multiplicative formula" | |
CREATE OR REPLACE FUNCTION functions.binomial_coef(n INT64, k INT64) AS (( | |
-- k!/(n!*(n-k)!) | |
-- We're going to have a hard time doing factorials here, | |
-- but based on the "multiplicative formula" in Wiki, it should be possible: |
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
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/ | |
# | |
# Download images from The Painting Dataset: https://www.robots.ox.ac.uk/~vgg/data/paintings/painting_dataset_2018.xlsx | |
# The image urls are outdaed in the Excel sheet but the painting urls are not, | |
# so this script re-crawls those images and downloads them locally. | |
# It works as of July 2020. | |
# | |
# Run this first with: | |
# $ scrapy runspider paintings_crawl.py -o paintings.json | |
# Images are stored in 'out/raw' |
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
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/ | |
# Run this file first, e.g.: | |
# $ scrapy runspider ft_extract.py -o members.json | |
# | |
# It will probably stop working if they change their urls for the contact list of course. | |
# Worked in Spring of 2019 | |
import scrapy | |
import re | |
from urllib.parse import urlparse, urlunparse |
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
// Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/ | |
class Tokenizer { | |
constructor(config = {}) { | |
this.filters = config.filters || /[\\.,/#!$%^&*;:{}=\-_`~()]/g; | |
this.lower = typeof config.lower === 'undefined' ? true : config.lower; | |
// Primary indexing methods. Word to index and index to word. | |
this.wordIndex = {}; | |
this.indexWord = {}; |
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
# Matplotlib | |
# Creating a list of colors (e.g. for a bar chart) | |
# "Blues" is the colormap. It can be any colormap | |
# https://matplotlib.org/examples/color/colormaps_reference.html | |
colors = [matplotlib.colors.to_hex(c) for c in plt.cm.Blues(np.linspace(0, 1, len(some_dataframe.index)))] | |
# Globally adjusting DPI and figure size | |
matplotlib.rcParams['figure.dpi'] = 100 | |
matplotlib.rcParams['figure.figsize'] = [6.0, 4.0] |
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
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/ | |
# Create a Keras embedding layer with an initial one-hot encoding by using identity initializer | |
import tensorflow as tf | |
import numpy as np | |
# Input sequence consisting of four features (e.g. words) | |
# Let's pretend this is "hello world hello everyone else" | |
# Where hello is then mapped to 1, world = 0, everyone = 2, else = 3, | |
a = np.array([[1, 0, 1, 2, 3]]) |
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
# Convert a unix timestamp in millisconds in a column of a CSV to a date | |
cat thefile.csv | perl -MPOSIX -pe 's/(^\d+),/strftime("%F,", localtime($1\/1000))/ge' |
NewerOlder