Skip to content

Instantly share code, notes, and snippets.

@PieterScheffers
PieterScheffers / mysql_insert_with_subselect.sql
Created July 12, 2016 15:25
MySQL insert with subselect to insert a incrementing value
# http://stackoverflow.com/questions/10644149/insert-into-with-subquery-mysql
# Use a SELECT instead of VALUES
# Then give static values an alias
# Add a new row
# value for position should be the highest position in group + 1
INSERT INTO some_table (group_id, name, position)
SELECT
2 as group_id,
'bert' as name ,
@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 / vncserver.patch
Created February 5, 2017 16:21
Patch for vncserver on FreeBSD to use it in a jail (Source: http://www.bsdnow.tv/patches/vncserver.patch)
--- vncserver 2013-10-09 16:10:25.000000000 +0000
+++ vncserver.new 2013-10-09 16:12:45.000000000 +0000
@@ -296,7 +296,7 @@ sub CheckDisplayNumber
socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n";
eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))';
- unless (bind(S, pack('S n x12', $AF_INET, 6000 + $n))) {
+ unless (bind(S, sockaddr_in(6000 + $n, &INADDR_ANY))) {
close(S);
return 0;
@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 / 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 / .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
#
@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 / docker-raspberry-pi.sh
Created May 30, 2017 12:49
Build ARM docker images for Raspberry Pi with QEMU
# https://blog.hypriot.com/post/setup-simple-ci-pipeline-for-arm-images/
### Choose a base image with QEMU binary
# FROM hypriot/rpi-alpine
# FROM resin/rpi-raspbian
# FROM resin/raspberry-pi-alpine-node:slim
### Register QEMU in the build agent
docker run --rm --privileged multiarch/qemu-user-static:register --reset