Skip to content

Instantly share code, notes, and snippets.

View dtudury's full-sized avatar

David Tudury dtudury

  • Oakland, California, USA
View GitHub Profile
@dtudury
dtudury / q-idea.js
Created April 21, 2021 18:00
idea for an sql-like utility for javascript arrays and objects
const a = [
{ m: "a", id: 1 },
{ m: "b", id: 2 },
{ m: "c", id: 3 }
];
const b = [
{ n: "x", id: 1 },
{ n: "y", id: 2 },
{ n: "z", id: 3 }
];
@dtudury
dtudury / lispish.js
Last active November 2, 2020 20:53
basic lisp parser
// A *just* good-enough lisp parser
const WHITE_SPACE = /\s/
const OPEN_PAREN = /\(/
const CLOSE_PAREN = /\)/
const SUBATOMIC = /[^\s()]/
function parse (program) {
let i = 0
@dtudury
dtudury / queens.js
Created July 3, 2019 00:47
solution to eight queens puzzle
function place (placed, unplaced) {
if (!unplaced.length) return [placed]
let validPlacements = []
unplaced.forEach(unplacedRow => {
if (placed.every((placedRow, i) => {
const d = placed.length - i
return placedRow + d !== unplacedRow && placedRow - d !== unplacedRow
})) {
let possibleUnplaced = unplaced.filter(row => row !== unplacedRow)
validPlacements = [...validPlacements, ...place([...placed, unplacedRow], possibleUnplaced)]
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@dtudury
dtudury / hues.lum.js
Created October 17, 2016 21:40
map color hues to same luminance
let lum = ([r, g, b]) => r * 0.2126 + g * 0.7152 + b * 0.0722;
let blend = (c0, c1, s, i = 1 - s) => [c0[0] * s + c1[0] * i, c0[1] * s + c1[1] * i, c0[2] * s + c1[2] * i];
let hex = c => c.reduce((p, v) => p + Math.round(0x100 + v * 0xff).toString(16).substr(-2), "");
let colors = {
red: [1, 0, 0],
yellow: [1, 1, 0],
green: [0, 1, 0],
cyan: [0, 1, 1],
blue: [0, 0, 1],
@dtudury
dtudury / emscripten_transcripten.md
Created May 5, 2016 21:44
emscripten notes and direction from Julian for Cosmin

get the repo and tools

I've run this so it should be mostly (hopefully) okay

  • setup emscripten (I think you already have)
  • install sox; if you use homebrew: brew install sox
  • get Julian's WIP: git clone git@github.com:Voxer/voxer2mp3.git and git checkout jg-emscripten
  • do the magic:
    • ./buildvoxencode.sh
  • jgautier: "so you have a VoxEncode.js file now?"
@dtudury
dtudury / keybase.md
Created August 4, 2014 17:26
keybase.md

Keybase proof

I hereby claim:

  • I am dtudury on github.
  • I am dtudury (https://keybase.io/dtudury) on keybase.
  • I have a public key whose fingerprint is BF35 8F92 0C77 AD10 5A80 62D7 577E AC54 B305 E554

To claim this, I am signing this object:

#!/usr/bin/osascript
-- run as something like `./run_in_panes.scpt "echo a" "echo b"`
on run argv
set numCmds to count of argv
set numCols to round numCmds ^ 0.5 rounding up
set numRows to round numCmds / numCols rounding up
launch "iTerm"

##Liquid Sugar: combine

  • 4 cups white sugar
  • 1 1/2 cups water
  • 1/4 teaspoon cream of tartar

in a covered pot over low heat for at least 30 minutes; makes 4 cups

because 4 cups contains 4 cups of sugar it's a very good substitute for granulated sugar. Boiling it with the cream or tartar inverts some of the sucrose creating a sweeter combination of sugars less prone to crystallization. The higher sugar content also increases the shelf-life.

@dtudury
dtudury / page2.js
Last active August 29, 2015 13:57
/*
javascript:(function () {
var jsCode = document.createElement('script');
jsCode.setAttribute('src', 'https://rawgit.com/dtudury/9501738/raw/f383c0de610467b8b81d38b263772bb663b04ceb/page2.js');
document.body.appendChild(jsCode);
}());
*/
var numbers = "0123456789";
function randomNumber() {
return numbers.charAt(Math.floor(Math.random() * numbers.length));