Skip to content

Instantly share code, notes, and snippets.

@city41
city41 / gist:aab464ae6c112acecfe1
Last active January 19, 2021 12:51
ClojureScript secretary client side navigation without hashes

This is the example that comes with the reagent template converted to use HTML5 based history. This means there are no # in the urls.

I just got this working, so there might be better approaches

The changes are

  • use goog.history.Html5history instead of goog.History
  • listen to clicks on the page, extract the path from them, and push them onto the history
  • listen to history changes, and have secretary do its thing in response
@timruffles
timruffles / dyanmic_or_di_elixir.md
Last active June 11, 2020 04:23
Approaches to dependency-injection/dynamic dispatch in elixir

In many production systems you'll want to have one module capable of talking to many potential implementations of a collaborator module (e.g a in memory cache, a redis-based cache etc). While testing it's useful to control which module the module under test is talking to.

Here are the approaches I can see. The two points that seem to divide the approaches are their tool-ability (dialyzer) and their ability to handle stateful implementations (which need a pid).

Passing modules

Modules are first class, so you can pass them in. Used in EEx, where passed module must implement a behaviour.

@simenbrekken
simenbrekken / gulpfile.js
Created March 14, 2014 08:54
React project gulpfile
var gulp = require('gulp'),
gutil = require('gulp-util')
// HTML
gulp.task('html', function() {
return gulp.src('src/index.html')
.pipe(gulp.dest('build'))
})
// Scripts
@mikeal
mikeal / gist:6137274
Last active December 20, 2015 13:18
NodeBase chat on Search
@jgarzik
jgarzik / bitcoin-packaging-challenges.md
Last active December 20, 2015 03:39
Challenges of packaging Bitcoin software

DRAFT IN PROGESS - DO NOT CIRCULATE

Technical note

The Challenges of Packaging Bitcoin Software

Introduction

Bitcoin technology is complex. Under the hood of the decentralized virtual currency lies a novel form of decentralized, distributed database. It is critical for users, system adminstrators and packaging engineers to understand bitcoin's database consistency model, which is radically different from familiar database consistency models (MySQL, Berkeley DB, Amazon Dynamo, or Google's GPS-based doohickey).

@kanwei
kanwei / removedups.clj
Created April 8, 2013 18:37
Clojure: Remove duplicates via a user-defined function
(defn remove-dups [f coll]
(vals
(reduce (fn [m v]
(let [applied (f v)]
(if-not (contains? m applied)
(assoc m applied v)
m)))
{}
coll)))
@snoyberg
snoyberg / conduit.hs
Created November 5, 2012 20:31
Monad transformer laws in pipes and conduit
import Data.Conduit
import Control.Monad.Trans.State
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
main = runPipe $ yield () >+> transPipe (flip evalStateT 0) (do
a <- lift get
lift $ put $ a + 1
b <- lift get
liftIO $ print (a, b)
@swannodette
swannodette / gist:4015208
Created November 5, 2012 03:47
intersect.js
Intersection.intersectLineLine = function(a1, a2, b1, b2) {
var result;
var ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x);
var ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x);
var u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
if ( u_b != 0 ) {
var ua = ua_t / u_b;
var ub = ub_t / u_b;
@domenic
domenic / promises.md
Last active July 17, 2025 03:03
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@lynaghk
lynaghk / 0-update.md
Last active July 5, 2022 13:33
Angular.js from ClojureScript