Skip to content

Instantly share code, notes, and snippets.

View skellock's full-sized avatar

Steve Kellock skellock

View GitHub Profile

In this tutorial we're going to build a set of parser combinators.

What is a parser combinator?

We'll answer the above question in 2 steps.

  1. What is a parser?
  2. and, what is a parser combinator?

So first question: What is parser?

import Reconciler from 'react-reconciler'
import omit from 'lodash/omit'
import capitalize from 'lodash/capitalize'
import { actions as elementActions } from './store/elements'
import * as Elements from './elements'
const roots = new Map()
const emptyObject = {}
const Renderer = Reconciler({
@evancz
evancz / data-interchange.md
Last active April 29, 2024 16:53
Why do I have to write JSON decoders in Elm?

A vision for data interchange in Elm

How do you send information between clients and servers? What format should that information be in? What happens when the server changes the format, but the client has not been updated yet? What happens when the server changes the format, but the database cannot be updated?

These are difficult questions. It is not just about picking a format, but rather picking a format that can evolve as your application evolves.

Literature Review

By now there are many approaches to communicating between client and server. These approaches tend to be known within specific companies and language communities, but the techniques do not cross borders. I will outline JSON, ProtoBuf, and GraphQL here so we can learn from them all.

@sibelius
sibelius / android25.sh
Created May 16, 2017 12:03
Upgrade all node_modules dependencies do android 25
#!/usr/bin/env bash
find node_modules -name 'build.gradle' -print -exec sed -i.bak -E 's/compileSdkVersion[[:space:]]+23/compileSdkVersion 25/g' {} \;
find node_modules -name 'build.gradle' -print -exec sed -i.bak -E 's/buildToolsVersion[[:space:]]+"23.0.1"/buildToolsVersion "25.0.1"/g' {} \;
@mochja
mochja / main.c
Last active September 25, 2023 15:08
Yoga + OpenGL Example
#include <GLFW/glfw3.h>
#include <yoga/Yoga.h>
#include <stdlib.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
@mjackson
mjackson / resolvePromise.js
Last active September 9, 2018 08:23
An easy way to do async APIs in JavaScript that support both promises *and* callbacks!
// Here is a function that I use all the time when creating public
// async APIs in JavaScript:
const resolvePromise = (promise, callback) => {
if (callback)
promise.then(value => callback(null, value), callback)
return promise
}
// Sometimes I like to use callbacks, but other times a promise is
@Jeevuz
Jeevuz / isDeviceLocked.java
Created September 20, 2016 10:41
Check device is currently locked
/**
* Returns true if the device is locked or screen turned off (in case password not set)
*/
public static boolean isDeviceLocked(Context context) {
boolean isLocked = false;
// First we check the locked state
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
boolean inKeyguardRestrictedInputMode = keyguardManager.inKeyguardRestrictedInputMode();
@mmazzarolo
mmazzarolo / redux_naming_example.js
Created September 6, 2016 21:44
Redux naming example
import { find, findIndex, pullAt } from 'lodash'
import { actionTypes as appActionTypes } from 'reducers/appReducer'
export const actionTypes = {
CREATE_MENU_ENTRY_REQUEST: 'MENU/CREATE_MENU_ENTRY_REQUEST',
CREATE_MENU_ENTRY_SUCCESS: 'MENU/CREATE_MENU_ENTRY_SUCCESS',
CREATE_MENU_ENTRY_FAILURE: 'MENU/CREATE_MENU_ENTRY_FAILURE',
UPDATE_MENU_ENTRY_REQUEST: 'MENU/UPDATE_MENU_ENTRY_REQUEST',
UPDATE_MENU_ENTRY_SUCCESS: 'MENU/UPDATE_MENU_ENTRY_SUCCESS',
UPDATE_MENU_ENTRY_FAILURE: 'MENU/UPDATE_MENU_ENTRY_FAILURE',
@mmazzarolo
mmazzarolo / ContainerExample1.js
Created August 3, 2016 07:34
Authentication duck example
// ACTIONCREATORS USAGE EXAMPLE 1
// When the action needed are all in a single duck (in this case authReducer)
import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { actionCreators } from '../reducers/authReducer'
const mapStateToProps = (state, ownProps) => ({
// blablabla
})
@littlepsylo
littlepsylo / index.js
Last active July 28, 2016 13:37
Using WebSocket in react-native with a socket.io server
const io = new WebSocket('ws://yourdomain:port/socket.io/?transport=websocket')
io.onclose = e => console.log('onclose', e.code, e.reason)
io.onerror = e => console.log('onerror', e.message)
io.onopen = () => console.log('connected !')