Skip to content

Instantly share code, notes, and snippets.

@killwing
killwing / generics.go
Created April 26, 2024 08:54
generic utils
package main
import (
"encoding/json"
"fmt"
"os"
)
func bar() (int, error) { return 2, fmt.Errorf("testerr") }
@killwing
killwing / linkit.js
Last active May 25, 2022 01:45
bookmarklet
javascript:document.querySelectorAll("li section").forEach(s => s.innerHTML = s.innerHTML.replace(/(https:\/\/.*)/, "<a href='$1' target='_blank'>$1</a>"))
@killwing
killwing / duration.go
Last active August 19, 2024 06:04
golang utils
// alt. https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/v1/duration.go
package duration
import (
"encoding/json"
"fmt"
"time"
)
type Duration struct {
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
#!/usr/bin/env python3
import argparse
import os
import random
import shutil
import time
import warnings
import torch
import torch.nn as nn
@killwing
killwing / ubuntu.Dockerfile
Created April 12, 2019 07:18
ubuntu image with debugging tools
FROM ubuntu:18.04
ENV LC_ALL=C.UTF-8
ENV TERM=xterm
ADD http://devtools.dl.atlab.ai/docker/PRC-tz /etc/localtime
ADD https://github.com/krallin/tini/releases/download/v0.18.0/tini /usr/local/bin/tini
ADD https://github.com/tobert/pcstat/raw/2014-05-02-01/pcstat.x86_64 /usr/local/bin/pcstat
RUN chmod +x /usr/local/bin/tini && chmod +x /usr/local/bin/pcstat
#!/bin/bash
FQDN=$1
# make directories to work from
mkdir -p server/ client/ all/
# Create your very own Root Certificate Authority
openssl genrsa \
-out all/my-private-root-ca.privkey.pem \
2048
@killwing
killwing / main.go
Created March 31, 2017 11:46
flac cue maker (with foobar)
package main
import (
"fmt"
"regexp"
"strings"
)
const cueInfo = `FILE "01 遺サレタ場所:丁.wav" WAVE
TRACK 01 AUDIO
@killwing
killwing / proxy.go
Created December 13, 2015 11:00
simple proxy
package main
import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"sync"
"time"
@killwing
killwing / bit-hack.cpp
Last active August 29, 2015 14:14
useful bit hacks
// round down to multiple of 1024
size_t roundDown(size_t s) {
return s & ~1023;
}
// round up to multiple of 1024
size_t roundUp(size_t s) {
return (s + 1023) & ~1023;
}