Skip to content

Instantly share code, notes, and snippets.

View bs1180's full-sized avatar

Ben Smith bs1180

  • Vienna, Austria
View GitHub Profile
@lenileiro
lenileiro / datalog.ex
Last active April 17, 2024 21:02
Elixir Datalog modelled as ReBAC (Relationship-Based Access Control) - Inspired by Google Zanzibar authorization system
defmodule Datalog do
defstruct rules: [], facts: %{}
alias Datalog.{Fact, Rule}
alias __MODULE__
def new, do: %__MODULE__{}
def add_rule(%Datalog{rules: rules} = datalog, %Rule{} = rule) do
{:ok, %Datalog{datalog | rules: [rule | rules]}}

Everything I Know About UI Routing

Definitions

  1. Location - The location of the application. Usually just a URL, but the location can contain multiple pieces of information that can be used by an app
    1. pathname - The "file/directory" portion of the URL, like invoices/123
    2. search - The stuff after ? in a URL like /assignments?showGrades=1.
    3. query - A parsed version of search, usually an object but not a standard browser feature.
    4. hash - The # portion of the URL. This is not available to servers in request.url so its client only. By default it means which part of the page the user should be scrolled to, but developers use it for various things.
    5. state - Object associated with a location. Think of it like a hidden URL query. It's state you want to keep with a specific location, but you don't want it to be visible in the URL.
@busypeoples
busypeoples / TypeScriptFundamentals.ts
Last active June 21, 2022 14:57
TypeScript Fundamentals For JavaScript Developers
// TypeScript Fundamentals For JavaScript Developers
/*
Tutorial for JavaScript Developers wanting to get started with TypeScript.
Thorough walkthrough of all the basic features.
We will go through the basic features to gain a better understanding of the fundamentals.
You can uncomment the features one by one and work through this tutorial.
If you have any questions or feedback please connect via Twitter:
A. Sharif : https://twitter.com/sharifsbeat
*/
@lenkan
lenkan / use-location.js
Created March 2, 2019 18:26
React hook that keeps up to date with the current location.
// @ts-check
import { useState, useEffect } from 'react'
function getCurrentLocation () {
return {
pathname: window.location.pathname,
search: window.location.search
}
}
@rzane
rzane / Field.js
Created November 14, 2017 15:12
<Field /> component that supports nested values for formik
import React from 'react';
import PropTypes from 'prop-types';
import { set, get } from 'lodash/fp';
/**
* This is a copy-pasta job of Formik's Field component. It's needed in
* order to handle nested values. Future versions of formik will support
* this.
*/
@antho1404
antho1404 / migration.js
Last active September 25, 2018 07:07
A script to be able to execute some data migrations with graphcool framework
const fs = require('fs')
const os = require('os')
const vm = require('vm')
const yaml = require('js-yaml')
const { paramCase } = require('change-case')
const { GraphQLClient } = require('graphql-request')
const cmd = process.argv[2]
const MIGRATION_PATH = `./db/migrations`
const isLocalTarget = target => target.startsWith('local/')
@branneman
branneman / fp-lenses.js
Last active May 17, 2023 00:56
JavaScript: Lenses (Functional Programming)
// FP Lenses
const lens = get => set => ({ get, set });
const view = lens => obj => lens.get(obj);
const set = lens => val => obj => lens.set(val)(obj);
const over = lens => fn => obj => set(lens)(fn(view(lens)(obj)))(obj);
const lensProp = key => lens(prop(key))(assoc(key));
@tkh44
tkh44 / Box.js
Created August 30, 2017 20:54
styled-system with emotion.
import styled, { css } from 'emotion/react'
import { space, width, fontSize, color, responsiveStyle } from 'styled-system'
export const display = responsiveStyle('display')
export const flex = responsiveStyle('flex')
export const order = responsiveStyle('order')
const wrap = responsiveStyle('flex-wrap', 'wrap', 'wrap')
const direction = responsiveStyle('flexDirection', 'direction')
const align = responsiveStyle('alignItems', 'align')
@tkh44
tkh44 / index.js
Created August 25, 2017 19:25
Getting react-leaflet working with SSR (next.js)
import React from 'react'
export default class extends React.Component {
constructor () {
super()
this.state = { components: undefined }
this.markers = new WeakMap()
}
componentDidMount () {
@francoisromain
francoisromain / project-create.sh
Last active June 14, 2024 09:55
A bash script to create a Git post-receive hook to deploy after a Git push
#!/bin/bash
# source: https://gist.github.com/francoisromain/58cabf43c2977e48ef0804848dee46c3
# and another script to delete the directories created by this script
# project-delete.sh: https://gist.github.com/francoisromain/e28069c18ebe8f3244f8e4bf2af6b2cb
# Call this file with `bash ./project-create.sh project-name`
# - project-name is mandatory
# This will creates 4 directories and a git `post-receive` hook.