{{ message }}

Instantly share code, notes, and snippets.

🙃
Work From Quarantine - I'm doing OSS work as time and stress allow

James Socol jsocol

🙃
Work From Quarantine - I'm doing OSS work as time and stress allow
Created Aug 12, 2020
People love using Fibonacci as an example of recursion but the closed form solution is great
View fib.go
 package main import ( "fmt" "math" ) const Psi = -1.0 / math.Phi var Sqrt5 = math.Pow(5.0, 0.5)
Created Jun 22, 2020
Generate random gemstones for D&D 5e
View rand_gems.py
 """Generate random gemstones for D&D 5e It always bothered me that the tables in the DMG won't let you randomly generate a diamond worth 50gp, or 300gp, or 500gp, when these are all common spell components. This script generates random gemstones and values. It considers that you might have a small diamond worth 50gp, but probably not a giant azurite worth 5000gp. First, we get a base and a multiplier. A base could be e.g. 10, 100, 1000. A
Last active Jun 22, 2020
A Monte Carlo dice roller to investigate ability score generation methods and other probability questions
View dice.py
 import argparse import random __all__ = ['d4', 'd6', 'd8', 'd10', 'd12', 'd20', 'd100'] class D(): """A die.
Created Jul 22, 2019
#golang test subcases
View ex_test.go
 package ex import ( "fmt" "testing" ) func Multiplier(in int) int { return in * 2 }
Last active May 6, 2019
View dice.py
 import functools import operator import random class D(): """A die. Simulates an n-sided die, e.g. to create a d6, pass 6:
Last active Apr 23, 2018
finally example
View finally.js
 async function batchFunctionFinally(commands) { const batchStats = this.startBatch(commands) let error = null let response = null try { response = await this.redis.multi(commands) } catch (e) { error = e throw e } finally {
Last active May 6, 2019
View mkpw.py
 #!/usr/bin/env python from __future__ import absolute_import, print_function, unicode_literals import argparse import random import re import string sr = random.SystemRandom()
Last active Apr 14, 2017
throwing from callbacks
View async.js
 // Logs 'rejected Error: sync error' const p = new Promise((resolve, reject) => { throw new Error('sync error'); }).then(null, e => console.log('rejected', e)); // q never settles, uncaught error const q = new Promise((resolve, reject) => { setImmediate(() => { throw new Error('async error'); }); }).then(null, e => console.log('rejected', e));
View postfix.py
 from __future__ import division, print_function, unicode_literals import operator import re import sys WHITESPACE_RE = re.compile(r'\s+') NUMBER_RE = re.compile(r'-?\d+(\.\d+)?') OPERATORS = {
Last active Feb 14, 2016
View logger call site.js
 'use strict'; var format = require('util').format; function Logger() { } Logger.prototype.log = function \$\$Logger_log(msg) { var context = this.getContext(); console.log(format('%s:%s:%s(%s): %s', context.pathname, context.lno, context.col, context.func, msg));