Skip to content

Instantly share code, notes, and snippets.

View freddi301's full-sized avatar

Frederik Batuna freddi301

View GitHub Profile
@freddi301
freddi301 / index.js
Last active November 3, 2017 13:19
Observables (alternative)
// alternative observables, knowledge about Observables implemetation is required (ex: RxJs)
// this is fully type-annoteable (typescript, flowtype)
// An observer is a function that takes an item from the stream
// and must return a function that will be called with the next item in the stream
// this way stateful observers can mantain state in clojures and every instance of them if replayable.
// observers should not have side effects
// type Observer<T> = (item: T) => Observer<T>
@freddi301
freddi301 / veawco.js
Created September 19, 2017 15:12
version aware programming proof of concept
// @flow
/// as first we declare the contract our program will have with external world
type v1Api = {
getPerson(id: string): v1Person,
addPerson(person: v1Person): void
};
type v1Person = { id: string, name: string, age: number };
@freddi301
freddi301 / curryByNam.js
Created August 30, 2017 08:10
JavaScript + Flow Named Curried Functions
/* @flow */
const createPerson = ({}: { name: string, birth: Date, pets: number }): [] => []
const a = {};
//createPerson(a);
const b = { ...a, name: 'fred' };
//createPerson(b);
@freddi301
freddi301 / TypeFaster.html
Last active September 25, 2019 09:29
Type Faster
<html>
<head>
<style>
.type-chars {
font-family: monospace;
font-size: 30px;
}
</style>
</head>
<body>
@freddi301
freddi301 / do_not_cache.http.headers
Created June 15, 2017 08:26
Do not cache HTTTP headers
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
@freddi301
freddi301 / doc_build.sh
Created March 1, 2017 02:43
Automatic gh-pages branch generation script
#!/usr/bin/env bash
set -e
set -x
COMMIT=$(git rev-parse master)
TAG=$(git describe $(git rev-list --tags --max-count=1))
DATE=`date +%Y-%m-%d`
mkdir -p doc-building
@freddi301
freddi301 / rx_transducers.js
Last active October 6, 2016 01:58
rx + transducers
const map = f => r => (m, i) => r(m, f(i));
const filter = p => r => (m, i) => (p(i) ? r(m, i) : m);
function conc(m, i) { return m.concat(i); }
[1, 2, 3].reduce(
map(x => (console.log('map ' + x), x + x))(
filter(x => (console.log('filter ' + x), x !== 4))(conc)),
[]);
class S {
@freddi301
freddi301 / clone_gists.js
Created June 28, 2016 10:38
Clone Public gists
const gistUser = process.argv[2]; if (!gistUser) {
console.error('no gist user specified'); process.exit(1); }
const destDir = process.argv[3] || './';
const exec = require('child_process').exec;
const path = require('path');
exec(`curl -s https://api.github.com/users/${gistUser}/gists`, (e, so, se) => {
gists = JSON.parse(so).map(gist => ({
folder: gist.description || gist.id,
pull: gist.git_pull_url }));
@freddi301
freddi301 / docker_proxy_set.sh
Last active June 28, 2016 18:23
Docker Utils Scripts
#!/bin/sh
mkdir -p /etc/systemd/system/docker.service.d
echo "[Service]
Environment=\"HTTP_PROXY=http://10.215.2.2:8080/\"
Environment=\"HTTPS_PROXY=https://10.215.2.2:8080/\""\
> /etc/systemd/system/docker.service.d/http-proxy.conf
echo sudo systemctl daemon-reload
@freddi301
freddi301 / optimisticLoopMongo.js
Created June 20, 2016 17:04
Optimistic Loop Mongo Node + throng
import throng from 'throng';
import {MongoClient} from 'mongodb';
let dups = 0;
async function insertOptimisticLoop(doc, collection, retry=100){
const cursor = await collection // find greatest __t progrssive number
.find( { __t: { $exists: true } }, { __t: 1, __id: -1} )
.sort( { __t: -1 } ).limit(1);
const next = await cursor.hasNext() ? (await cursor.next()).__t + 1 : 1; // calculate next __t