Skip to content

Instantly share code, notes, and snippets.

@dcposch
dcposch / bulbs.java
Created December 26, 2017 07:20
Lights Out algorithms challenge - breadth first, can extend to A*
public class Bulbs {
public static void main(String[] args) {
Board challenge = new Board(3);
challenge.set(1, 0, true);
System.out.println("CHALLENGE");
System.out.println(challenge);
System.out.println("SOLUTION");

😱😱

> var s = 'hello [object Object] null undefined'
> s.indexOf([])
0
> s.indexOf({})
6
> s.indexOf(null)
22
@dcposch
dcposch / README.md
Last active November 30, 2016 04:07
profiling JS array performance

profiling JS array performance

what's the fastest way to make short-lived arrays in Javascript?

i need to make this array very often. variable length, from a couple to a couple thousand. i don't know each length ahead of time. i also want to minimize memory allocations.

options

@dcposch
dcposch / mac-cp-bug.md
Created November 29, 2016 20:06
really weird macOS bug

really weird macOS bug

reasonable behavior on linux

dc@dc:/tmp$ mkdir foo
dc@dc:/tmp$ echo sup > foo/1
dc@dc:/tmp$ echo dawg > foo/2
dc@dc:/tmp$ echo yo > bar
dc@dc:/tmp$ cp -r foo/ bar
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.app {
// In *both* the main and renderer processes
// For example, in both main/index.js and renderer/index.js
var crashReporter = require('../crash-reporter')
crashReporter.init()
// Separately, create crash-reporter.js, shared by main and renderer:
module.exports = {
init
}
// In the main process, check whether the app is starting
// because the user dragged files onto the app icon
process.argv.forEach(onOpen)
// Open handlers should be added on the first tick.
// These fire if the app is already running and the user
// drags files or URLs onto the dock icon, or if they set
// the app as a handler for a file type and then open a file
app.on('open-file', onOpen)
app.on('open-url', onOpen)
const win = new electron.BrowserWindow(...)
// When work makes progress, show the progress bar
function onProgress (progess) {
// Use values 0 to 1, or -1 to hide the progress bar
win.setProgressBar(progress || -1) // Progress bar works on all platforms
}
// When work completes while the app is in the background, show a badge
var numDoneInBackground = 0
console.time('init')
// require() calls and early initialization
[...]
var state = State.getInitialState()
// `state.saved` is read from and written to a file. All other state is ephemeral.
// First we load state.saved, once that is done, initialize the app.
loadState(init)
console.time('init')
// require() calls and early initialization
[...]
var state = State.getInitialState()
// `state.saved` is read from and written to a file. All other state is ephemeral.
// First we load state.saved, once that is done, initialize the app.
loadState(init)