Skip to content

Instantly share code, notes, and snippets.

View mangosmoothie's full-sized avatar

Nathan Lloyd mangosmoothie

View GitHub Profile
@mangosmoothie
mangosmoothie / untar.clj
Created July 25, 2016 21:51
clojure untar
(ns untar
(:import (org.apache.commons.compress.archivers.tar TarArchiveInputStream)
(java.io File)
(java.io FileOutputStream)
(java.io FileInputStream)))
(defn untar-file
"untar file and save to location - preserving filenames"
[zipfile outdirpath]
(let [buffer (byte-array 1024)
@mangosmoothie
mangosmoothie / encode_base64.clj
Last active January 4, 2018 21:56
Clojure encode Base64
;; requires >= jdk 1.8
(defn encode-base64 [to-encode]
(.encodeToString (java.util.Base64/getEncoder) (.getBytes to-encode)))
@mangosmoothie
mangosmoothie / decode_base64.clj
Last active January 4, 2018 21:57
Clojure decode Base64 string
;; requires >= jdk 1.8
(defn decode-base64 [to-decode]
(String. (.decode (java.util.Base64/getDecoder) to-decode)))
@mangosmoothie
mangosmoothie / nested-map-destructuring.clj
Last active April 2, 2019 14:20
clojure nested map destructuring
;;input [:app :env config-{}]
(defn download-archive
[app env
{:keys [build-number build-name workdir]
{:keys [base-url archive-api archive-type archive-input-regex user pass]} :artifactory
{{{:keys [regex]} app} env} :deploy}]
(write-stream {:in (io/input-stream
(get-archive-response-body
{:uname user
//counts instances of words that start with EDRIVE. stripping ; or ) off the end
grep -re 'EDRIVE\.' * |sed -e 's/.* \(EDRIVE\.[^ \);]*\).*/\1/' |sort |uniq -c
@mangosmoothie
mangosmoothie / bash-log-wrapper.sh
Last active September 22, 2017 22:05
function to log & print output of bash commands while preserving exit codes
#!/bin/bash
# function to wrap a command with logging that also returns
# the status code of the command
function run() {
echo "running $@" |& tee -a out.log
eval $@ > >(tee -a out.log) 2> >(tee -a out.log)
return $?
}
@mangosmoothie
mangosmoothie / pretty git log
Created November 20, 2017 22:10
pretty git log for .*rc file
alias lg="git log --color --pretty=format:'%C(auto)%h %Cred %<(10,trunc)%an %Creset%C(auto)%s %Cgreen(%cr,%ar) %Creset%C(auto)%d'"
@mangosmoothie
mangosmoothie / kebab2camel
Created February 18, 2018 16:50
Vim - convert kebab case to camel case (whole file)
:%s/\(-\)\(\w\)/\u\2/g
:%s <- every line in file
/
\(-\) <- match group of char "-"
\(\w\) <- match group of any char
/
\u\2 <- uppercase group 2
/
g <- globally (all occurances per line)
@mangosmoothie
mangosmoothie / example.js
Last active May 28, 2022 08:37
redux-mock-store with redux-saga for testing actions / sagas
// https://github.com/arnaudbenard/redux-mock-store/issues/59#issuecomment-345741265
//------------- the saga ----------------
function* fetchSaga(action) {
try {
yield put({type: "FETCH_SUCCEEDED", data: "data"});
} catch (e) {
yield put({type: "FETCH_FAILED", message: e.message});
}
}
@mangosmoothie
mangosmoothie / OSX-environment-variables
Created February 22, 2018 17:41
OSX "global" environment variables for GUI and command-line apps
# Set environment variables here so they are available globally to all apps
# (and Terminal), including those launched via Spotlight.
#
# After editing this file run the following command from the terminal to update
# environment variables globally without needing to reboot.
# NOTE: You will still need to restart the relevant application (including
# Terminal) to pick up the changes!
# grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl
#
# See http://www.digitaledgesw.com/node/31