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 13, 2021 04:45
golang utils
package duration
import (
"encoding/json"
"fmt"
"time"
)
type Duration struct {
time.Duration
@killwing
killwing / convertArgsStrToArray.sh
Created November 7, 2012 17:44
[convertArgsStrToArray] convert args str to array
#!/bin/bash
returnVal=()
convertArgsStrToArray() {
local concat=""
local t=""
returnVal=()
for word in $@; do
local len=`expr "$word" : '.*"'`
#!/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
@killwing
killwing / option_parser.sh
Created October 10, 2014 10:36
cmd line options parser
#!/bin/bash
# for optional arguments: short - there can't be any spaces between the option and the argument
# long - the argument can only be passed by "="
# parse options
OPTIONS=$(getopt -o o::r:n -l optional::,required:,none -n "$0" -- "$@")
# check result
[ $? -ne 0 ] && exit 1
#!/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 / markdown.css
Created June 15, 2012 17:55
[markdowncss]flavored markdown style
/*
CSS stylesheet is based on Kevin Burke's Markdown.css project:
http://kevinburke.bitbucket.org/markdowncss
For code highlighting:
<link rel="stylesheet" href="http://yandex.st/highlightjs/6.1/styles/magula.min.css">
<script src="http://yandex.st/highlightjs/6.1/highlight.js"></script>
<script src="http://yandex.st/highlightjs/6.1/languages/cpp.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
*/