Skip to content

Instantly share code, notes, and snippets.

View lelandbatey's full-sized avatar

Leland Batey lelandbatey

View GitHub Profile
@lelandbatey
lelandbatey / emscripten_problem.md
Last active August 29, 2015 14:18
Emscripten problem

Problem

When compiling this[0] C++ file with Emscripten, the compiled javascript file produces incorrect output when run with node (using node v0.12.0 on all platforms). This is not "serious" code, it is a toy minified raytracer, as found here[1]. I have tried to find any information on the Emscripten website regarding less-than-compatible behavior this source file might be doing which makes it run incorrectly, but I have had no luck.

In attempting to narrow the problem, I also constructed a small program which seems to break in a similar way, which can be found here[6].

I come here hoping that it is simply an oversight by me in how this code is written or how I'm compiling it.

Steps to reproduce:

@lelandbatey
lelandbatey / remove_lf.ps1
Last active August 29, 2015 14:25
Remove errant line-feed characters in Windows csv
# To run this file, change the value below where it says ".\sample.csv" to the
# path to the CSV file you want to change. Then, to have this script write to
# a new csv file, pipe it into the Out-File cmdlet. For example, you might run
# this file (AFTER MODIFYING THE PATH TO THE INPUT FILE DOWN BELOW) with an
# invocation like this:
#
# .\remove_lf.ps1 | Out-File .\fixed_version.csv -encoding ASCII
#
# Note the option `-encoding ASCII` above. Leaving this option off might not
# cause any problems, but it may also break the output in some way. See what
@lelandbatey
lelandbatey / prime-sieve.cpp
Last active February 7, 2017 19:59
Sieve of Eratosthenes in C++ based on Python implementation written by David Eppstein.
#include <iostream>
#include <map>
#include <cmath>
#include <vector>
// Sieve of Eratosthenes
//
// This is a simple implementation of the Sieve of Eratosthenes, implemented in
// C++. This is a port of the excellent and very terse implementation by David
// Eppstein[0]. This port is meant to be a straightforward naive port of the
@lelandbatey
lelandbatey / jpg_recompresser.py
Last active August 31, 2015 00:28
Recompresses a jpeg many times over to destroy quality
#! /usr/bin/env python
from __future__ import print_function
import random
import sys
import os
# This code reads like a basketball (it doesn't). In my defense, I wrote this a
# long time ago, and I wrote it in one hazy evening out of rage just to spite
# people who re-compress jpegs so aggressively. I publish this only because
# there's some stuff I need to not forget (e.g. how to add grain to an image
@lelandbatey
lelandbatey / persistant_checklist.html
Last active October 30, 2016 23:27
Turn html lists into checklists; great for markdown
<script>
var checkboxes = [];
function getCheckboxStates() { return checkboxes.map(bx => !!bx.checked); };
function saveCheckboxStates() {
localStorage['boxStates'] = JSON.stringify(getCheckboxStates());
}
// Add a checkbox in front of every list item, save reference to each
[].slice.call(document.getElementsByTagName('li')).forEach((li, index) => {
var chkbx = document.createElement('input');
@lelandbatey
lelandbatey / tac.py
Created March 25, 2016 02:39
Tic tac toe bot beginnings
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
class player:
X = 'X'
O = 'O'
class Board(object):
@lelandbatey
lelandbatey / index.html
Last active January 9, 2017 02:21
Draw a fractal tree using javascript on an HTML5 canvas.
<!DOCTYPE html>
<html lang="en">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<body style="margin: 0;">
<canvas id='canvas' width='4000' height='2000'></canvas>
</body>
<script>
// To run, download this file and serve it via some http server; I prefer
@lelandbatey
lelandbatey / distribution.js
Last active December 18, 2016 03:41
Poisson disk, implemented from the paper!
// I implemented poisson disk selection from this paper: http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf
// This was very fun, I highly recommend it to anybody!
function create_draw(ctx) {
return {
line: (start, end) => {
let [sx, sy] = start;
let [ex, ey] = end;
ctx.beginPath();
@lelandbatey
lelandbatey / probabilities.py
Last active December 31, 2022 01:29
Proto-minesweeper probability -- a kludged together POC for statistics of mines in squares
'''
A toy example to calculate the probability of a mine existing on any particular square.
Runs slowly and is organized like spaghetti, but it does currently work!
Note that for this to work, it depends on a slightly modified defusedivision;
inside defuse_division the _create_foothold function in game.py has to be
modified to be public, instead of private like in the public version.
@lelandbatey
lelandbatey / stir-fry-peppers-and-onions.md
Created November 4, 2018 01:55
A recipe for stir fry peppers and onions. Taken from the New York Times, but now more accessible and not behind a paywall.