Skip to content

Instantly share code, notes, and snippets.

View pbaille's full-sized avatar
🏠
Working from home

Pierre Baille pbaille

🏠
Working from home
  • Freelance
  • France
View GitHub Profile
(ns markov
(use clojure.test))
;; ---------- basic markov chain utils and API ----------
(defn n-grams
"Partition seq s into all sequential groups of n items"
[n s]
(partition n 1 (repeat nil) s))
@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)))))))
@msgodf
msgodf / core.cljs
Created March 1, 2014 20:26
A Clojurescript port of the first of the Web Audio API examples from HTML5 Rocks (http://www.html5rocks.com/en/tutorials/webaudio/intro/)
(ns cljsaudio.core
(:require [goog.net.XhrIo]
[cljs.core.async :as async :refer [<! >! chan close!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn decode-audio-data
[context data]
(let [ch (chan)]
(.decodeAudioData context
data
@jasongilman
jasongilman / transparent_functions.clj
Last active January 16, 2017 22:40
Transparent Functions
;; Transparent Functions
;; I was experimenting with transducers and wanted a way to understand how they worked. Transducer
;; code uses many nested functions in various locations with other nested functions defined as local
;; variables in scope. Typically after an anonymous Clojure function is defined you have no visibility
;; into the locals that were in scope when the function was defined, where the function came from,
;; or the code in the function. I defined a macro, tfn, that creates a transparent function. It's
;; a normal Clojure function with additional metadata including the function code and local
;; variable names and values.
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@scientific-coder
scientific-coder / core.clj
Created February 2, 2015 18:00
Toy bytecode compiler for integer arithmetic DSL
(ns clojr.core
(:require [instaparse.core :as insta])
(:import (clojure.lang DynamicClassLoader)))
(import '[clojure.asm ClassWriter Type Opcodes]
'[clojure.asm.commons Method GeneratorAdapter])
(def parser
(insta/parser
"prog = expr (<#'[\\n]+'> expr?)*
@jackrusher
jackrusher / webview-for-martin.clj
Last active December 29, 2016 22:24
An example boot-ified Swing app that contains a JavaFX WebView (Webkit instance).
#!/usr/bin/env boot
;; -*- mode: Clojure;-*-
(set-env! :dependencies '[[seesaw "1.4.5"]])
(use 'seesaw.core)
(import '(javafx.scene.web WebView)
'(javafx.scene SceneBuilder)
'(javafx.scene.layout VBoxBuilder))

Code Splitting

NOTE: This gist uses the master branch of ClojureScript. Clone ClojureScript and from the checkout run ./script/bootstrap and ./script/uberjar. This will produce target/cljs.jar which you can use to follow this guide.

As client applications become larger it becomes desirable to load only the code actually required to run a particular logical screen. Previously ClojureScript :modules compiler option permitted such code splitting, but this feature only worked under :advanced compilation and users would still have to manage loading these splits. :modules also required manual

@dander
dander / Macros.md
Created February 8, 2018 21:18
JacobGood1's macros page

Macros(SPEL:-semantic-programming-enhancement-logic).md First of all, I advocate we call macros SPELs in order to get rid of the confusion when people come from other languages. This will also allow people who want to write tutorials about such a feature to easily(or more easily) google the word SPEL over macro. My recommendation of SPEL is not my own idea it comes from Conrad Barski: http://www.lisperati.com/no_macros.html

Shen, a dialect of lisp, will be what is used for spel examples. I will try to explain the syntax in order for readers of this wiki to be able to absorb the idea of spels. Come to this channel for questions, comments, approvals, disapprovals, or whatever else: https://gitter.im/red/red/lisp

We will begin(and end) by discussing two examples: max and thread.

In Shen, one defines a function at the repl like so...

@hiiamboris
hiiamboris / arity.red
Last active April 12, 2021 17:50
get arity of any word or path
arity?: func [p [word! path!] /local p2] [
either word? p [
preprocessor/func-arity? spec-of get :p
][
; path format: obj1/obj2.../func/ref1/ref2...
; have to find a point where in that path a function starts
; i.e. p2: obj1/obj2.../func
; and the call itself is: func/ref1/ref2...
p2: as path! clear [] ; reuse the same block over and over again
until [