Skip to content

Instantly share code, notes, and snippets.

View cbrunnkvist's full-sized avatar

Conny Brunnkvist cbrunnkvist

View GitHub Profile
@cbrunnkvist
cbrunnkvist / encodeURI.sh
Last active November 12, 2019 07:24
echo $annoyingPath | encodeURI
# I actually just pasted this inline as part of a TC buildstep but hey, wanna get the Gist to color coding correctly
encodeURI() {
# for each char from stdin
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
for c in $(grep -o .)
do
case $c in
[a-zA-Z0-9.~_-/?=&]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
@cbrunnkvist
cbrunnkvist / ssh-keyscan.yml
Last active July 14, 2022 09:49
SSH keyscan all Ansible inventory
---
# in retrospect, it's better to just run e.g.
# ansible all -a true --ssh-extra-args="-o UpdateHostKeys=yes -o StrictHostKeyChecking=accept-new"
- hosts: all
gather_facts: false
tasks:
- name: Set custom SSH port fact (or use default)
delegate_to: localhost
set_fact:
@cbrunnkvist
cbrunnkvist / winkwink.sh
Last active October 1, 2018 13:23
E2E verification testing Node.js -> Scala ISOString datetime conversion
node -e 'd=new Date("2000-01-01");console.error(`Start JS: ${d}`);console.log(d)' \
| xargs scala -nc -e 'val d=java.time.OffsetDateTime.parse(args.head);System.err.println(s"In Scala: $d");println(d)' \
| xargs node -e 'd=new Date(process.argv.pop());console.error(`End JS: ${d} ;-)`);console.log(d)'
@cbrunnkvist
cbrunnkvist / scalafmt.rb
Created May 8, 2018 05:59
scalafmt brew tap
require 'formula'
class Scalafmt < Formula
head 'https://github.com/scalameta/scalafmt.git'
def install
bin.install 'scalafmt'
end
end
@cbrunnkvist
cbrunnkvist / rebuild-dock-icon-cache.sh
Created June 4, 2017 14:45
Quickfix for broken/missing icons in MacOS Dock
# sudo will probably prompt = you won't be able to just cut-n-paste into a terminal
# ... but I didn't have to spell that out for ya', right? ;-)
sudo ( find /private/var/folders/ -name com.apple.dock.iconcache -exec rm {} \;
sudo find /private/var/folders -name com.apple.iconservices -exec rm -rf {} \;
killall Dock
@cbrunnkvist
cbrunnkvist / switch-from-mail-to-outlook.sh
Last active June 2, 2017 04:59
(Command-line/Provisioning script) Change the MacOS "Default Email Reader" preference
defaults export com.apple.LaunchServices/com.apple.launchservices.secure - | sed -e s/apple.mail/microsoft.outlook/ | defaults import com.apple.LaunchServices/com.apple.launchservices.secure -
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -all local,system,user
@cbrunnkvist
cbrunnkvist / example1.sh
Last active October 31, 2019 13:04 — forked from rbraband/example 1
Howto implement stored procedures within Redis (-with enable_strict_lua)
# Step 0 -- create test data
redis-cli HSET :object:30343552:data foo bar
# Step 1 -- store sample function 'sampleFunction'
redis-cli SET :functions:sample1 "
redis.call('SELECT', 0);
local data = redis.call('HGETALL', ':object:' .. ARGV[1] .. ':data');
return table.concat(data, '+');
"
@cbrunnkvist
cbrunnkvist / .bash_profile
Last active February 13, 2024 01:40 — forked from burpnoes/.bash_profile
Bash git prompt and command completion with Xcode / Mac OS X >= Mavericks (no Homebrew required)
if [ -f /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash ]; then
. /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
fi
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
# configuration variables as documented in:
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh#L8
#
GIT_PS1_SHOWDIRTYSTATE="yes"
@cbrunnkvist
cbrunnkvist / DIY-coroutines.js
Last active January 27, 2017 10:12
Extensively commented version of the simplest possible ES6 `co`/`Bluebird.coroutine`-like implementation
function executeWithCoroutine(generatorFunction) {
function letItYield(rejectionError, resolvedValue) {
// 1st round: resolvedValue is empty at kick off (see last line in executeAsCoroutine)
// 2nd round and onwards: resolvedValue is the value we pass ourselves at promise resolution
// let the generatorObject deal with the error in case of promise rejection
if (rejectionError) {
generatorObject.throw(rejectionError)
}
@cbrunnkvist
cbrunnkvist / traits-mixins-example-class-composition.js
Last active March 22, 2017 09:52
ES6 composition: mixins / traits using anonymous subclass factories
class Fig { constructor() { console.log("I'm Ficus carica") } }
const Dateable = (SC) => class extends SC { constructor() { super(); this.creationDate = new Date() } }
const Invisible = (SC) => class extends SC { isVisible() { return false } }
class InvisibleDateableFig extends Invisible(Dateable(Fig)) {}
let f = new InvisibleDateableFig()
// > f