Skip to content

Instantly share code, notes, and snippets.

View mraxus's full-sized avatar

Marcus Bergman mraxus

View GitHub Profile
@mraxus
mraxus / s3-upload-with-md5.js
Last active February 16, 2022 11:48
Upload file to s3 with MD5 hash-check
const crypt = require('crypto');
const fs = require('fs').promises;
const aws = require('aws-sdk');
async function uploadFileToS3WithMd5Hash(bucket, filename, s3Key = null) {
const data = await fs.readFile(filename);
const md5Base64 = crypt.createHash("md5").update(data).digest('base64');
if (!s3Key) {
@mraxus
mraxus / scroll.py
Last active March 22, 2017 22:22
Py-script for reading a file and displaying the text with the Raspberry scroll pHAT
#!/usr/bin/env python
### http://docs.pimoroni.com/scrollphat
from collections import namedtuple
import json
import os
import sys
import time
@mraxus
mraxus / Rakefile
Last active December 15, 2016 15:37
Generalized commands to initialize docker-compose/wait for db
def postgres_url()
postgres_str = `docker-compose port postgres 5432`.strip
return "postgres://postgres:postgres@#{postgres_str}/postgres"
end
desc "Run initial setups needed to get service running locally (also runs all setup_x tasks)"
task :setup => [:start_doc, :setup_db]
desc "Start docker-compose in background"
task :start_doc do
@mraxus
mraxus / durl.sh
Last active October 10, 2016 09:22
Bash script to translate docker-compose service name with hostname:port
#!/bin/bash
########## C O N F I G ##########
DOCKER_HOST_NAME=localhost
#################################
cmd="curl $@"
service_name=`echo $cmd | sed -n 's/.* \([a-zA-Z0-9_][a-zA-Z0-9_]*\)\/.*/\1/p'`
row=`docker-compose ps |grep _${service_name}_1`
@mraxus
mraxus / JQuery1.whenAll.js
Created August 25, 2015 23:51
Extend JQuery 1.x with whenAll that handles async call functions in objects or arrays. Returns a deferred that resolves in the same structure.
$.whenAll = function (deferreds) {
function isPromise(fn) {
return fn && typeof fn.then === 'function' &&
String($.Deferred().then) === String(fn.then);
}
var d = $.Deferred(),
keys = Object.keys(deferreds),
args = keys.map(function (k) {
return $.Deferred(function (d) {
var fn = deferreds[k];
@mraxus
mraxus / install.sh
Last active August 29, 2015 14:03 — forked from bradrydzewski/install.sh
#!/bin/bash
# remove existing 9.1 installation
sudo /etc/init.d/postgresql stop
sudo apt-get --force-yes -fuy remove --purge postgresql postgresql-9.1 postgresql-client
# install zip
sudo apt-get install -y zip
# install 9.3
apt-get update
apt-get -y upgrade
apt-get -y install vim
# edit /etc/vim/vimrc to enable syntax, dark mode etc...
# edit ~/.bashrc for added aliases...
alias lh='ls -lh'
alias lah='ls -lAh'
=== TEST SETUPS ===
t.plan(x) // Expect x asserts. If less, test will timeout, if more, test fails
t.end() // End test if not t.plan() is used
t.fail('fail test with this description')
t.bailout("en test right here. No more to run")
// t.bailsOut() wraps a child test and succeeds if it calls bailout()
t.bailsOut(t.test("this should bailout", function (t) {
t.bailout("oh noes, bailing out!")
}))
@mraxus
mraxus / .gitconfig
Last active May 7, 2017 19:54
Default .gitconfig
[alias]
a = !git add . && git status
amend = commit --amend -C HEAD
ap = !git add -p && git status
au = !git add -u && git status
b = branch
ba = branch --all
bi = for-each-ref --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset)) - %(color:magenta dim)%(contents:subject)%(color:reset)'
c = commit
ch = checkout