Skip to content

Instantly share code, notes, and snippets.

View flintinatux's full-sized avatar

Scott McCormack flintinatux

View GitHub Profile
require 'spintax_parser'
class String
include SpintaxParser
end
spintext = "{Hello|Hi} {{world|worlds}|planet}{!|.|?}"
10.times do
puts spintext.unspin
end
@flintinatux
flintinatux / composite_view.coffee
Created October 29, 2014 17:26
Backbone view layer
class CompositeView extends Backbone.View
initialize: (options) ->
super(options)
@children = _([])
renderChild: (child) ->
@children.push child
child.parent = this
child.render()
module.exports = class SwappingRouter extends Backbone.Router
execute: (callback, args) ->
@params = @_parseParams args.pop()
callback?.apply this, args
navigate: (fragment, options={}) ->
url = new URI fragment.replace('#','')
url.query options.params if options.params?
super "##{url.toString()}", _.omit(options, 'params')
@flintinatux
flintinatux / component.js
Created July 23, 2016 18:12
Component wrapper for mithril 1.x. Registers lifecycle methods as streams, so that components may be contructed as single-closure factories that return view functions.
const m = require('mithril')
const stated = hook => vnode => vnode.state[hook](vnode)
const oninit = Comp => vnode => {
vnode.state.oncreate = m.prop()
vnode.state.onremove = m.prop()
vnode.state.view = Comp(vnode)
}
const identity = require('ramda/src/identity')
const qs = require('qs')
const Task = require('./task')
const parseHeaders = identity
const request = opts => Task((reject, resolve) => {
var {
data,
@flintinatux
flintinatux / Layout.jsx
Created May 31, 2018 14:13
One way to simplify routing in React
const Layout = Child => props =>
<div>
<header></header>
<main>
<Child />
</main>
</div>
export default Layout
@flintinatux
flintinatux / linked-lists-play.js
Created July 3, 2018 03:24
Messing around with ordering items in a db using linked lists
init = {
all: {},
head: null,
last: null
}
list = {
all: {
1: {
id: '1',
@flintinatux
flintinatux / compose.js
Created April 19, 2019 04:06
Tiny function composition!
const compose = (...fs) => x => {
let i = fs.length
while(i--) x = fs[i](x)
return x
}