Skip to content

Instantly share code, notes, and snippets.

View bbstilson's full-sized avatar
🕺

Brandon Stilson bbstilson

🕺
View GitHub Profile
@aarondewindt
aarondewindt / adt.py
Last active October 27, 2023 05:07
Experimental Algebraic Data Types implementation in Python 3.10
from dataclasses import dataclass
class ADTMeta(type):
def __new__(mcs, name, bases, namespace: dict):
adtc_class = super().__new__(mcs, name, bases, namespace)
if "__is_adt_variant__" in namespace:
if namespace["__is_adt_variant__"]:
return adtc_class
@justgage
justgage / HowToElm.md
Last active January 17, 2020 23:49
How To Elm

How to Elm

This is a basic guide on how to learn Elm rather than actually teach you. I'm going to mostly link to resources that I feel are valuable and try to "teach you how to fish".

The main purpose is to accelerate your learning and save you a lot of googling and weeding through bad explinations.

Essential links

var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}
@oinopion
oinopion / read-access.sql
Created October 5, 2016 13:00
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@acdlite
acdlite / app.js
Last active January 20, 2023 08:23
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
anonymous
anonymous / dodgygame_ai.js
Created July 5, 2016 14:33
Dodgy game AI
/**
* @author Dongjun Lee <dongjun.lee@streami.co>
* Game AI for dodgygame. (http://brandonstilson.com/dodgygame/)
*
* How to use
* Copy and paste in browser's inspector console.
*/
// constants
var BOARD_SIZE = 11;
@jpalala
jpalala / how-to-setup-mac-elasticsearch.md
Created September 11, 2015 08:28
setting up elasticsearch on your mac with brew

Install va homebrew

If you don't have homebrew installed - get homebrew here

Then run: brew install elasticsearch

Configuration

Update the elasticsearch configuration file in /usr/local/etc/elasticsearch/elasticsearch.yml.

@JeffBelback
JeffBelback / docker-destroy-all.sh
Last active December 12, 2023 17:47
Destroy all Docker Containers and Images
#!/bin/bash
# Stop all containers
containers=`docker ps -a -q`
if [ -n "$containers" ] ; then
docker stop $containers
fi
# Delete all containers
containers=`docker ps -a -q`
if [ -n "$containers" ]; then
docker rm -f -v $containers
@agemooij
agemooij / customformat.scala
Last active November 28, 2022 13:50
More advanced example of a custom spray-json format
implicit object ProductItemFormat extends RootJsonFormat[ProductItem] {
// some fields are optional so we produce a list of options and
// then flatten it to only write the fields that were Some(..)
def write(item: ProductItem) = JsObject(
List(
Some("product_number" -> item.productNumber.toJson),
item.ean.map(ean ⇒ "ean" -> ean.toJson),
Some("title" -> item.title.toJson),
item.description.map(description ⇒ "description" -> description.toJson),
Some("price" -> item.price.toJson),
@caridy
caridy / export-syntax.js
Last active January 15, 2022 14:22
ES6 Module Syntax Table
// default exports
export default 42;
export default {};
export default [];
export default foo;
export default function () {}
export default class {}
export default function foo () {}
export default class foo {}