Skip to content

Instantly share code, notes, and snippets.

http://www.w3.org/TR/2013/WD-cssom-view-20131217/
// Window Extensions
enum ScrollBehavior { "auto", "instant", "smooth" };
dictionary ScrollOptions {
ScrollBehavior behavior = "auto";
};
data Maybe a = Nothing | Just a
bind :: Maybe a -> (a -> Maybe b) -> Maybe b
bind m f = case m of
Just x -> f x
Nothing -> Nothing
return :: a -> Maybe a
return x = Just x
@joseanpg
joseanpg / transpose.hs
Created October 27, 2013 09:16
Matrix transposition usind foldl
import Control.Monad
transpose [] = []
transpose (z:zs) = foldl beta (alpha z) zs
where alpha = map (\x-> [x])
beta = zipWith (\x y-> x++[y])
transpose' [] = []
transpose' (z:zs) = map reverse $ foldl beta (alpha z) zs
where alpha = map (\x-> [x])
@joseanpg
joseanpg / BB.sml
Last active December 24, 2015 05:49
(*
http://groups.csail.mit.edu/mac/users/adams/BB/BB.sml
Copyright 1992-1996 Stephen Adams.
This software may be used freely provided that:
1. This copyright notice is attached to any copy, derived work,
or work including all or part of this software.
2. Any derived work must contain a prominent notice stating that
import Control.Monad.State
type Interact a = StateT Int IO a
repl :: Interact ()
repl = forever $ do
val <- liftIO readLn
state <- get
liftIO $ putStr "Total: "
liftIO $ print (val + state)
@joseanpg
joseanpg / discrete_non_uniform.hs
Last active December 18, 2015 07:49
[Pendiente]
-- Basado en
-- https://twitter.com/joseanpg/status/343757288089190401
-- https://twitter.com/joseanpg/status/343758742455738368
-- https://twitter.com/joseanpg/status/343759216424652802
-- Version ultramejorable: http://t.co/da8tx1LK6r
-- Versión Clojure by @jneira: https://gist.github.com/jneira/5745669
-- con probabilidad inversamente proporcional a las prioridades
import Random
@joseanpg
joseanpg / GasterAlgebraicHierarchy97.hs
Created June 9, 2013 13:14
Gaster's Algebraic hierarchy
-- http://benedictgaster.org/wp-content/uploads/2012/08/haskwork97.pdf
-- Polymorphic Extensible Records for Haskell (page 3)
type Monoid v r = Rec { plus :: v -> v -> v , id :: v | r }
type Group v r = Monoid v { inv :: v -> v | r }
type Ring v r = Group v { mult :: v -> v -> v , one :: v | r }
iMonoid :: Monoid Int {}
@joseanpg
joseanpg / EditInPlace.js
Created May 13, 2013 08:19
EditInPlace.js
var editor = null;
var sleeping = null;
var sleepingParent = null;
function handler(ev) {
var el = ev.target;
if (sleeping) {
sleeping.innerHTML = editor.value;
editor.value = '';
editor.defaultValue = editor.value;
@joseanpg
joseanpg / SimpleHttpRequest.js
Last active December 17, 2015 00:59
SimpleHttpRequest
(function(module){
var hop = Object.prototype.hasOwnProperty;
var urlEncode = function(flatObject) {
var result = [];
for (var p in flatObject) if (hop.call(flatObject,p)) {
result.push(encodeURIComponent(p)+'='+encodeURIComponent(flatObject[p]));
}
return result.join('&');
@joseanpg
joseanpg / cps.scm
Created April 20, 2013 09:05
LISP in small pieces: CPS Transformation (5.9)
;; http://books.google.es/books?id=81mFK8pqh5EC&pg=PA177#v=onepage&q&f=false
;; http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/LiSP.html
;; src/chap5f.scm
(define (cps e)
(if (pair? e)
(case (car e)
((quote) (cps-quote (cadr e)))
((if) (cps-if (cadr e) (caddr e) (cadddr e)))
((begin) (cps-begin (cdr e)))