Skip to content

Instantly share code, notes, and snippets.

View smrchy's full-sized avatar

Patrick Liess smrchy

View GitHub Profile
@smrchy
smrchy / app.js
Created February 11, 2020 14:34 — forked from tj/app.js
const http = require('http')
const rpc = require('./rpc')
/**
* Pets service.
*/
class Pets {
constructor(db = []) {
@smrchy
smrchy / base36_decode.sql
Created October 11, 2017 19:38
PostgreSQL base36 time functions
-- FUNCTION: public.base36_decode(character varying)
-- DROP FUNCTION public.base36_decode(character varying);
CREATE OR REPLACE FUNCTION public.base36_decode(
base36 character varying)
RETURNS bigint
LANGUAGE 'plpgsql'
COST 100
@smrchy
smrchy / AWS.cfc
Created July 25, 2016 13:22
Coldfusion AWS helper functions
<!---
Parts of this are based on Tim Dawe's
http://amazonsig.riaforge.org
and
Joe Danziger's Amazon S3 REST Wrapper
http://amazons3.riaforge.org/
Written by Patrick Liess
#host running out of memory!
ALERT HighMem
IF 100 -(node_memory_MemFree + node_memory_Buffers + node_memory_Cached) / node_memory_MemTotal* 100 > 80
FOR 1m
WITH {
severity="page"
}
SUMMARY "Instance {{$labels.host}} has high memory consumption"
DESCRIPTION "{{$labels.host}} of job {{$labels.job}} has less than 40% of memory available for more than 1 minutes."

Intersection / Difference / Union Hints

Which elements are new in new_array compared to old_array

old_array = [1, 4, 5]
new_array = [1, 2, 3, 4]

_.difference(new_array, old_array)
@smrchy
smrchy / helpers.sh
Created February 10, 2016 13:31 — forked from mpneuried/cron.sh
bash helpers
# SYSTEM: open a file as admin with a special app
sudo open -a /Applications/Utilities/Console.app/ /usr/local/mysql/data/Mathiass-iMac.log
# SYSTEM: Create a symbolic link
ln -s /Path/to/original/folder New-folder-name
# SYSTEM: show long running clock
clear; while true; do echo -e \\b\\b\\b\\b\\b\\b\\b\\b`date +%T`\\c ; sleep 1; done
# SYSTEM: Set ENV var
@smrchy
smrchy / nginx-openresty-ubuntu-build-dependencies.sh
Last active September 24, 2015 12:35 — forked from markselby/nginx-openresty-ubuntu-build-dependencies.sh
Build Nginx OpenResty version on Ubuntu.This is part of the high performance caching blog on writebox.co.uk
# Build dependencies for OpenResty.
sudo apt-get install build-essential libpcre3-dev libssl-dev libgeoip-dev
# Install standard Nginx first so that you get the relevant service scripts installed too
sudo apt-get install nginx
# If you want to access Postgres via Nginx
sudo apt-get install libpq-dev

Remove unused Docker containers and images

This removes all containers that are not running:

docker ps -q -a | xargs docker rm

Remove images:

docker rmi $(docker images -q -f "dangling=true")

@smrchy
smrchy / gist:3b76bd53c6a4bb7266b7
Last active August 29, 2015 14:24
Install Docker on 14.04
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo sh -c "echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install -y lxc-docker
docker -v
@smrchy
smrchy / dockermemory.sh
Created June 18, 2015 11:46
Memory usage of all docker containers
for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do docker ps | grep $line | awk '{printf $NF" "}' && echo $(( `cat /sys/fs/cgroup/memory/docker/$line*/memory.usage_in_bytes` / 1024 / 1024 ))MB ; done