Comparing ES7 and core.async
ES7 | core.async |
---|---|
async function() {...} |
(fn [] (go ...)) |
await ... |
(<! ...) |
await* or Promise.all(...) |
(doseq [c ...] (<! c)) |
ActiveRecord cheat sheet / EXAMPLES | |
INSTALL | |
======= | |
$ gem install activerecord | |
in GEMFILE: gem ‘activerecord’ | |
REQUIRE | |
======= | |
require ‘active_record’ |
-- show running queries (pre 9.2) | |
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
FROM pg_stat_activity | |
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start desc; | |
-- show running queries (9.2) | |
SELECT pid, age(clock_timestamp(), query_start), usename, query | |
FROM pg_stat_activity | |
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
(defn rand-str [len] | |
(apply str (take len (repeatedly #(char (+ (rand 26) 65)))))) |
(defn parent-children-map | |
"Converts a vector of [child parent] edges into a map where every entry has | |
the form [parent set-of-children]. | |
Examples: | |
(parent-children-map [[0, 2], [3, 0], [1, 4], [2, 4]]) | |
;=> {4 #{1 2}, 0 #{3}, 2 #{0}} | |
(parent-children-map [[10 1] [1 4] [6 1] [8 6] [9 5] [2 4] |
(require '[clojure.core.async :as a]) | |
(def xform (comp (map inc) | |
(filter even?) | |
(dedupe) | |
(flatmap range) | |
(partition-all 3) | |
(partition-by #(< (apply + %) 7)) | |
(flatmap flatten) | |
(random-sample 1.0) |
(comment ; Fun with transducers, v2 | |
;; Still haven't found a brief + approachable overview of Clojure 1.7's new | |
;; transducers in the particular way I would have preferred myself - so here goes: | |
;;;; Definitions | |
;; Looking at the `reduce` docstring, we can define a 'reducing-fn' as: | |
(fn reducing-fn ([]) ([accumulation next-input])) -> new-accumulation | |
;; (The `[]` arity is actually optional; it's only used when calling | |
;; `reduce` w/o an init-accumulator). |
(defn tree-seq-depth | |
"Returns a lazy sequence of vectors of the nodes in a tree and their | |
depth as [node depth], via a depth-first walk. branch? must be a fn | |
of one arg that returns true if passed a node that can have | |
children (but may not). children must be a fn of one arg that | |
returns a sequence of the children. Will only be called on nodes for | |
which branch? returns true. Root is the root node of the tree." | |
[branch? children root] | |
(let [walk (fn walk [depth node] | |
(lazy-seq |
defmodule Saturn.Logger do | |
use Timex | |
require Logger | |
alias Plug.Conn | |
@behaviour Plug | |
def init(opts) do | |
Keyword.get(opts, :log, :info) | |
end |
ES7 | core.async |
---|---|
async function() {...} |
(fn [] (go ...)) |
await ... |
(<! ...) |
await* or Promise.all(...) |
(doseq [c ...] (<! c)) |
# This is just a cheat sheet: | |
# On production | |
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz | |
# On local | |
scp -C production:~/database.sql.gz | |
dropdb database && createdb database | |
gunzip < database.sql.gz | psql database |