Skip to content

Instantly share code, notes, and snippets.

View wmertens's full-sized avatar

Wout Mertens wmertens

View GitHub Profile
@wmertens
wmertens / nix.tmLanguage
Created December 1, 2014 00:05
Nix syntax highlighting in TextMate format
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>nix</string>
</array>
<key>name</key>
<string>Nix</string>
@wmertens
wmertens / script.coffee
Last active August 29, 2015 14:15
PwRggP
# Pure coffeescript React.JS
# Also features "global state manager"
R = React.DOM
N = null
# global state manager
render = null
state = clicks: 0
count = ->
@wmertens
wmertens / auto-vendor-prefixer.coffee
Last active August 29, 2015 14:18
tiny in-browser memoized auto-prefixer for React styles, supports flexbox too.
# Auto-vendor-prefixer
# Finds the vendor prefix to use
# MIT license, Author: Wout Mertens
prefix=null
myStyle=document?.head?.style or {}
foundProps={}
newCssProp = (prop) ->
t = foundProps[prop]
@wmertens
wmertens / q-promise-cache.coffee
Created June 21, 2013 10:30
Using cached promises for better resource use
# We have a function that loads some resource. It might get called multiple times by our application, for example a web server.
# We use a stored promise to serve as both a cache and a hook for multiple callers to get the same result
# JavaScript version at the bottom
Q = require 'q'
loadPromise = null
doLoad = ->
if not loadPromise
# get a fresh result
loadPromise = Q.delay(1000).then -> Date.now()
# after 1 second clear cache
@wmertens
wmertens / New iTerm Window.scpt
Last active February 2, 2017 21:48
Open a new iTerm window (https://iterm2.com) in the current application folder via Applescript
on run
-- Figure out if we want to do the cd (doIt)
-- Figure out what the path is and quote it (myPath)
set doIt to false
try
tell application "Finder" to set doIt to frontmost
set myPath to finder_path()
if myPath is equal to "" then
set doIt to false
else
// Based on https://gist.github.com/langpavel/b30f3d507a47713b0c6e89016e4e9eb7
const serializeDate = value => {
if (value instanceof Date) {
return value.toJSON().slice(0, 10)
} else if (typeof value === 'number') {
return Math.trunc(value)
} else if (typeof value === 'string') {
return (new Date(value)).toJSON().slice(0, 10)
}
return null

Keybase proof

I hereby claim:

  • I am wmertens on github.
  • I am wmertens (https://keybase.io/wmertens) on keybase.
  • I have a public key ASA6XQ6RqdgBgVFsOKWY0PV55O0x0hHULlbBfmNNhGbUXwo

To claim this, I am signing this object:

@wmertens
wmertens / Post.graphql
Last active June 12, 2017 11:27
Imagining what a graphql schema would look like that allows auto-creating lists and detail view/editor
enum PostStates { DRAFT, PUBLISHED, ARCHIVED }
scalar Date
scalar Html
directive @buildIndex on field
directive @defaultFirst on field
#...etc
type PostContent {
brief: Html @editor(height: 150, wysiwyg: true)
extended: Html @editor(height: 400, wysiwyg: true)
@wmertens
wmertens / router.jsx
Last active August 10, 2017 11:14
Wrapper for react-router v4 with an API more to my tastes
import React, {Component, PropTypes} from 'react'
import {Link, Route as OrigRoute, Switch, Redirect, BrowserRouter as Router, withRouter} from 'react-router-dom'
// Subscribes a child to history updates, passing the current location as a prop
// This is needed to work around the React context API not updating all children
// See https://github.com/ReactTraining/react-router/issues/4629#issuecomment-284218493
export class LocationListener extends Component {
static contextTypes = {
history: PropTypes.object,
}
@wmertens
wmertens / graphqlExpress.js
Created September 7, 2017 13:59
Add dataloaders to graphql context
import DataLoader from 'dataloader'
import {graphqlExpress} from 'graphql-server-express'
import schema from './schema'
import db from './database'
const contextFromReq = req => {
const {session} = req
const loaders = {}
const getLoader = (id, makeGetter) => {