Skip to content

Instantly share code, notes, and snippets.


Benjamin Dreux benzen

View GitHub Profile
benzen / genux.js
Last active Feb 17, 2016
Maybe the samllest flux implementation ever
View genux.js
//utilitary functions
const find = (pred, coll) => {
for(const item of coll){
return item;
return null;
benzen / exercices.js
Last active Nov 5, 2015 — forked from fxg42/exercices.js
View exercices.js
// # Exercice 1:
// Étant données les deux fonctions suivantes:
// f :: a -> [b]
var f = (a) => [ a * a ];
// g :: a -> [b]
var g = (a) => [ a + 10 ];
View mini-flux.js
let render = render || function(){
View index.html
<script src="node_modules/babel/node_modules/babel-core/browser.js"></script>
<script src="react-0.13.3.js"></script>
<script type="text/babel">
var comp = function(fun){
return React.createClass({render:fun});
var DevCardTitle = DevCardTitle || comp(function(){
const titleStyle = {
backgroundColor: "rgb(239, 237, 237)",
View devcards.cljs
(ns our-child.devcards
[reagent.core :as rg]
[devcards.core :as dc])
[devcards.core :as dc :refer [defcard defcard-doc deftest dom-node]]))
(dc/defcard string-card (str "## **string** type will render as markdown."))
View build.boot
(deftask devcards []
(serve :dir "frontend/target/")
(cljs :unified true
:source-map true
:optimizations :none
:compiler-options {
:main "our-child.devcards"
benzen /
Created Sep 6, 2015
Une impression de déjà vue ici
cheerio = require "cheerio"
superagent = require "superagent"
async = require "async"
_ = require "lodash"
benzen /
Last active Sep 6, 2015
Rookie mistake with local state

Theses are two implmentation of the same components. The component is a label, with two button, one to increase the counter, and one to decrease.

The counter's value can't go bellow zero.

In the first implmentation, there is a tiny bit of logic that is miss placed. This logic is executed when the component is rendered. This is bad because the effect of this logic will never appear.

On the second implementaition the "previous-value" is computed with a corrected value (min 0).

benzen / async
Last active Aug 29, 2015
Highland vs Async
View async
async = require 'async'
findClient = (clientsColl, clientId, cb) ->
clientsColl.findOne _id: new ObjectID(clientId), cb
findProjetsByClient = (clientId, cb) ->
projetsModule.find client: new ObjectID(clientId), cb
joinClientAndProjetsIds = (client, projetsIds, cb) ->
client.projets = projetsIds
cb null, client
View gist:710036
(defn convert [number]
"Convert a number between 50 and 0 to it's roman representation"
(defn convert-rec [acc num]
(cond (< num 4)
(concat acc (take num (repeat "i")))
(= num 4)
(concat acc "iv")
(pos? (int (/ num 50)))
(cons acc "l")
(pos? (int (/ num 10)))