Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dmsnell's full-sized avatar

Dennis Snell dmsnell

View GitHub Profile
@dmsnell
dmsnell / analyticsMiddleware.js
Last active April 12, 2016 16:19
Taking out the test-busters
import {
newTracksEvent
} from 'analytics/actions'
export const Doohickey = ( { recordClick, hotness } ) =>
<div onClick={ recordClick( 'dingos', { hotness } ) }>Dingos!</div>
const mapDispatchToProps = dispatch => ( {
recordClick: compose( dispatch, newTracksEvent )
} )
@dmsnell
dmsnell / docker-compose.yml
Last active October 5, 2016 23:22
WordPress docker compose configuration for local Jetpack dev
version: '2'
services:
wordpress:
image: wordpress
ports:
- 80:80
environment:
WORDPRESS_DB_PASSWORD: example
volumes:
@dmsnell
dmsnell / generate.js
Created November 5, 2016 20:17
Generate a star composite
const childProcess = require( 'child_process' )
const fs = require( 'fs' )
const spawn = childProcess.spawn
const spawnSync = childProcess.spawnSync
const l = m => { console.log( m ); return m }
const needsDir = dir => ! fs.existsSync( dir ) && fs.mkdirSync( dir )
@dmsnell
dmsnell / fractal.bas
Created November 11, 2016 20:42
Drawing a fractal in BASIC
SCREEN 12
CLS
RANDOMIZE TIMER
maxx = 640
maxy = 480
x1% = INT(RND * maxx) + 1
y1% = INT(RND * maxy) + 1
TYPE VERTEX
XC AS DOUBLE
version: '2'
services:
wordpress:
image: wordpress
ports:
- 80:80
environment:
WORDPRESS_DB_PASSWORD: example
@dmsnell
dmsnell / gridReducer.js
Created January 5, 2017 18:59
Building independent reducers of inter-related data
const height = ( state = 8, { type, height } ) =>
'SET_HEIGHT' === type || 'RESET_BOARD' === type
? height
: state;
const width = ( state = 8, { type, width } ) =>
'SET_WIDTH' === type || 'RESET_BOARD' === type
? width
: state;
@dmsnell
dmsnell / calypsoComments.purs
Last active May 26, 2017 19:07
Building a description of the Comment object in Calypso
module Main where
import Prelude
import Data.Foldable (fold)
import Data.Generic
import Data.Maybe
import TryPureScript
data CommentId = CommentId Int
type DateTime = String {- this interactive editor doesn't have the right type -}
@dmsnell
dmsnell / bf.peg
Last active June 14, 2017 15:26
An interpreter for BF in PEGjs
// Brain-Fried Language
// Load document from this GIST for a secret message
// https://gist.githubusercontent.com/dmsnell/b5e9465e97d352556249500c80ae6cbd/raw/bf547f71291e44c890ce9fe80c3c3b5217aae715/rot13.bf
{
const stdin = 'Jbeq Pnzc'.split('').map( c => c.charCodeAt( 0 ) ).concat( 0 );
const incDP = m => Object.assign( {}, m, { dp: m.dp + 1, maxRegister: Math.max( m.maxRegister, m.dp + 1 ) } )
@dmsnell
dmsnell / rot13.bf
Last active June 14, 2017 15:25
ROT13 in BF from Wikipedia
-,+[ Read first character and start outer character reading loop
-[ Skip forward if character is 0
>>++++[>++++++++<-] Set up divisor (32) for division loop
(MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero)
<+<-[ Set up dividend (x minus 1) and enter division loop
>+>+>-[>>>] Increase copy and remainder / reduce divisor / Normal case: skip forward
<[[>+<-]>>+>] Special case: move remainder back to divisor and increase quotient
<<<<<- Decrement dividend
] End division loop
]>>>[-]+ End skip loop; zero former divisor and reuse space for a flag
@dmsnell
dmsnell / benchmark-gutenberg-php-parser.php
Last active October 29, 2017 14:37
Run the parser from Gutenberg over test documents to measure its speed
<?php
/**
* Set the $RUNS and run `php -f benchmark-gutenberg-php-parser.php`
*/
// I ran this file from the `Gutenberg/lib` directory
require_once( 'parser.php' );
$RUNS = 2000;