Skip to content

Instantly share code, notes, and snippets.

View freddi301's full-sized avatar

Frederik Batuna freddi301

View GitHub Profile
@freddi301
freddi301 / pgnotify.js
Created June 17, 2016 09:44
Postgres Notify Trigger on eany table in JSON + node listener
var pg = require ('pg');
var pgConString = "postgres://postgres:mysecretpassword@localhost/postgres"
pg.connect(pgConString, function(err, client) {
if(err) {
console.log(err);
}
client.on('notification', function(msg) {
console.log(msg);
@freddi301
freddi301 / MongoCappedEventStore.js
Created June 17, 2016 09:40
Mongo EventStore with capped collection + throng
const mongodb = require('mongodb')
const Bluebird = require('bluebird')
class EventStore {
constructor(dbUrl, collectionName){
this.db = mongodb.MongoClient.connect(dbUrl);
this.cappedCollection = this.db.then(db=>
db.createCollection(collectionName, { capped: true, size: 1024*1024 })
.then(()=> db.collection(collectionName).createIndex({__t: 1}, {unique: true}))
.then(()=> db.collection(collectionName))
@freddi301
freddi301 / graphql.js
Created June 17, 2016 09:38
GraphQL Node Hello World with thron
const g = require('graphql'),
graphql = g.graphql,
GraphQLSchema = g.GraphQLSchema,
GraphQLObjectType = g.GraphQLObjectType,
GraphQLString = g.GraphQLString
const schema = new GraphQLSchema({
query: new GraphQLObjectType({ name: 'RootQueryType', fields: {
hello: { type: GraphQLString, resolve() { return 'world'; } },
ciao: { type: GraphQLString, resolve(){return Promise.resolve("heila")} }
@freddi301
freddi301 / lambda.js
Created June 17, 2016 09:35
Lambda JS in Thunks
// @flow
//"use strict";
interface Evaluable {
evaluate(scope: Object): ()=> Evaluable
}
/*
{ type: Lambda ,name:String , argument: String, body: Evaluable }
*/
@freddi301
freddi301 / javascript_functional_double_linked_list.js
Created December 12, 2015 16:24
JavaScript Functional Double-linked List
function prev(prev){return (self)=>(next)=>prev};
function self(prev){return (self)=>(next)=>self};
function next(prev){return (self)=>(next)=>next};
function node(self){return (next)=>(prev)=>(select)=>select(prev)(self)(next?next(node(self)(next)(prev)):next)};
function array2doublelist(array, index){
return index<array.length?
node(array[index])(array2doublelist(array,index+1))
:null;