Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
nolanlawson / index.html
Created May 14, 2014 05:50
WebSQL full-text search demo (open in Chrome or Safari)
<html>
<body>
<pre id="output"></pre>
<script src="//cdn.jsdelivr.net/jquery/2.1.1/jquery.js"></script>
<script>
var $output = $('#output');
var db = openDatabase('fts_demo', 1, 'fts_demo', 5000000);
db.transaction(function (tx){
@staltz
staltz / introrx.md
Last active May 23, 2024 20:07
The introduction to Reactive Programming you've been missing
@necrobious
necrobious / gist:14d78ee9b4caff766152
Created July 12, 2014 18:56
Ubuntu 14.04 + GHC 7.8.3 + cabal-install 1.20.0.3
# build with
# docker build -t 'necrobious/haskell-ghc-7.8-64' .
FROM ubuntu:14.04
MAINTAINER necrobious@gmail.com
ENV DEBIAN_FRONTEND noninteractive
####### Install Dependencies ###################################################
RUN apt-get -y update
@john2x
john2x / 00_destructuring.md
Last active April 23, 2024 13:18
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@KariHe
KariHe / http-loader.js
Last active December 15, 2016 13:48
Using AngularJS resource object for loader
angular.module('myApp').factory('httpLoaderInterceptor', ['$rootScope', function($rootScope) {
// Active request count
var requestCount = 0;
function startRequest(config) {
// If no request ongoing, then broadcast start event
if( !requestCount ) {
$rootScope.$broadcast('httpLoaderStart');
}
@jneen
jneen / variant-multimethods.clj
Created November 22, 2014 20:55
Multimethods with variants
; it's a bit cumbersome to set up and there's the unfortunate need to ignore the tag
; in the individual methods, but this allows you to leave the interpretation of open
; variants, well, *open* for extension by multimethod.
; dispatch off the first argument, which will be the tag
(defmethod command-multi (fn [tag & data] tag))
; the first argument to the *method* is still the tag
(defmulti command-multi :print [_ val] (println val))
(defmulti command-multi :read [_ fname] (slurp fname))
(ns variant
(:require [clojure.core.typed :as t]))
(t/defalias V
(t/Rec [V]
(t/U '[':lambda t/Sym V]
'[':if V V V]
'[':val t/Any])))
(t/ann command [V -> t/Str])
(defmacro defvariant
[name [[tag & variant-binders] & other-binders] body]
`(defmethod ~name ~tag [[_# ~@variant-binders]
~@other-binders]
~body)
[name [tag & binders] body]
`(defmethod ~name ~tag [[_# ~@binders]] ~body))
; CompilerException java.lang.RuntimeException: Unable to resolve symbol: & in this context, compiling:(/tmp/form-init8620656005427572977.clj:1:1)
@stianeikeland
stianeikeland / variant.clj
Last active August 29, 2015 14:10
variant core.typed
(ns variants-playground.core
(:require [clojure.core.typed :as t :refer [cf defalias ann U Value Str HVec HMap]]
[clojure.core.match :refer [match]]))
(defmacro Variant [& lst]
`(U ~@(for [[tag & items] lst]
`(HVec [(Value ~tag)
(HMap :mandatory ~@items)]))))
(println (macroexpand '(Variant [:foo {:bar Str}])))
@ahoy-jon
ahoy-jon / small-Y.clj
Last active April 22, 2017 05:37
Small and pluggable Y combinator in clojure.
;; ; made this macro scraching my head between the simplicity of Haskell for fix
;; ; and the absence of curryfication in Clojure.
;; (P expr-fn) ; makes expr-fn lazy
;; (P P expr-fn) ; curry one time expr-fn
;; (P P P expr-fn) ; curry two time expr-fn
;; (= ((((P P P str) "a") "b") "c") "abc") ;=> true
(defmacro P [& f]
(let [x (gensym 'x)] ;; cannot be replaced by x# due to nested macro expansion.