Skip to content

Instantly share code, notes, and snippets.

Avatar

Kyle McDonald kylemcdonald

View GitHub Profile
@kylemcdonald
kylemcdonald / Adversarial Variational Bayes toy example.ipynb
Last active Jul 23, 2021
Adversarial Variational Bayes toy example in PyTorch
View Adversarial Variational Bayes toy example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / Collect Parler Metadata.ipynb
Last active Jul 16, 2021
Collect video URLs and GPS data for Parler videos.
View Collect Parler Metadata.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / post-server.py
Created Sep 21, 2014
Python POST simple server
View post-server.py
import SimpleHTTPServer
import SocketServer
PORT = 8000
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_POST(self):
content_len = int(self.headers.getheader('content-length', 0))
post_body = self.rfile.read(content_len)
@kylemcdonald
kylemcdonald / ACAI (PyTorch).ipynb
Last active Jul 12, 2021
PyTorch ACAI (1807.07543).
View ACAI (PyTorch).ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / showarray.py
Created Jan 3, 2016
Minimal code for rendering a numpy array as an image in a Jupyter notebook in memory. Borrowed from the Deep Dream notebook.
View showarray.py
import PIL.Image
from cStringIO import StringIO
import IPython.display
import numpy as np
def showarray(a, fmt='png'):
a = np.uint8(a)
f = StringIO()
PIL.Image.fromarray(a).save(f, fmt)
IPython.display.display(IPython.display.Image(data=f.getvalue()))
@kylemcdonald
kylemcdonald / long_run_gray_codes.frag
Last active Jul 5, 2021
Long Run Gray Codes for 2-bits through 13-bits.
View long_run_gray_codes.frag
// Generated using code from https://stackoverflow.com/a/66555635/940196
// More info on LRGC http://emis.impa.br/EMIS/journals/EJC/Volume_10/PDF/v10i1r27.pdf
const int lrgc_2[4] = int[](0,1,3,2);
const int lrgc_3[8] = int[](0,1,3,2,6,7,5,4);
const int lrgc_4[16] = int[](0,1,3,7,15,11,9,8,12,13,5,4,6,14,10,2);
const int lrgc_5[32] = int[](0,1,3,7,15,31,29,25,17,16,18,2,10,14,12,28,20,21,23,19,27,11,9,13,5,4,6,22,30,26,24,8);
const int lrgc_6[64] = int[](0,1,3,7,15,31,63,62,58,42,40,32,36,37,5,21,17,25,27,11,10,14,46,38,54,50,48,49,33,41,9,13,29,28,30,26,18,2,34,35,39,55,53,61,57,56,24,8,12,4,6,22,23,19,51,59,43,47,45,44,60,52,20,16);
const int lrgc_7[128] = int[](0,32,33,35,39,103,111,127,125,93,89,81,80,16,18,2,10,42,46,44,60,124,116,117,119,87,83,91,75,11,9,13,5,37,36,38,54,118,126,122,120,88,72,64,65,1,3,7,15,47,63,61,57,121,113,112,114,82,66,74,78,14,12,28,20,52,53,55,51,115,123,107,105,73,77,69,68,4,6,22,30,62,58,56,40,104,96,97,99,67,71,79,95,31,29,25,17,49,48,50,34,98,106,110,108,76,92,84,85,21,23,19,2
@kylemcdonald
kylemcdonald / download-urls.py
Last active Jun 24, 2021
Download a range of URLs in parallel.
View download-urls.py
from multiprocessing.dummy import Pool
from tqdm import tqdm
from urllib.parse import urlsplit
import urllib3
import itertools, functools, operator
import os
import sys
import re
import errno
import argparse
@kylemcdonald
kylemcdonald / ffmpeg_load_audio.py
Last active Jun 23, 2021
Load audio from ffmpeg into Python using numpy.
View ffmpeg_load_audio.py
import numpy as np
import subprocess as sp
import os
DEVNULL = open(os.devnull, 'w')
# load_audio can not detect the input type
def ffmpeg_load_audio(filename, sr=44100, mono=False, normalize=True, in_type=np.int16, out_type=np.float32):
channels = 1 if mono else 2
format_strings = {
np.float64: 'f64le',
@kylemcdonald
kylemcdonald / index.html
Last active Jun 10, 2021
Google Cloud Vision API testing from Frontend
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>vision-test</title>
<script src="libraries/p5.js" type="text/javascript"></script>
<script src="libraries/p5.dom.js" type="text/javascript"></script>
<script src="libraries/p5.sound.js" type="text/javascript"></script>
@kylemcdonald
kylemcdonald / wikifil.pl
Last active Jun 9, 2021
Fork of Matt Mahoney's Wikipedia cleaning script.
View wikifil.pl
#!/usr/bin/perl
# Program to filter Wikipedia XML dumps to "clean" text consisting only of lowercase
# letters (a-z, converted from A-Z), and spaces (never consecutive).
# All other characters are converted to spaces. Only text which normally appears
# in the web browser is displayed. Tables are removed. Image captions are
# preserved. Links are converted to normal text. Digits are spelled out.
# Written by Matt Mahoney, June 10, 2006. This program is released to the public domain.