Skip to content

Instantly share code, notes, and snippets.

View erikvullings's full-sized avatar

Erik Vullings erikvullings

View GitHub Profile
@erikvullings
erikvullings / README.md
Last active August 29, 2015 14:14
Grouped horizontal bar chart.

This is an example of a horizontally grouped bar chart. It allows you to easily see the difference between different series of data.

@erikvullings
erikvullings / 0_reuse_code.js
Created May 8, 2017 11:32
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@erikvullings
erikvullings / scheduler.exs
Created August 9, 2017 14:20
Elixir scheduler example
# Example of a simple scheduler in Elixir
# Source code from the book Programming Elixir
# See: https://pragprog.com/book/elixir/programming-elixir
#
# Start iex
# $ iex
# > c("scheduler.exs")
# > Scheduler.run(12, FibSolver, :fib, [38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38])
defmodule Scheduler do
@erikvullings
erikvullings / fib_agent.exs
Created August 9, 2017 14:35
Fast Fibonacci implementation in Elixir
# Fast Fibonacci implementation (using a Map to cache previous results)
# This code comes from a mailing-list post by José Valim.
#
# Run iex
# $ iex
# > c("fib_agent.exs")
# > { :ok, agent } = FibAgent.start_link()
# > IO.puts FibAgent.fib(agent, 38)
defmodule FibAgent do
@erikvullings
erikvullings / gist:8e8d5ae026748681de8ddde90d835cde
Created August 11, 2017 09:30
Starting a new phoenix application
# Phoenix, by default, uses a Postgres database, so start one via docker
docker pull postgres
# Expose it on port 8432
docker run -p 8432:5432 --name hello-postgres -e POSTGRES_PASSWORD=postgres -d postgres
# Install Erlang, Elixir, and now Phoenix
mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez
# Create a new Phoenix app
mix phx.new hello
# Edit config/dev.exs and update your hostname. Add a port (default is 5432, but I've mapped it to 8432)
@erikvullings
erikvullings / docker-compose.yml
Created September 13, 2017 10:16
Docker-compose file for Kafka
---
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper
hostname: zookeeper
extra_hosts:
- "moby:127.0.0.1"
ports:
- "2181:2181"
@erikvullings
erikvullings / geo.ts
Last active May 29, 2018 15:49
Convert RD (rijksdriehoek) to WGS84 and back.
/**
* Convert RD (Rijksdriehoek) coordinates to WGS84 and vice versa.
* @see https://thomasv.nl/2014/03/rd-naar-gps/
*/
const projectionBetweenRdWgs84 = () => {
const x0 = 155000;
const y0 = 463000;
const f0 = 52.15517440; // f => phi
const l0 = 5.38720621; // l => lambda
@erikvullings
erikvullings / cachify.ts
Created May 31, 2018 08:00
Created a cached version of any function with a single argument.
/**
* Create a cached version of a function.
*
* @example cachedCalcArea = cachify(calcArea);
* @param fn Function whose results you want to cache
* @see TypeScript version of https://dev.to/kepta/javascript-underdogs-part-1---the-weakmap-4jih
*/
export const cachify = <T extends object, R>(fn: (arg: T) => R) => {
const cache = new WeakMap(); // Use Map() when dealing with non-object arguments
return (arg: T) => {
@erikvullings
erikvullings / index.html
Last active July 4, 2018 08:41
Horizontal axis with major and minor ticks using d3 version 4.
<!--
Source: https://gist.github.com/erikvullings/41be28677574fd484b43e91413a7e45d
Preview: https://bl.ocks.org/erikvullings/41be28677574fd484b43e91413a7e45d
-->
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
@erikvullings
erikvullings / deep-copy.ts
Created July 30, 2018 10:40
Deep copy or clone in TypeScript
/**
* Deep copy function for TypeScript.
* @param T Generic type of target/copied value.
* @param target Target value to be copied.
* @see Source project, ts-deepcopy https://github.com/ykdr2017/ts-deepcopy
*/
export const deepCopy = <T>(target: T): T => {
if (target === null) {
return target;
}