Skip to content

Instantly share code, notes, and snippets.

@henryw374
henryw374 / re-com.dropdown-fetching.cljs
Created November 6, 2015 11:05
minor modification to re-com.dropdown (https://github.com/Day8/re-com/blob/master/src/re_com/dropdown.cljs) to enable choices to be set from e.g. server fetch. this is a total hack... just proving the point atm
(ns re-com.dropdown-fetching
(:require-macros [re-com.core :refer [handler-fn]])
(:require [re-com.util :refer [deref-or-value position-for-id item-for-id]]
[re-com.box :refer [align-style flex-child-style]]
[re-com.validate :refer [vector-of-maps? css-style? html-attr? number-or-string?] :refer-macros [validate-args-macro]]
[clojure.string :as string]
[reagent.core :as reagent]
[re-frame.core :as re-frame]))
;; Inspiration: http://alxlit.name/bootstrap-chosen
@henryw374
henryw374 / ios-asset-generator.sh
Created March 20, 2017 15:02
ios asset generator catalog creator
#!/usr/bin/env bash
; brew install imagemagick if you haven't already
convert -resize 167x167 $ ic_launcher-19.png;
convert -resize 152x152 $ ic_launcher-18.png;
convert -resize 76x76 $ ic_launcher-17.png;
convert -resize 144x144 $ ic_launcher-16.png
convert -resize 72x72 $ ic_launcher-15.png;
convert -resize 100x100 $ ic_launcher-14.png;
; stack dump
(require '[clojure.stacktrace :as stck])
(defn jstack [n]
(let [threadMXBean (java.lang.management.ManagementFactory/getThreadMXBean)
info (.getThreadInfo threadMXBean (.getAllThreadIds threadMXBean) 100)]
(print
(for [threadInfo info]
(str
@henryw374
henryw374 / weekdays.cljc
Last active September 24, 2018 07:03
calculate weekdays between 2 dates
(ns test-tick.weekdays
(:require [tick.alpha.api :as t]))
; calculate weekdays between 2 local dates with tick
; 2 methods, one is quite readable, the other is probably more environmentally friendly
; https://www.timeanddate.com/date/workdays.html
; java.time weekday ordinals
; 1 2 3 4 5 6 7
; M T W T F S S
@henryw374
henryw374 / git.sh
Created November 16, 2018 12:12
some git aliases
alias commit='git commit -a -m '
alias glog='git log --pretty=oneline'
alias glog='git log --pretty=format:"%h%x09%an%x09%ad%x09%s"'
alias gsoft='git reset --soft HEAD~1'
alias gshowf='git show --name-only'
alias gshow='git diff-tree --no-commit-id --name-only -r '
alias gint='git rebase --interactive '
alias ginto='git rebase --interactive origin/master'
alias rgc='git rebase --continue'
alias rga='git rebase --abort'
@henryw374
henryw374 / ns-graph-data.clj
Created February 15, 2019 10:56
use ns-graph to create a function that returns all transitive dependencies of a namespace
(ns deps
"use https://github.com/alexander-yakushev/ns-graph
to create a function that returns all transitive dependencies of a namespace.
handy if you're trying to pull a ns out of a project
"
(:require [ns-graph.core :as nsg]
[clojure.java.io :as io]))
(ns transducers)
;;;;; simplified traditional impls
(defn mymap [f coll]
(reduce
(fn [acc n]
(conj acc (f n)))
[]
coll))
@henryw374
henryw374 / tidy-ns-requires.clj
Last active May 14, 2019 13:06
clojure clojurescript namespace require tidy
(ns tidy-requires)
(defn tidy-requires [[ _ & requires]]
(cons :require (sort-by first requires)))
(comment
(tidy-requires '(:require [foo]
[bar] ))
@henryw374
henryw374 / index-by.cljc
Created May 16, 2019 10:30
clojure index-by
(ns corr.core
(:require [medley.core :as m]))
(defn index-by [f coll]
(->> coll
(group-by f)
(m/map-vals (fn [xs]
(assert (= 1 (count (take 2 xs))))
(first xs)))))
@henryw374
henryw374 / clojure-jstack.clj
Last active February 28, 2020 15:15
thread dump clojure programmatic jstack
(ns thread-dump
(:require [clojure.stacktrace :as st])
(:import [java.lang.management ManagementFactory]))
(defn jstack [n]
(let [threadMXBean (ManagementFactory/getThreadMXBean)
info (.getThreadInfo threadMXBean (.getAllThreadIds threadMXBean) 100)]
(print
(for [threadInfo info]
(str