Skip to content

Instantly share code, notes, and snippets.

View jneira's full-sized avatar
:octocat:

Javier Neira jneira

:octocat:
View GitHub Profile
/* Son objetivos fundamentales:
* - Minimizar las funciones ECMAScript utilizadas
* - Optimizar en espacio, evitando la creación de arrays transitorios
*
* Suponemos que no se utilizará esta función con arrays creados
* en frames externos, con lo cual instanceof Array es seguro
*/
function aplaneitor(soa,acu) {
if (soa instanceof Array) {
-- A simple definition without using any fancy functions.
haskell>let ifMaybe pred value = if pred value then Just value else Nothing
haskell>:t ifMaybe
ifMaybe :: (a -> Bool) -> a -> Maybe a
haskell>ifMaybe (const True) 2
Just 2
haskell>ifMaybe (const False) 2
Nothing
-- Using functions from standard library.
@Gozala
Gozala / example.js
Created January 29, 2012 03:46
Workaround for lack of "tail call optimization" in JS
// Lack of tail call optimization in JS
var sum = function(x, y) {
return y > 0 ? sum(x + 1, y - 1) :
y < 0 ? sum(x - 1, y + 1) :
x
}
sum(20, 100000) // => RangeError: Maximum call stack size exceeded
// Using workaround
@timyates
timyates / LazyGenerator.groovy
Created April 20, 2012 14:04
LazyGenerator
LazyGenerator.from 1..10 where { it < 3 } transform { it * idx++ } using idx:0 each {
println "Transformed Range $it"
}
LazyGenerator.from x:1..5, y:2..5 where { ( x + y ) % ( x + 2 ) == 0 } eachWithIndex { match, idx ->
println "$idx) $match"
}
LazyGenerator.from 1..10 each {
println "Range: $it"
@techtangents
techtangents / Nel.hs
Created January 24, 2013 12:21
Just learning how to instance Comonad on Non-Empty List
module Nel where
import Control.Comonad
infixr 5 :|
data Nel a = a :| [a]
toList :: Nel a -> [a]
toList (a :| as) = a : as
@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
@Chouser
Chouser / externs_for_cljs.clj
Created June 17, 2013 13:44
Generate an externs.js file for arbitrary JS libraries for use in advanced Google Closure compilation, based on the ClojureScript code that uses the libraries.
(ns n01se.externs-for-cljs
(:require [clojure.java.io :as io]
[cljs.compiler :as comp]
[cljs.analyzer :as ana]))
(defn read-file [file]
(let [eof (Object.)]
(with-open [stream (clojure.lang.LineNumberingPushbackReader. (io/reader file))]
(vec (take-while #(not= % eof)
(repeatedly #(read stream false eof)))))))
@rxaviers
rxaviers / gist:7360908
Last active May 24, 2024 07:00
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue: