Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
@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)))))))
@manuel
manuel / dyn-wind-commentary.scm
Created August 11, 2012 12:45
Commenting on Oleg's dyn-wind.scm
;; See http://okmij.org/ftp/continuations/implementations.html#dynamic-wind
;; and http://axisofeval.blogspot.com/2012/08/delimited-continuations-do-dynamic-wind.html
;; Slight trick here: use identity of yield-record-tag function as the actual tag
(define (yield-record-tag) yield-record-tag)
(define (make-yield-record v k)
(list yield-record-tag v k))
;; Yield simply aborts up to the generator's caller, delivering to it
;; the yielded value and the continuation for resuming after the call
@samaaron
samaaron / gist:6509442
Last active December 22, 2015 17:59
Simple Promise implementation in Ruby
require 'thread'
module SonicPi
class Promise
def initialize
@val_sem = Mutex.new
@push_sem = Mutex.new
@box = Queue.new
@value = nil
@timperrett
timperrett / gist:6224373
Created August 13, 2013 18:49
Shapeless typed element selection
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._, HList._
import shapeless._
import HList._
scala> "foo" :: 124 :: HNil
res0: shapeless.::[java.lang.String,shapeless.::[Int,shapeless.HNil]] = foo :: 124 :: HNil
@cgrand
cgrand / comprehensions.clj
Created May 24, 2013 14:06
Comprehension framework, upon which are (re)implemented, for, doseq, reducible/foldable for and reduce-based doseq
;; I wrote this in the Eurostar on my way back from the last lambdanext.eu clojure course.
(ns comprehensions
(:refer-clojure :exclude [for doseq])
(:require [clojure.core.reducers :as r]))
;; borrowed from clojure.core
(defmacro ^{:private true} assert-args
[& pairs]
`(do (when-not ~(first pairs)
;;; clips-mode.el --- Clips editing mode.
;;;************************************************************************
;;; Basado en jess-mode.el de:
;; Copyright (C) 1999 by David E. Young.
;; Modified 2012 by Fogus (http://www.fogus.me)
;; Author: David E. Young <david.young@fnc.fujitsu.com>
;; Keywords: languages, clips
anonymous
anonymous / gist:5122217
Created March 9, 2013 02:29
data StartsWithA a b = StartsWithA a (StartsWithB a b)
| EmptyA
deriving Show
data StartsWithB a b = StartsWithB b (StartsWithA a b)
| EmptyB
deriving Show
infixr 7 <<<
infixr 7 >>>
#!/usr/bin/env python
# -*-coding: utf8-*-
# Title: chessboard.py
# Author: Gribouillis
# Created: 2012-05-19 22:18:09.909216 (isoformat date)
# License: Public Domain
# Use this code freely.
version_info = (0, 1)
version = ".".join(map(str, version_info))
@mtnygard
mtnygard / query.clj
Created February 8, 2013 22:19
Use Datomic queries as a source for RxJava pipes.
(ns rxjava-datomic.query
(:require [datomic.api :as d])
(:use [clojure.repl :only [pst]])
(:import [rx Observable]
datomic.Peer))
(defn query [qry & inputs]
(Observable/toObservable
(Peer/q qry (object-array inputs))))