Skip to content

Instantly share code, notes, and snippets.

View ThomasCrevoisier's full-sized avatar

Thomas Crevoisier ThomasCrevoisier

View GitHub Profile
@ThomasCrevoisier
ThomasCrevoisier / ClojureScript_example
Created December 17, 2014 21:59
Simple example of ClojureScript
(ns poney.world)
(defn hastalavistaify [xs]
(str "Hasta la vista " xs))
(hastalavistaify "Thomas") ;;; Outputs : "Hasta la vista Thomas"
(map hastalavistaify ["Thomas" "poney" "mutability"]) ;;; Outputs : ("Hasta la vista Thomas" "Hasta la vista poney" "Hasta la vista mutability")
@ThomasCrevoisier
ThomasCrevoisier / ClojureScript_example#1
Last active August 29, 2015 14:11
Keyword to property conversion in ClojureScript
;;; ClojureScript example from David Nolen's talk "ClojureScript : Lisp's revenge"
;;; https://www.youtube.com/watch?v=MTawgp3SKy8
(defn capitalize [s]
(str (.toUpperCase (aget s 0))
(.substring s 1)))
(defn keyword->property [k]
(let [[x & xs] (-> (str k) (.substring 1) (.split "-"))]
(apply str x (map capitalize xs))))
@ThomasCrevoisier
ThomasCrevoisier / monetjs_example#1
Created December 23, 2014 23:14
A simple example using Maybe monad of MonetJS
// Run the code with NodeJS
var Monet = require('monet');
function getValue (obj, keysString) {
var keys = keysString.split('.');
var curr = obj;
keys.forEach(function (key) {
module Exercises where
import Data.Monoid
class (Monoid m) <= Action m a where
act :: m -> a -> a
instance repeatAction :: Action Number String where
act 0 _ = ""
act n s = s ++ act (n - 1) s
combineMaybe :: forall a f. (Applicative f) => Maybe (f a) -> f (Maybe a)
combineMaybe (Just x) = pure <$> x
combineMaybe Nothing = pure Nothing
@ThomasCrevoisier
ThomasCrevoisier / gist:2ca1476b197bbf5de9ce
Last active August 29, 2015 14:15
purescript-sample
module Exercises where
import Math
import Control.Monad.Eff.Random
import Control.Monad.Eff
import Control.Monad.ST
import Debug.Trace
{- Non-working version -}
foreign import mapHRecLabel
"function mapHRecLabel(f, rec) {\
\ var mapped = {};\
\ for (var k in rec) {\
\ if (rec.hasOwnProperty(k)) {\
\ mapped[k] = f(k, rec[k]);\
\ }\
\ }\
\ return mapped;\
@ThomasCrevoisier
ThomasCrevoisier / HW04.hs
Created May 7, 2015 08:40
CIS194 - HW04
{-# OPTIONS_GHC -Wall #-}
module HW04 where
newtype Poly a = P [a]
-- Exercise 1 -----------------------------------------
x :: Num a => Poly a
x = P [0, 1]
fibs2 :: [Integer]
fibs2 = 1 : 1 : zipWith (\a b -> a + b) fibs2 (tail fibs2)
@ThomasCrevoisier
ThomasCrevoisier / live-coding.js
Created September 28, 2015 11:57
String evaluation on ctrl+enter
var keypressed = Bacon.fromEvent(document.getElementById('text-editor'), 'keypress');
var evaluatedString = keypressed
.filter(function (event) { return event.ctrlKey && event.charCode === 10; })
.map(function (event) { return getSelection(event.target.value, event.target.selectionStart, event.target.selectionEnd); })
.filter(function (value) { return !!value.trim(); }).log();