Skip to content

Instantly share code, notes, and snippets.

View benzen's full-sized avatar

Benjamin Dreux benzen

View GitHub Profile
@benzen
benzen / gist:710036
Created November 22, 2010 14:29
cesear kata
(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)))
@benzen
benzen / async v1.coffee
Last active August 29, 2015 14:17
Highland vs 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
async.auto
@benzen
benzen / context.md
Last active September 6, 2015 11:22
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
benzen / mamanpourlavie.com.coffee
Created September 6, 2015 22:27
Une impression de déjà vue ici
cheerio = require "cheerio"
superagent = require "superagent"
async = require "async"
_ = require "lodash"
BOY_URLS = [
"http://www.mamanpourlavie.com/prenoms/lettre/a/garcon",
"http://www.mamanpourlavie.com/prenoms/lettre/b/garcon",
"http://www.mamanpourlavie.com/prenoms/lettre/c/garcon",
"http://www.mamanpourlavie.com/prenoms/lettre/d/garcon",
"http://www.mamanpourlavie.com/prenoms/lettre/e/garcon",
(deftask devcards []
(comp
(serve :dir "frontend/target/")
(watch)
(speak)
(cljs :unified true
:source-map true
:optimizations :none
:compiler-options {
:main "our-child.devcards"
(ns our-child.devcards
(:require
[reagent.core :as rg]
[devcards.core :as dc])
(:require-macros
[devcards.core :as dc :refer [defcard defcard-doc deftest dom-node]]))
(dc/defcard string-card (str "## **string** type will render as markdown."))
<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)",
let render = render || function(){
React.render(
<DevCardsListing/>,
document.getElementById('app'));
};
setInterval(
function(){
requestAnimationFrame(render);
@benzen
benzen / exercices.js
Last active November 5, 2015 19:10 — forked from fxg42/exercices.js
Exercices
// # 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 ];
@benzen
benzen / genux.js
Last active February 17, 2016 03:49
Maybe the samllest flux implementation ever
//utilitary functions
const find = (pred, coll) => {
for(const item of coll){
if(pred(item)){
return item;
}
}
return null;
};