Skip to content

Instantly share code, notes, and snippets.

@pleasetrythisathome
pleasetrythisathome / nashorn.clj
Last active August 29, 2015 14:10
nashorn cljs rendering
(ns starlab.services.nashorn
(:require [clojure.tools.logging :as log]
[clojure.java.io :as io])
(:import [javax.script
Invocable
ScriptEngineManager])
(:use [plumbing.core :exclude [update]]))
(defn nashorn-env []
(doto (.getEngineByName (ScriptEngineManager.) "nashorn")
(page "index.html"
(:require
[tailrecursion.hoplon.reload :refer [reload-all]]))
(reload-all 0)
(defn random-minefield [size n]
(loop [mines #{}]
(if (< (count mines) n)
(recur (conj mines [(rand-int size) (rand-int size)]))
@jpthomson
jpthomson / gist:d7c36805ebe24d07428f
Created February 3, 2015 14:35
Run CLJX code after (cljx)
(deftask start []
(let [f (delay (do
(require 'fy.core) ;; cljx file
((resolve 'fy.core/start-system!))))]
(with-post-wrap fileset @f fileset)))
@noprompt
noprompt / complies.clj
Created March 16, 2015 04:13
complies? macro for ClojureScript. Verifies than an object not only satisfies a protocol but implements all of it.
(ns example.macros
(:require
[cljs.analyzer :as a]
[cljs.compiler :as c]))
(defmacro complies?
"True if x satisfies and implements all methods of a protocol.
Ex.
@jackrusher
jackrusher / OO.md
Created July 29, 2013 12:53
Gist blogging? Yet another exposition on the nature of OO programming.

Object-orientation

There are many articles and discussion threads on the web regarding the nature of Object-oriented (OO) programming. Most of them come at the question from a Programming Language Theory (PLT) perspective, attempting to assert a formal definition of OO programming and objects. I'm not going to do that here. Instead, I'm going to write about objects from an implementation perspective, approaching the subject first from below and then from above.

@marshallbrekka
marshallbrekka / cf-template.clj
Created November 28, 2013 01:54
CloudFormation Template Generation
(defn keys->strings
"Given a map converts all keys that are keywords from dash-separated to
camel-case using key->string."
[m]
(let [f (fn [[k v]] [(key->string k) v])
walk-fn (fn [x]
(if (map? x)
(->> (map f x)
(into {}))
x))]
@kgabis
kgabis / dropboxpro.md
Last active May 18, 2016 22:03
Weird pricing of Dropbox Pro

Last week Dropbox introduced Dropbox Pro with 1TB storage space (and some other cool features) for $99/year (or $9,99/month), which is a pretty good deal (Google Drive 1TB also costs $99,99/year). The problem: it's not $99/year, but $130/year (or $13/month) if you happen to live in Europe. Instead of converting prices from dollars to euros, they just changed $ to €.

pricing

But that's not the best part. You can buy it cheaper if you use Dropbox app on iOS.

pricing on iOS

Now it's only $118/year or $10/month, which is much cheaper than through their website (and they still have to give 30% of that to apple!). I guess we should thank apple for not allowing different pricing in different regions. So if you plan to upgrade to Dropbox Pro, do it through their mobile app.

(ns racehub.om.facebook
(:require [cljs.core.async :as a]
[racehub.schema :as rs]
[schema.core :as s :include-macros true]))
;; ## Utilities
(defn prune
"Takes a mapping of keys -> new key names and a map and returns a
map with nils removed and keys swapped where they're present in the
@micha
micha / build.boot
Last active January 6, 2017 13:05
(require '[clojure.java.io :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, java.io.File]
(by-ext [".c"]) ; pairs, the classpath path and File
(map (juxt tmp-path tmp-file)))] ; for files with given extensions.
@Deraen
Deraen / angular-filesize.js
Last active July 5, 2017 15:14 — forked from thomseddon/gist:3511330
Humanize filesize
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];
};
});