Skip to content

Instantly share code, notes, and snippets.

/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
@nhtzr
nhtzr / askpass
Created March 20, 2020 01:01
askpass for osx
#!/usr/bin/env sh
osascript -e "
on GetCurrentApp()
tell application \"System Events\"
set _app to item 1 of (every process whose frontmost is true)
return name of _app
end tell
end GetCurrentApp
set _app to GetCurrentApp()
tell application _app
@nhtzr
nhtzr / make-passwd
Last active February 16, 2020 02:10
#!/bin/sh
declare SALT # One time pad
if [ "${1+x}" = x ]; then
SALT="$1"
else
# 64byte = 512bit
SALT="$(head -c64 /dev/random)"
fi
@nhtzr
nhtzr / config
Last active June 2, 2022 03:49
my .ssh/config
Host */*
ProxyCommand ssh %r@$(dirname %h) -W $(basename %h):%p
Host *_*
ProxyCommand ssh %r@$(cut -f1 -d_ <<< '%h') -W $(: '%h'; echo "${_##*_}"):%p
# SSH over Session Manager
Host aws-ssm-*
ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
#!/usr/bin/env bash
# Not actually executable, but a reminder for myself
# see https://lunaticgeek.com/whatsapp-stickers/
# see https://gist.github.com/patrickhammond/4ddbe49a67e5eb1b9c03#gistcomment-2903816
TMP="$(mktemp -d)"
wget https://dl.stickershop.line.naver.jp/products/0/0/1/3962468/iphone/stickers@2x.zip --no-check-certificate
# unzip, folder is stickers@2x
cd 'stickers@2x'
my-df() {
df -h |
awk '$NF != "/" && NR > 1 {print $NF}' |
xargs -I{} echo --exclude {} |
sudo xargs du / -h \
--exclude /sys \
--exclude /proc |
tee du.out |
sort -h |
less
#!/bin/bash
cat <<EOF > /etc/cni/net.d/100-crio-flannel.conf
{
"cniVersion": "0.3.0",
"name": "mynet",
"type": "flannel"
}
EOF
cat <<EOF > /etc/cni/net.d/200-loopback.conf
@nhtzr
nhtzr / getenv
Created October 23, 2019 03:41
getenv with default in bash
#!/usr/bin/env bash
set -euo pipefail
key="${1:?Env var is required as first parameter}"
default=${2:-}
value="${!key:-$default}"
: "${value:?Env var $key not found}"
printf "%s" "${value}"
@nhtzr
nhtzr / init.ps
Last active September 30, 2019 01:17
$env:SCOOP_GLOBAL='D:\ProgramData\scoop'
[Environment]::SetEnvironmentVariable('SCOOP_GLOBAL', $env:SCOOP_GLOBAL, 'Machine')
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
iwr -useb get.scoop.sh | iex
scoop install 7zip git openssh aria2 curl grep sed less touch --global
scoop bucket add extras
scoop install imageglass paint.net firefox vlc vcredist2015 --global
scoop install googlechrome --global
scoop install neovim deluge discord steam
@nhtzr
nhtzr / default.conf
Created July 23, 2019 02:52
File listing http server nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
charset utf-8;
location / {
autoindex on;
}
}