Skip to content

Instantly share code, notes, and snippets.

@tjwds
tjwds / gist:1320846a1f7a75ff11e089730eadd3f3
Created September 20, 2022 01:35
phillyjs october meeting working agenda
* What is the Philadelphia JS club? (Joe)
* Brief intros, what are you working on, what are you excited about?
* Let's talk about deno and bun
* Let's watch "10 Things I Regret About Node.js" by Ryan Dahl and talk about it https://www.youtube.com/watch?v=M3BM9TB-8yA
* Show and tell
* Social hour: move to the Disco room and hang out and chat
@tjwds
tjwds / index.js
Created May 19, 2022 17:45
Benford's Law
for (let radix = 2; radix <= 36; radix++) {
const results = {};
for (let count = 0; count < 10000; count++) {
const res = Number(String(Math.random()).slice(2)) * Number(String(Math.random()).slice(2));
const lead = res.toString(radix).slice(0, 1);
if (!results[lead]) {
results[lead] = 1;
} else {
results[lead] += 1;
}
@tjwds
tjwds / fizzbuzz.fth
Created October 12, 2019 14:56
fizzbuzz in FORTH
: FIZZBUZZ (n -- )
0 DO
I 1 + 15 MOD 0 = IF
." fizzbuzz " CR ELSE
I 1 + 5 MOD 0 = IF
." buzz " CR ELSE
I 1 + 3 MOD 0 = IF
." fizz " CR ELSE
I 1 + . CR
THEN THEN THEN LOOP ;
@tjwds
tjwds / umd-js-explained.js
Last active October 6, 2019 15:16
A poor attempt to explain the current state of dependency management in js
/* This is a template to make sure that the chart.js library is available as a global object wherever it is invoked.
* See https://devhints.io/umdjs
*/
/* Let's start by defining an IIFE with two parameters — the global context and our library. The missing docblock for
* this function would read something like "Checks the runtime environment and adds callback 'factory' (our code) to
* the application context 'global' (this). This is necessary to make sure our function is always available to be
* invoked as a new Chart(), regardless of where it's run or how it's imported."
*/
(function (global, factory) {
def doituntildone(data, letter, number, answer):
data = int(data)
if data >= number:
answer += letter
data = data - number
print('attempting recursion ' + str([data, letter, number, answer]))
# I was incorrectly assuming the following line would work:
# doituntildone(str(data), letter, number, answer)
data, answer = doituntildone(str(data), letter, number, answer)
# print([data, answer])
@tjwds
tjwds / unicodetoascii.py
Created August 30, 2015 22:40
Comprehensive Unicode -> ASCII python function
"""Alright, so it's pretty common knowledge that unicode and python just don't get along. Especially on OS X, apparently?
Separating out the sort function from the actual database that you're working with is, in my opinion, an elegant solution,
though maybe bad in big-O terms. Anyway, there are a few good options online, but if you don't want to install any libraries
(here, I need this particular function to be hyper-portable), you have to consider a lot of different circumstances.
Part of this function (the part that actually does something) comes from here:
http://stackoverflow.com/questions/2700859/how-to-replace-unicode-characters-by-ascii-characters-in-python-perl-script-giv"""
# be sure to import unicodedata