Skip to content

Instantly share code, notes, and snippets.

@dwaltrip
dwaltrip / merged-streams.js
Last active August 29, 2015 13:57
Code snippet that can take a set of ordered integer streams and return a merged, ordered stream
// helper functions
// includes end points as possible return values
var randint = function(min, max) {
return (Math.floor(Math.random() * (max - min + 1)) + min);
}
// I was surprised to find out this is necessary to get a numerical sort
function sort_number(a,b) {
if (a < b)

Movie Maven

On the web server

  • Node.js app that is the web app (front-end, API, database, etc)
  • Python script that takes a list of filename text strings and processes it into a list of standardized movie names
  • Ruby script that uses the cleaned up movie names to fetch associated data from Rotten Tomato, Imdb, etc

On the user's computer

/****
Problem:
You are making some edits, and in one of the computed properties you make
the correct change to the function body, but forget to update the dependent keys.
You test the change (the basic case only), and it works great. However, the function now
has a bug that will need to be caught by QA or it will slip through to production.
Solution:
@dwaltrip
dwaltrip / memory-leak-mithril-v.1.1.1.html
Last active April 27, 2017 23:53
Testing for memory leaks in `m.mount` (in mithril.js v1.1.1)
<html lang="en">
<head>
<meta charset="utf-8">
<title>Memory Leak test</title>
<script src="mithril-v1.1.1.js"></script>
<style>
body { padding: 15px; margin: 0; }
#widget-container {
width: 340; height: 340; display: flex; flex-wrap: wrap; margin-top: 10px;
}
@dwaltrip
dwaltrip / memory-leak-mithril-v.0.2.5.html
Created April 27, 2017 23:54
m.mount causing memory leaks in mithril v0.2.5
<html lang="en">
<head>
<meta charset="utf-8">
<title>Memory Leak test</title>
<script src="mithril-v0.2.5.js"></script>
<style>
body { padding: 15px; margin: 0; }
#widget-container {
width: 340; height: 340; display: flex; flex-wrap: wrap; margin-top: 10px;
}
@dwaltrip
dwaltrip / differences-in-key-behavior.html
Last active May 2, 2017 00:25
Differences in `key` behavior between mithril v0.2.5 and mithril v1
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mixing keyed and non-keyed Vnodes</title>
<!-- <script src="https://unpkg.com/[email protected]/mithril.js"></script> -->
<script src="https://unpkg.com/[email protected]/mithril.js"></script>
<style>
body { margin: 10px; }
@dwaltrip
dwaltrip / wrapped-react-beautiful-dnd.js
Last active April 24, 2020 02:05
Wrapping react-beautiful-dnd components so that we can pass `onDragEnd` directly to each `Droppable`
import {
DragDropContext as RealDragDropContext,
Droppable as RealDroppable,
Draggable
} from 'react-beautiful-dnd';
import React, { Component } from 'react';
const DroppableManager = {
_onDragEndLookup: {},
@dwaltrip
dwaltrip / tail_file.py
Last active August 24, 2018 22:06
"tail -f" in python
import sys
import time
import subprocess
import select
# Modified from: https://stackoverflow.com/a/12523371/111635
def tail_file(filename, process_line):
assert callable(process_line), '`process_line` should be a callable'
@dwaltrip
dwaltrip / gpt-4-math-problem.md
Last active March 14, 2023 22:05
GPT-4 correctly calculating more difficult math problems

Me: What is 124 * 983? Perform the calculation by breaking it into easier sub-problems, such as (100 * 983) and (20 * 983). Proceed logically and carefully do each step.

GPT-4: Sure, let's break down the multiplication into smaller parts.

124 * 983 can be separated into (100 * 983) + (20 * 983) + (4 * 983)

Let's find the product of 100 * 983:

100 * 983 = 98,300