Skip to content

Instantly share code, notes, and snippets.

@favila
favila / tx-pipeline-inorder.clj
Created April 4, 2017 00:17
Transact transactions in core.async channel `from-ch` against datomic connection `conn` with a pipeline depth of `n`.
(defn tx-pipeline-inorder
"Transact transactions in core.async channel `from-ch` against datomic connection `conn` with a pipeline depth of `n`.
Returns a map with keys `:stop!` and `:result`. `:stop!` is a no-arg function you can call to immediately
cease sending transactions (already sent transactions cannot be stopped). `:result` is a promise channel
returning a variant of the result of the tx-pipelining after from-ch is closed and drained, or
:stop! is called and all send transaction futures are deref-ed, or a transaction produces an exception.
The variant returned from the :result channel may be one of:
(defmacro afor
"Like for but eagerly builds a JS array.
Usually for react consumption."
[[item coll] & body]
`(reduce (fn [neue# ~item]
(.push neue# (do ~@body))
neue#)
(cljs.core/array) ~coll))
(defmacro arfor
@ryu1kn
ryu1kn / Makefile
Last active March 19, 2023 13:02
Encrypt/decrypt with AWS KMS using AWS cli
# How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli
KEY_ID=alias/my-key
SECRET_BLOB_PATH=fileb://my-secret-blob
SECRET_TEXT="my secret text"
ENCRYPTED_SECRET_AS_BLOB=encrypted_secret_blob
DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target
encrypt-text:
@favila
favila / entity-pull.clj
Created February 8, 2017 18:19
entity-pull: a datomic.api/pull that returns values the way datomic.api/entity would, with sets and ident keywords
(require '[datomic.api :as d])
(defn entity-pull
"Like pull, but returns values consistent with d/entity, i.e.,
entities with :db/ident are represented as keywords and sets are
used instead of vectors."
[db pat eid]
(->> (d/pull db pat eid)
(clojure.walk/prewalk
(fn [x]
@aengelberg
aengelberg / core.clj
Created February 3, 2017 16:53
Manifold examples
(ns hello-manifold.core
(:require
[aleph.http :as http]
[byte-streams :as bs]
[cheshire.core :as json]
[clojure.string :as str]
[manifold.deferred :as d]
[manifold.executor :as e]
[manifold.stream :as s]))
@scottopell
scottopell / fix_exfat_drive.md
Last active May 18, 2025 18:52
Fix corrupted exFAT disk macOS/OSX

exFAT support on macOS seems to have some bugs because my external drives with exFAT formatting will randomly get corrupted.

If Disk Utility is unable to repair, consider trying this:

  1. In Disk Utility, ensure that the drive is not mounted, eject it if it is mounted.
  2. Use diskutil list to find the right drive id.
  3. You want the id under the IDENTIFIER column, it should look like disk1s1
  4. Run sudo fsck_exfat -d <id from above>. eg sudo fsck_exfat -d disk1s3
  5. -d is debug so you'll see all your files output as they're processed.
(defmacro datomic-fn
"Creates a datomic function given (fn [db e a ...] code...)"
[[_ args & body]]
`(d/function '{:lang "clojure"
:params ~args
:code (do ~@body)}))
(defn trinity-new
"1. If a is a ref:
Ensures that
@davidowens
davidowens / build-momentjs-data.js
Last active July 26, 2016 13:50
Repack Moment.js data, limited to a subset of zones
import gulp from 'gulp';
import moment from 'moment-timezone/moment-timezone';
import 'moment-timezone/moment-timezone-utils';
import fs from 'fs';
import config from '../../config';
const inputFile = 'node_modules/moment-timezone/data/unpacked/latest.json';
const outputFile = 'app/lib/moment-timezone-data.json';
const start = 2014;
const end = moment().add(5, 'years').year();
@gbaman
gbaman / HowToOTGFast.md
Last active April 30, 2025 02:59
Simple guide for setting up OTG modes on the Raspberry Pi Zero, the fast way!

Setting up Pi Zero OTG - The quick way (No USB keyboard, mouse, HDMI monitor needed)

More details - http://blog.gbaman.info/?p=791

For this method, alongside your Pi Zero, MicroUSB cable and MicroSD card, only an additional computer is required, which can be running Windows (with Bonjour, iTunes or Quicktime installed), Mac OS or Linux (with Avahi Daemon installed, for example Ubuntu has it built in).
1. Flash Raspbian Jessie full or Raspbian Jessie Lite onto the SD card.
2. Once Raspbian is flashed, open up the boot partition (in Windows Explorer, Finder etc) and add to the bottom of the config.txt file dtoverlay=dwc2 on a new line, then save the file.
3. If using a recent release of Jessie (Dec 2016 onwards), then create a new file simply called ssh in the SD card as well. By default SSH i

@favila
favila / datomic-reset-attributes.clj
Last active January 12, 2025 14:04
Datomic transaction functions to "reset" attributes: i.e. make them have a post-transaction value you specify without having to enumerate the retractions.
(def tx-fns
[{:db/ident :db.fn/reset-attribute-values
:db/doc "Transaction function which accepts an entity identifier, attribute identifier
and set of values and expands to any additions and retractions necessary to
make the final post-transaction value of the attribute match the provided
values. Attribute values must be scalars.
If multiple values are provided on a cardinality-one attribute you will get a
datom conflict exception at transaction time."
:db/fn (d/function