Skip to content

Instantly share code, notes, and snippets.

View wmertens's full-sized avatar

Wout Mertens wmertens

View GitHub Profile
@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]
@kirbysayshi
kirbysayshi / mdb.js
Created September 12, 2011 19:36
example showing how to wrap node-mongodb-native driver in promises. uses jquery deferreds from https://github.com/kirbysayshi/jquery-jqd
var mongo = require('mongodb')
,jqd = require('../jquery-jqd').jqd
,host = process.env['MONGO_NODE_DRIVER_HOST'] != null
? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost'
,port = process.env['MONGO_NODE_DRIVER_PORT'] != null
? process.env['MONGO_NODE_DRIVER_PORT'] : mongo.Connection.DEFAULT_PORT
,db = null
,gConnection = null;
@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
export default function withMutation({name, args}) {
let mutation;
if (args) {
const args1 = _.map(args, (type, name) => `$${name}: ${type}`); // e.g. $url: String
const args2 = _.map(args, (type, name) => `${name}: $${name}`); // e.g. $url: url
mutation = `
mutation ${name}(${args1}) {
${name}(${args2})
@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) => {
@MrOrz
MrOrz / README.md
Last active July 22, 2018 15:36
Cross-device BrowserSync with webpack demo
@MoOx
MoOx / svgicon.css
Last active December 3, 2018 08:50
Svg icons with React.js with webpack loader (svg: raw-loader)
.SVGIcon {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* fix webkit/blink poor rendering issues */
transform: translate3d(0,0,0);
/* it's better defined directly because of the cascade shit
width: inherit;
height: inherit;
@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>