Skip to content

Instantly share code, notes, and snippets.

Brian Schlenker bschlenk

Block or report user

Report or block bschlenk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bschlenk
bschlenk / png2console
Created Aug 5, 2019
Generate a node.js script that prints an image to the console using chalk. Requires pillow.
View png2console
#!/usr/bin/env python3
import sys
from itertools import islice
from PIL import Image
PIXEL = '▄'
# The amount an image needs to be scaled to look good in terminal
TERM_RATIO = 0.8276
@bschlenk
bschlenk / sortBy.js
Created Jun 1, 2019
A function to easily sort JS objects by key.
View sortBy.js
/**
* Create a sorting function that can sort objects by a calculated key. Can be passed to `Array.sort`.
* @param cb A function that will be passed each object and expected to return a key to sort by.
* The key can be either a string, number, or an array of those.
* @return A function that can be passed to `Array.sort`.
*/
function sortBy(cb) {
const stringCompare = (a, b) => a.localeCompare(b);
const numberCompare = (a, b) => a - b;
@bschlenk
bschlenk / color.ts
Last active Mar 2, 2018
typeorm @BeforeInsert repro
View color.ts
import {
BaseEntity,
Entity,
JoinTable,
ManyToMany,
PrimaryColumn,
} from 'typeorm';
import Picture from './picture';
@bschlenk
bschlenk / truthgen.py
Created Jan 28, 2017
Generate all possible truth table combinations for the given number of inputs. Wrote for students in logic class.
View truthgen.py
#!/usr/bin/env python
import sys
if len(sys.argv) != 2:
print "usage: %s <number of inputs>" % sys.argv[0]
sys.exit(1)
inputs = int(sys.argv[1])
rows = 2 ** inputs
@bschlenk
bschlenk / say.js
Last active Mar 23, 2018
Call macOS's "say" program with every possible voice at the same time with the given phrase.
View say.js
#!/usr/bin/env node
/**
* Call macOS's `say` program with every possible voice at the same
* time with the given phrase. Scare your pets.
*/
const { exec } = require('child_process');
function getVoices(callback) {
@bschlenk
bschlenk / hashtree.py
Created Dec 26, 2016
Reorganize a directory into subfolders the same way git organizes its object files.
View hashtree.py
#!/usr/bin/env python3
"""
Reduce the size of a directory by creating new directories for each
unique combination of the first two letters of the existing files.
This is the same way that git stores object files.
For example, a file with this name would result in the following:
fff394e6-214d-4f74-8607-d6825f17c8fd
@bschlenk
bschlenk / hideit.user.js
Last active Mar 4, 2018
Hide any element on the page by meta+alt clicking it. Return the page to normal by shift+meta+alt clicking. https://gist.github.com/bschlenk/a9b19645d6611705b26eb93e3c0288ac/raw/hideit.user.js
View hideit.user.js
// ==UserScript==
// @name HideIt
// @namespace http://tampermonkey.net/
// @version 1.1.2
// @description Hide any element on the page, with the ability to restore all.
// @author Brian Schlenker <bschlenk@umich.edu>
// @match *://*/*
// @noframes
// ==/UserScript==
@bschlenk
bschlenk / ini2json.py
Last active Mar 3, 2017 — forked from Natim/ini2json.py
Convert an ini configuration file into a json file. Retains original order of ini file entries and prints json out with four space indentation.
View ini2json.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import sys
from collections import OrderedDict
from ConfigParser import (ConfigParser, MissingSectionHeaderError,
ParsingError, DEFAULTSECT)
You can’t perform that action at this time.