Skip to content

Instantly share code, notes, and snippets.

View danthedaniel's full-sized avatar
👨‍💻
⠠⠵

Daniel danthedaniel

👨‍💻
⠠⠵
View GitHub Profile
@danthedaniel
danthedaniel / phoenix.d.ts
Last active March 20, 2018 18:23
Phoneix 1.3 type definitions
declare module "phoenix" {
interface Response {
status: string,
response: any,
}
interface RecHook {
status: any,
callback: (response: any) => void
@danthedaniel
danthedaniel / english_num.py
Last active March 2, 2018 01:23
Print an integer in English
"""Print a number."""
from __future__ import print_function
size_names = [
"", "thousand", "million", "billion", "trillion", "quadrillion",
"quintillion", "sexillion", "septillion", "nonillion", "decillion"
]
num_names = [
#!/bin/bash
if [ ! -z "$1" -a ! -z "$2" -a ! -z "$3" ]; then
psql -c "CREATE USER $1 WITH PASSWORD '$2'"
psql -c "CREATE DATABASE $3"
psql -c "GRANT ALL PRIVILEGES ON DATABASE $3 to $1"
else
echo "Usage: new [user] [password] [database]"
fi
@danthedaniel
danthedaniel / minesweeper.py
Last active February 11, 2018 23:58
Python CLI Minesweeper
#!/usr/bin/env python
import random
import itertools
import os
from termcolor import colored
def randbool(per=2):
"""Get a random boolean value."""
@danthedaniel
danthedaniel / repo.sh
Last active February 9, 2018 04:34
bash git repo switching
export REPO_PATH="$HOME/git"
function repo {
new_repo="$REPO_PATH/$2"
if [ "$1" == "new" -a ! -z "$2" ]; then
if [ ! -f "$new_repo" -a ! -d "$new_repo" ]; then
mkdir "$new_repo"
cd "$new_repo"
git init
else
echo "$new_repo already exists." 1>&2
@danthedaniel
danthedaniel / tms.py
Created January 10, 2018 02:19
Drexel Term Master Schedule scraper
import bs4 as bs
import sqlite3
import requests
import datetime
def db_setup(conn):
c = conn.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS classes (
subject_code TEXT,
@danthedaniel
danthedaniel / katex_auto.js
Created August 26, 2017 18:33
Tiny automatic KaTeX rendering.
// Automatically render all elements of type pre.math as latex equations.
(function() {
var math_elements = document.querySelectorAll('pre.math');
math_elements.forEach(function(e) {
e.innerHTML = katex.renderToString(e.innerText);
});
})();
@danthedaniel
danthedaniel / config.py
Last active July 10, 2017 07:39
Reversible BNF in TPOT
import numpy as np
classifier_config_dict_light = {
# Classifiers
'sklearn.naive_bayes.GaussianNB': {
},
'sklearn.naive_bayes.BernoulliNB': {
'alpha': [1e-3, 1e-2, 1e-1, 1., 10., 100.],
@danthedaniel
danthedaniel / crystal_binary_size_comparison.md
Last active August 25, 2018 23:46
Comparison of Crystal and C binary sizes

Crystal Source Code:

def factorial(n)
    n < 2 ? 1 : n * factorial(n - 1)
end

if ARGV.size > 0
    n = ARGV.first.to_u64
 puts factorial(n)
@danthedaniel
danthedaniel / bitmap_to_png.py
Last active April 3, 2017 21:04
Convert reddit /r/place bitmap to a png
import requests
from PIL import Image
bitmap_width = 1000
bitmap_height = 1000
colours = [
(0xff, 0xff, 0xff), # #FFFFFF
(0xe4, 0xe4, 0xe4), # #E4E4E4
(0x88, 0x88, 0x88), # #888888
(0x22, 0x22, 0x22), # #222222