Skip to content

Instantly share code, notes, and snippets.

View twfarland's full-sized avatar

Tim Farland twfarland

  • Farland Digital
  • Auckland, NZ
View GitHub Profile
@twfarland
twfarland / crossword-cheat.js
Created December 23, 2017 18:43
Crossword / Take 5 cheat
const readline = require('readline')
const fs = require('fs')
const lineReader = readline.createInterface({
input: fs.createReadStream('/usr/share/dict/words', { encoding: 'utf8' })
})
const word = process.argv[2]
if (!word) {
@media (min-width:768px) {
.r {
clear: left;
}
.r:before, .r:after {
content: "";
display: table;
}
.r:after {
clear: both;
@twfarland
twfarland / snake.html
Last active August 25, 2016 17:45
snake game
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Snake</title>
</head>
<style>
.board {
width: 300px;
height: 300px;
@twfarland
twfarland / vdom-stream.js
Last active March 24, 2016 18:35
redux style reducer with vdom, baconjs and immutablejs
import Immutable from 'immutable'
import Bacon from 'baconjs'
import h from 'virtual-dom/h'
import diff from 'virtual-dom/diff'
import patch from 'virtual-dom/patch'
import createElement from 'virtual-dom/create-element'
const INCREMENT = 'INCREMENT'
const DECREMENT = 'DECREMENT'
@twfarland
twfarland / element-plain.js
Created October 9, 2015 02:13
generate html strings from js with same syntax as https://gist.github.com/twfarland/fdcbd933bd876af79b33
const voidElements = { area:1, base:1, br:1, col:1, command:1, embed:1, hr:1, img:1, input:1, keygen:1, link:1, meta:1, param:1, source:1, track:1, wbr:1 };
function exists (n) {
if (n instanceof Array || typeof n === 'string') return n.length > 0;
return !!(n === 0 || n);
}
@twfarland
twfarland / element.js
Created September 25, 2015 04:07
React shorthand element creation
import React from 'react'
// E(String, { attr: val }, ... ReactElement || Atom) -> ReactElement
// Allows use of css selector shorthand and concise element creation
function E (head, attrs, ... child) {
if (typeof head === 'function') return React.createElement(head, attrs, ... child)
var i, p, c
var u = require('util');
var strings = ["1234", "hello", "hell", "1el", "1235"];
var trie = {};
function insert (trie, str) {
var i, ref = trie;
@twfarland
twfarland / syntax-style-ideas.scm
Last active August 29, 2015 14:04
Syntax style ideas for a statically-typed lisp
;; A translation of the example on http://nightmare.com/rushing/irken/irken/lang.html
;; Type definition follows Haskell's approach
(data (tree a)
empty
(node a (tree a) (tree a)))
@twfarland
twfarland / pals.c
Created May 7, 2014 23:23
Learning c. Find the longest palindrome in a text file, ignoring case and multiple spaces.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Usage: ./pals war_and_peace.txt
char *readFile(char *filename) {
FILE *infile;
char *buffer;
@twfarland
twfarland / fit-patterns.rkt
Created March 27, 2014 22:40
Generating patterns with genetic algorithms
#lang racket
(require 2htdp/image)
(require "../connive/connive.rkt")
(:= rate 5) ; amount to mutate each property per generation
(:= gen-size 30) ; generation size
(:= acceptable-dist 20) ; how close the best of a generation is to ideal to stop evolving
(struct state (a o h r g b) #:transparent)