Skip to content

Instantly share code, notes, and snippets.

levelsio / btc-eth-dca-buy.php
Last active Jun 22, 2020
This script runs daily and "Dollar Cost Average"-buys $40 BTC and $10 ETH per day
View btc-eth-dca-buy.php
// by @levelsio
// 2017-08-23
// 1) buy $40/day BTC
// 2) buy $10/day ETH
View build.boot
(require '[ :as io])
(deftask demo []
(let [tmp (tmp-dir!) ; Anonymous, boot-managed temp directory.
prev-fs (atom nil)] ; Atom where the previous fileset is stored.
(with-pre-wrap [fs]
(let [diff (fileset-diff @prev-fs (reset! prev-fs fs)) ; Fileset containing only changed files.
inputs (->> (input-files diff) ; Sequence of [String,]
(by-ext [".c"]) ; pairs, the classpath path and File
(map (juxt tmp-path tmp-file)))] ; for files with given extensions.
swannodette /
Last active Nov 28, 2019
Externs Inference

Externs Inference

Integrating third party JavaScript libraries not written with Google Closure Compiler in mind continues to both be a source of error for users when going to production, and significant vigilance and effort for the the broader community (CLJSJS libraries must provide up-to-date and accurate externs).

In truth writing externs is far simpler than most users imagine. You only need externs for the parts of the library you actually intend to use from ClojureScript. However this isn't so easy to determine from Closure's own documentation. Still in the process of writing your code it's easy to miss a case. In production you will see the much dreaded error that some mangled name does not exist. Fortunately it's possible to enable some compiler flags :pretty-print true :pseudo-names true to generate an advanced build with human readable names. However debugging missing externs means compiling your production build for each missed case. So much time wasted for such simple mistakes damages our sen

attentive / leaflet.cljs
Last active Sep 16, 2017
Adapting React components in Rum
View leaflet.cljs
(ns project.leaflet
(:require-macros [project.macros :as m])
(:require [rum.core :as rum]
cljsjs.react-leaflet)) ;; js/ReactLeaflet
(m/adapt-react leaflet-map js/ReactLeaflet.Map)
(m/adapt-react tile-layer js/ReactLeaflet.TileLayer)
(m/adapt-react marker js/ReactLeaflet.Marker)
(m/adapt-react popup js/ReactLeaflet.Popup)
ohpauleez / interceptor.clj
Last active Jun 19, 2018
An example of how to make conditional interceptors that enqueue new interceptors
View interceptor.clj
;; Let's start with a simple conditional interceptor that works with functions...
(defn conditional-context
"Given a keyword name and any variable predicate and terminator function pairs,
return an interceptor that will apply the terminator function paired to the first
truthy predicate. Predicates and terminators are both given the context as
the only argument.
If all predicates fail, the original context is returned."
[name-kw & pred-terms]
mhuebert /
Last active Sep 9, 2020
Using existing namespaces from cljs.js

Let's say you want to use cljs.js to eval code using functions declared in your project.

Expressions that only use core functions are simple to evaluate:

(ns foo.try-eval
  (:require [cljs.js :as cljs]))

(def compiler-state (cljs/empty-state))
noprompt / complies.clj
Created Mar 16, 2015
complies? macro for ClojureScript. Verifies than an object not only satisfies a protocol but implements all of it.
View complies.clj
(ns example.macros
[cljs.analyzer :as a]
[cljs.compiler :as c]))
(defmacro complies?
"True if x satisfies and implements all methods of a protocol.
mrb /
Last active Oct 4, 2020
"Programs that eat programs" Works cited/bibliography
jpthomson / gist:d7c36805ebe24d07428f
Created Feb 3, 2015
Run CLJX code after (cljx)
View gist:d7c36805ebe24d07428f
(deftask start []
(let [f (delay (do
(require 'fy.core) ;; cljx file
((resolve 'fy.core/start-system!))))]
(with-post-wrap fileset @f fileset)))
Deraen / angular-filesize.js
Last active Jul 5, 2017 — forked from thomseddon/gist:3511330
Humanize filesize
View angular-filesize.js
app.filter('bytes', function() {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'];
var number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
You can’t perform that action at this time.