Skip to content

Instantly share code, notes, and snippets.

@PieterScheffers
PieterScheffers / find_processes_with_file_descriptors.sh
Created November 15, 2021 15:46
Find processes with a minimum number of file descriptors
minimum=30
for pid in /proc/[0-9]*; do number_fds=$(ls $pid/fd | wc -l); if [ $number_fds -ge $minimum ]; then printf "PID %6d has %4d FDs\n" $(basename $pid) $(ls $pid/fd | wc -l); ps aux | grep $(echo $pid | cut -d/ -f3) | grep -v grep; fi; done
@PieterScheffers
PieterScheffers / npm-get-lock-version.sh
Created March 24, 2021 16:41
Get package-lock.json version for devDependencies
for package in $(jq -r '.devDependencies | keys | .[]' package.json); do version=$(jq -r --arg pkg $package '.dependencies[$pkg].version' package-lock.json); echo "$package: $version"; done
@PieterScheffers
PieterScheffers / kubeshell
Created July 28, 2020 12:36
Get a shell to a Kubernetes node with root capabilities
#!/bin/sh
# https://alexei-led.github.io/post/k8s_node_shell/
if [ -z "${1}" ]; then
echo "ERROR No kubernetes node supplied.
Script needs a node name as first argument!
Find node names with:
$ kubectl get node
@PieterScheffers
PieterScheffers / entries.ts
Created March 26, 2020 15:43
object.entries typescript
type Entry<T> = [ keyof T, T[keyof T] ]
type Entries<T> = Entry<T>[]
type Key<T> = (keyof T)
type Keys<T> = Key<T>[]
type Value<T> = T[keyof T]
type Values<T> = Value<T>[]
type HasKeys<T> = { [key in keyof T]: any }
const keys = <T>(obj: T): Keys<T> => Object.keys(obj) as Keys<T>
const toEntries = <T>(obj: T): Entries<T> => Object.entries(obj) as Entries<T>
@PieterScheffers
PieterScheffers / CheckboxButton.js
Created December 5, 2019 16:50
react checkbox
import React from 'react';
import PropTypes from 'prop-types';
const style = {
label: {
display: 'inline',
fontFamily: 'RobotoCondensed-Regular, sans-serif',
userSelect: 'none', // disable text selection
fontWeight: 'bold'
},
@PieterScheffers
PieterScheffers / makefile_windows.txt
Created July 25, 2019 09:44
Makefile Windows link
https://www.oreilly.com/library/view/managing-projects-with/0596006101/ch07.html
@PieterScheffers
PieterScheffers / transip_stack_clear_trash.sh
Last active August 28, 2020 23:03
TransIP Stack - Clear Trash
#!/bin/sh
STACK_URL=myuser.stackstorage.com
STACK_USER=myuser
STACK_PASSWORD=nooneknowsthis
curl \
--silent \
-X POST \
-H "Content-Type: application/json" \
@PieterScheffers
PieterScheffers / trello_add_week.js
Created March 19, 2019 10:14
Trello add a list for each weekday
// Trello
// Add a List for each weekday
// Pass throught https://skalman.github.io/UglifyJS-online/
// Then add 'javascript:' before the code
// and add 'void(0);' after the code
// Add a bookmark in Chrome and put this as the url
(function () {
function getLastDate (lastDate = null) {
@PieterScheffers
PieterScheffers / .bashrc
Last active July 6, 2020 15:42
Download new kubeconfig when it is older as 6 days for DigitalOcean kubernetes
#!/usr/bin/env bash
# DigitalOcean Kubernetes
# The kubeconfig you download from DigitalOcean invalidates every 7 days
# By appending this to your .bashrc file the kubeconfig gets refreshed every 6 days
#
# Pre
# - install 'doctl': https://github.com/digitalocean/doctl#installing-doctl
# - auth with DigitalOcean API token: https://github.com/digitalocean/doctl#authenticating-with-digitalocean
#
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {