Skip to content

Instantly share code, notes, and snippets.

View mvarela's full-sized avatar
💭
The forecast is hacky, with high chance of parenthesis

Martín Varela mvarela

💭
The forecast is hacky, with high chance of parenthesis
View GitHub Profile
@mvarela
mvarela / keyboard-layout.json
Last active April 13, 2020 14:57
60% Keyboard design
[
[
{
"c": "#91867a"
},
"~\n`",
{
"a": 0
},
"!\n1\n\n\nF1",
@mvarela
mvarela / ibid.clj
Created February 2, 2020 09:39
A solution for the "Ibid." problem proposed by Gene Kim here: https://twitter.com/RealGeneKim/status/1201922587346866176?ref_src=twsrc%5Etfw. We avoid explicit recursion
(defn replace-ibids [coll]
(letfn [(go [{:keys [acc latest]} e]
(if (and (= e "Ibid.")
(some? latest))
{:acc (conj acc latest) :latest latest}
{:acc (conj acc e) :latest e}))]
(if (= "Ibid." (first coll))
(ex-info "Invalid ibid" {})
(-> (reduce go {:acc []} coll)
:acc))))
;; This snippet allows to add a ":ns" option to clojure source blocks, which
;; will correctly set the cider-buffer-ns variable, so that the block in quesiton, as well
;; as subsequent blocks, are executed in the desired namespace, instead of "user" (this happens
;; because of how CIDER handles the namespaces in non-clojure files (such as org files)
;; - example usage
;;
;;
;; The namespace is created, and the rest of the block is evaluated in it.
@mvarela
mvarela / de_jong.clj
Created October 29, 2017 09:56
De Jong attractors
(ns ifs.de-jong
(:require [clojure.core.matrix :as m]
[com.evocomputing.colors :as c]
[clojure.core.matrix.stats :as mstats])
(:import [java.io File]
[javax.imageio ImageIO]
[java.awt Color]
[java.awt.image
BufferedImage]))
(ns fractals.core
( :require [hiccup.core :as hiccup]))
(def start [:F :X])
(defn rewrite [i]
(cond
(= :X i) [:X :+ :Y :F :+]
(= :Y i) [:- :F :X :- :Y]
:true [i]))
@mvarela
mvarela / binVis2d.r
Created September 9, 2017 09:38
This is the code used in my blog post about binary data visualization. Feel free to use it as you see fit.
library(tidyverse)
# binviz Veles-like binary visualizaiton
binViz2d <- function(filename, alpha = 1/100, maxsize = 5000000,
save = TRUE, polar = FALSE, sample = FALSE,
sample_size = 2000000, do_density = FALSE){
# setting dens_plot as NA simplifies the logic below a bit
dens_plot = NA
case `uname` in
Linux)
HOSTTYPE="(\[\e[0;33m\]☢\[\e[0;32m\])"
;;
Darwin)
HOSTTYPE="(\[\e[0;31m\]\[\e[0;32m\])"
;;
esac
export PS1="\n\[\e[0;32m\]\u@\h$HOSTTYPE\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;34m\]\nλ\[\e[m\] \[\e[1;37m\]"
-- What is a "for" construct, really? :)
for :: (Monad m) => (a, (a -> Bool), a -> a) -> (a -> m ()) -> m ()
for (i, cond, fStep) fm = mapM_ fm $ takeWhile cond $ iterate fStep i
@mvarela
mvarela / gist:1322227
Created October 28, 2011 13:13
Brew Boost 1.4.7 failed build
...on 10100th target...
darwin.compile.c++ bin.v2/libs/thread/build/darwin-4.2.1/release/link-static/threading-multi/pthread/once.o
common.mkdir bin.v2/libs/wave/build/darwin-4.2.1/release/link-static
common.mkdir bin.v2/libs/wave/build/darwin-4.2.1/release/link-static/threading-multi
darwin.compile.c++ bin.v2/libs/thread/build/darwin-4.2.1/release/link-static/threading-multi/pthread/thread.o
darwin.archive bin.v2/libs/thread/build/darwin-4.2.1/release/link-static/threading-multi/libboost_thread-mt.a
common.copy /usr/local/Cellar/boost/1.47.0/lib/libboost_thread-mt.a
darwin.compile.c++ bin.v2/libs/wave/build/darwin-4.2.1/release/link-static/threading-multi/instantiate_cpp_grammar.o
darwin.compile.c++ bin.v2/libs/wave/build/darwin-4.2.1/release/link-static/threading-multi/instantiate_cpp_exprgrammar.o
darwin.compile.c++ bin.v2/libs/wave/build/darwin-4.2.1/release/link-static/threading-multi/instantiate_cpp_literalgrs.o