Skip to content

Instantly share code, notes, and snippets.

@qwtel
qwtel / connectContext.js
Last active September 17, 2015 16:34
Enhanced version of redux' connect, that puts all action creators into the child context of the component.
import {PropTypes} from 'react';
import {connect} from 'react-redux';
/**
* Enhanced version of redux' connect, that puts all action creators
* into the child context of the component.
*
* @param mapStateToProps {Function}
* @param mapDispatchToProps {Function} Must be free of side effects!
* @returns {Function}
@qwtel
qwtel / clojure.js
Last active September 29, 2015 09:46
If JavaScript was written like Clojure...
function cost(state) {
return mul(
b,
Math.log(
reduce(
add,
map(
function(x) {return Math.pow(Math.E, div(x, b))},
vals(x)))))}
@qwtel
qwtel / separator.cljc
Last active December 7, 2015 11:54
Valid Clojure
(defn <> [] <>)
(((((((((((((((((((((((((((((((((((((((<>)))))))))))))))))))))))))))))))))))))))
@qwtel
qwtel / ethpyramid.sol
Created January 30, 2016 16:31
ETH Pyramid Contract
contract Pyramid {
struct Participant {
bytes desc;
address etherAddress;
bytes bitcoinAddress;
}
Participant[] public participants;
uint public payoutIdx = 0;
@qwtel
qwtel / goog.clj
Last active February 7, 2016 17:03
find words in an input, lower-case only, brute force
(ns goog
(:require [clojure.string :as str]))
(def words-by-count (->> (slurp "/usr/share/dict/words" :encoding "ASCII")
str/split-lines
(map str/lower-case)
distinct
(map seq)
(group-by count)))
@qwtel
qwtel / cda.clj
Last active March 2, 2016 12:09
A Simple CDA Implementation in Clojure http://qwtel.com/a-simple-cda-implementation-in-clojure
(ns interact.cda
(:require [clojure.test :refer :all]))
(defn insert-by [f c e]
(let [[lt gt] (split-with #(f % e) c)]
(concat lt [e] gt)))
(def insert (partial insert-by <))
(testing "insert"
@qwtel
qwtel / project.clj
Last active July 4, 2016 13:24
Very basic ClojureScript Leiningen configuration: https://www.youtube.com/watch?v=eWGFYRyWT0Y
(defproject hello-world "0.0.0"
;; lein obviously does dependency management
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.92"]]
;; and uses plugins for non-standard tasks
:plugins [[lein-cljsbuild "1.1.3"]
[lein-figwheel "0.5.4-4"]]
;; this will build cljs on `lein compile`
@qwtel
qwtel / project.clj
Created July 4, 2016 17:38
Very basic ClojureScript Leiningen setup with cljs-devtools
(defproject hello-world "0.0.0"
;; lein obviously does dependency management
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.92"]]
;; and uses plugins for non-standard tasks
:plugins [[lein-cljsbuild "1.1.3"]
[lein-figwheel "0.5.4-4"]]
;; this will build cljs on `lein compile`
@qwtel
qwtel / example.md
Last active August 26, 2016 08:29
Ring REST JSON and namespaced clojure.spec

Handy for a ring REST server that is spec'd via the upcomming clojure.spec library in Clojure 1.9, since it encourages the use of namespaced keywords.

A request like

POST /endpoint Content-Type: application/json {"name": "Test", "id": -1}

will be parsed as

{:my.spec/name "Test"
Atom Sync Settings Backup