Skip to content

Instantly share code, notes, and snippets.

View elnygren's full-sized avatar

el3ng elnygren

  • Helsinki, Finland
View GitHub Profile
@elnygren
elnygren / sql.ts
Created June 11, 2019 14:02
Knex + Mocha tests with seeding & clearing db
import * as shelljs from 'shelljs'
import db from 'path-to-knex-client'
import config from 'src/config'
/**
Mocha hooks
*/
before(async () => {
@elnygren
elnygren / ReasonMLStory.re
Created April 25, 2019 17:22
React Storybook ReasonML
open StoryBook;
let _module = [%bs.raw "module"];
storiesOf("ReasonML Example", _module)
->addDecorator(storyFn =>
<div style={ReactDOMRe.Style.make(~textAlign="center", ~marginTop="50px", ())}>
{storyFn()}
</div>
)
@elnygren
elnygren / apollo_cache_control.re
Created April 9, 2019 01:01
ReasonML snippets
/**
Very nasty way to control Apollo cache in reason-apollo
*/
[@bs.module] external gql: ReasonApolloTypes.gql = "graphql-tag";
let shifts_query =
gql(.
@elnygren
elnygren / 01-update_config.sh
Last active April 4, 2019 22:07
Hasura Kubernetes setup with version-controlled changes and CI/CD
#!/bin/bash
kubectl delete -n staging configmap hasura-configmap
kubectl create -n staging configmap hasura-configmap --from-file=metadata.json
@elnygren
elnygren / monad.re
Created March 6, 2019 15:02
ReasonML monad proof
/* monad */
type box('t) = Foo('t);
let return = (x) => Foo(x);
let bind = (b, f) => switch b {
| Foo(v) => f(v)
};
/* proof helpers */
let a = 1;
let m = Foo(a);
@elnygren
elnygren / Dockerfile
Last active April 5, 2025 21:35
Nginx+Docker with autoreload on config changes for local development
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
RUN apt-get update && apt-get install -y inotify-tools
COPY watcher.sh /watcher.sh
RUN chmod +x /watcher.sh
CMD ["/watcher.sh"]
@elnygren
elnygren / brew.sh
Last active March 4, 2019 13:51
Setting up a new Macbook
#!/usr/bin/env bash
# Check for Homebrew and install it if missing
if test ! $(which brew)
then
echo "Installing Homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# Make sure we’re using the latest Homebrew.
@elnygren
elnygren / validation.ts
Created February 12, 2019 10:25
Field validation with nice type safety in TypeScript
/** Valid doesn't really need any metadata */
type Valid = {
t: true
}
/** Invalid should describe all the problems */
type Invalid = {
t: false
errors: Array<{ text: string /** object, in case more fields are needed here */ }>
}
@elnygren
elnygren / tslint.json
Created December 3, 2018 15:48
TSLINT + Prettier
{
"extends": [
"tslint:recommended",
"tslint-config-prettier"
],
"rulesDirectory": [
"tslint-plugin-prettier"
],
"rules": {
"no-console": false,
@elnygren
elnygren / db.ts
Created September 22, 2018 11:29
Knex with query logging and camelCasing
/// <reference path="./identifierMappings-types.d.ts" />
import * as knex from 'knex';
import * as config from '../config'
import { knexSnakeCaseMappers } from './identifierMappings'
const db: knex = knex({
client: 'pg',
connection: config.DATABASE_URL,
...knexSnakeCaseMappers(),
})