Skip to content

Instantly share code, notes, and snippets.

A quick jQuery plugin for asynchronously embedding a gist in an HTML document.

There are a couple of ways to use it. The simpler way is replacing all Gist links in document by their embedded version:

<script>$($.gist);</script>

All links that point to a gist, or gist file will be replaced by the corresponding embedded gist, or gist file.

Gist link replacement can also be called on a container element:

@douglas-vaz
douglas-vaz / prime.clj
Last active August 29, 2015 14:25
Prime function in Clojure
(defn divisible? [x y] (zero? (mod x y)))
(defn prime? [num]
(or (= num 2) (and (not (even? num)) (not-any? #(divisible? num %) (range 3 (inc (Math/sqrt num)) 2)))))
@douglas-vaz
douglas-vaz / merge.clj
Created July 16, 2015 05:59
Merge sort in Clojure
(ns merge-sort)
(defn split-at-middle [xs] (split-at (/ (count xs) 2) xs))
(defn merge [X Y]
(loop [ [xhead & xtail :as x] X, [yhead & ytail :as y] Y, Result []]
(if (and (not-empty x) (not-empty y))
(if (<= xhead yhead)
(recur xtail y (conj Result xhead))
(recur x ytail (conj Result yhead)))
@douglas-vaz
douglas-vaz / smallest.clj
Last active January 25, 2016 14:59
Least common sorted infinite sequences
(defn proc-seq [limit arg]
(drop-while #(< % limit) arg))
(defn all-same? [xs]
(let [f #(= % (first xs))]
(every? f xs)))
(defn solve [& args]
(loop [seqs args]
(let [firsts (map first seqs)]
@douglas-vaz
douglas-vaz / compose.scala
Created February 9, 2018 14:00
Scala compose monadic type
implicit class OptionK[A, B](f: (A) => Option[B]) {
def composed[C](g: B => Option[C]): (A) => Option[C] = (x: A) => f(x).flatMap(g)
}
val strToInt:(String) => Option[Int] = s => if(s.matches("-?[\\d]+")) Some(s.toInt) else None
val realSqrt:(Int) => Option[Double] = x => if(x > 0) Some(Math.sqrt(x)) else None
val strToSqrt = strToInt composed realSqrt
@douglas-vaz
douglas-vaz / Dockerfile.giter8
Created June 13, 2019 10:33
Dockerfile for douglasvaz/giter8:0.12.0-M1
FROM openjdk:8-alpine
RUN apk --update add curl bash
RUN export CONSCRIPT_HOME=/root/.conscript
RUN curl https://raw.githubusercontent.com/n8han/conscript/master/setup.sh -o setup.sh && chmod +x setup.sh
ENV PATH="/root/.conscript/bin:${PATH}"
RUN ./setup.sh; true