Skip to content

Instantly share code, notes, and snippets.

@ralucas
ralucas / ubuntu-sleep.yaml
Created July 29, 2021 15:46 — forked from tcdowney/ubuntu-sleep.yaml
Ubuntu Sleep Pod
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
labels:
app: ubuntu
spec:
containers:
- image: ubuntu
command:
@ralucas
ralucas / kvencoder.go
Created August 13, 2020 19:38 — forked from rhymes/kvencoder.go
key=value encoder for logging library zap (a giant hack)
// adapted from https://github.com/uber-go/zap/blob/master/zapcore/json_encoder.go
// and https://github.com/uber-go/zap/blob/master/zapcore/console_encoder.go
package logging
import (
"encoding/base64"
"encoding/json"
"math"
"sync"
"time"
# either build from source or dnf install cups
sudo systemctl enable cups.service
sudo systemctl start cups
# open up firewalld ports
sudo firewall-cmd --zone=internal --add-port=631/tcp
sudo firewall-cmd --zone=internal --add-port=192.168.0.0/16
rsync -avhW --no-compress --progress [from_dir] [to_dir]
@ralucas
ralucas / docker-cleanup-resources.md
Created August 23, 2018 20:15 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@ralucas
ralucas / switch_kubectl.bash
Created June 10, 2018 20:09
Bash script for switching kubernetes contexts
#!/bin/bash -e
APP=$1
ENV=$2
if [ -z "$APP" ] || [ -z "$ENV" ]; then
echo -e "Missing parameters\n\nUsage:\n\tswitch_kubectl [app_name] [environment]"
exit 0
fi
@ralucas
ralucas / Array.prototype.flatten
Last active February 23, 2018 22:20
Flatten on Array.prototype
// Flattens nested arrays down to one
// ex. [[1,[2,[3,4]]],5,[6],[[[7]]]] => [1,2,3,4,5,6,7]
Array.prototype.flatten = function flatten() {
return this.reduce(function(acc, item) {
if (Array.isArray(item) && item.some(Array.isArray)) {
return acc.concat(item.flatten());
}
return acc.concat(item);
}, []);
};
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation sample template that contains a single Lambda function behind an API Gateway",
"Resources": {
"GreetingLambda": {
"Type": "AWS::Lambda::Function",
"Properties": {
/**
* Searches through an array finding all
* occurences of predicates
* @param arr {array}
* @param searchVals {array}
* @return findCountData {object}
*/
function findAll (arr: any[], searchVals: any[]) {
let findCounts = searchVals.reduce((acc, val) => {
acc[val] = 0;
@ralucas
ralucas / create-jwt-using-unix-commands-on-mac.md
Created November 4, 2017 20:25 — forked from indrayam/create-jwt-using-unix-commands-on-mac.md
Create JWT Token Header Using Unix Command line tools ONLY!

Pseudocode:

Y = Base64URLEncode(Header) + ‘.’ + Base64URLEncode(Payload)
JWT = Y + ‘.’ + Base64URLEncode(HMACSHA256(Y))

The steps called out here should work on a Mac as well. The only thing that might be different is the sed command used below. Instead of using -E, you will have to use -r to run sed with extended regular expression support

Use data from this tutorial:

scotch.io