Skip to content

Instantly share code, notes, and snippets.

View mangosmoothie's full-sized avatar

Nathan Lloyd mangosmoothie

View GitHub Profile
@mangosmoothie
mangosmoothie / s3.ts
Created November 30, 2022 06:07
TypeScript / Node utilize credential_process in for AWS profile to access S3
import * as https from 'https';
import * as AWS from 'aws-sdk';
import { execFileSync } from 'child_process';
import * as process from 'process';
const REGION = process.env.AWS_REGION || 'us-east-1';
const { CREDENTIALS_PROCESS } = process.env;
export const createDefaultConfiguration = async (): Promise<AWS.S3.ClientConfiguration> => {
const config = {
@mangosmoothie
mangosmoothie / clojure_rsa_crypto.clj
Last active May 6, 2020 19:15
crypto with clojure using RSA asymmetric keys
;; https://blog.jonm.dev/posts/rsa-public-key-cryptography-in-java/
;; generate a 2048-bit RSA private key
;; $ openssl genrsa -out private_key.pem 2048
;; # convert private Key to PKCS#8 format (so Java can read it)
;; $ openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem \
;; -out private_key.der -nocrypt
;; # output public key portion in DER format (so Java can read it)
;; $ openssl rsa -in private_key.pem -pubout -outform DER -out public_key.der
@mangosmoothie
mangosmoothie / sha1.clj
Created July 17, 2019 22:51
sha-1 hash clojure
(:import java.nio.charset.Charset
java.security.MessageDigest
javax.xml.bind.DatatypeConverter)
(defn get-sha [s]
(DatatypeConverter/printHexBinary
(.digest (MessageDigest/getInstance "SHA-1") (.getBytes s "UTF-8"))))
@mangosmoothie
mangosmoothie / gzip.clj
Last active July 17, 2019 21:44
clojure gzip compress-decompress
(:import java.io.ByteArrayInputStream
java.io.ByteArrayOutputStream
java.io.OutputStream
java.util.zip.GZIPInputStream
java.util.zip.GZIPOutputStream
java.nio.charset.Charset)
(defn compress ^bytes [^String s]
(.toByteArray
(with-open [*output (ByteArrayOutputStream.)
@mangosmoothie
mangosmoothie / tornado_async_locks.py
Created April 26, 2019 05:51
Tornado Coroutines with Locks
import tornado.web
from tornado import gen
from tornado.locks import Lock
class Service():
def __init__(self, service_id, nth=None):
self._nth = nth
self._service_id = service_id
self._count = 0
@mangosmoothie
mangosmoothie / clojure_xml_remove_nils.clj
Last active April 2, 2019 19:45
remove keys with nil value from clojure.xml parsed xml file
;; remove keys with nil value from a data structure created by parsing an xml file with clojure.xml
;; to do this you first must convert the clojure.xml elements to regular maps since they are created
;; as structs and thus will not allow you to remove keys
(require '[com.rpl.specter :as r] '[clojure.xml :as xml])
(def ALL-ELEMENTS
(r/recursive-path
[] p
(r/if-path :content
# never use pull https://www.reddit.com/r/programming/comments/6nzgje/psa_use_git_config_global_bool_pullrebase_true_to/
git fetch
git log ..@{u} # show me the new goodies
# @{u} is git-speak for "the upstream branch I'm currently tracking"
# Let's take it
git rebase
# alternatively
@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
@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 / 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)