Skip to content

Instantly share code, notes, and snippets.

View wmertens's full-sized avatar

Wout Mertens wmertens

View GitHub Profile
@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 / nix.YAML-tmLanguage
Last active October 6, 2022 19:42
Syntax highlighting for Nix in Sublime Text YAML-tmLanguage format
# [PackageDev] target_format: plist, ext: tmLanguage
# Made by Wout.Mertens@gmail.com
# This grammar tries to be complete, but regex-based highlighters
# can't be full parsers. Therefore it's a bit looser than the Nix
# parser itself and some legal constructs will be marked as illegal.
# It seems to work fine for nixpkgs.
# Cute hacks: Check out the attrset-for-sure and friends definitions
---
name: Nix
scopeName: source.nix
@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 / private.xml
Last active March 12, 2019 19:57
Use Karabiner (https://pqrs.org/osx/karabiner/) to emulate a http://waytools.com TextBlade as well as add some useful shortcuts for the TextBlade proper.
<?xml version="1.0"?>
<root>
<devicevendordef>
<vendorname>WT</vendorname>
<vendorid>0x000d</vendorid>
</devicevendordef>
<deviceproductdef>
<productname>TB</productname>
<productid>0x0000</productid>
@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 / full stack redux.md
Last active February 8, 2022 22:46
making an awesome server with the redux model, Work In Progress

Thought experiment: Redux-like stateless server

Description

We describe a model for client-server processing where the Redux model is used to minimize stateful code. This should allow live-reloading server code, and make it possible to share code (e.g. optimistic updating) between client and server.

Dramatis Personae

  • Assume a server consisting of multiple worker processes that do not share memory and may be running on multiple hosts.
    • Workers have middleware, root reducers and an app state object
  • Workers can be dynamically added and removed
@wmertens
wmertens / server.js
Last active January 5, 2019 15:51
Example Let's Encrypt configuration for KeystoneJS
const keystone = require('keystone')
keystone.init({
name: 'myApp',
brand: 'My App',
port: process.env.PORT,
'ssl port': process.env.SSLPORT,
ssl: 'force',
@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)
// 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