Skip to content

Instantly share code, notes, and snippets.

@sakateka
sakateka / mongo_shard_init.sh
Last active January 8, 2016 02:42
nano mongo cluster initializer
#!/bin/bash
cCfg="--fork --logappend";W=" --storageEngine=wiredTiger ";
nShrds=4;mt(){ tail $@|sed '/^$/d'|grep --color -C$dl =;}
r=1;g=2;o=3;b=4;m=5;p=6; ec(){ echo -e $3 "${4:-\t}\e[3${!1:-7}m$2\e[0m";}
_n="#`echo {a..z}|tr -d ' '`"; hlp="[-d[d+]ebug] -help|-stop|-clean|-init [-key]"
md(){ mkdir -p$v $1 >&4;};ecn(){ ec "$@" -n "-\b";};len(){ echo ${#1};};nrep=3
for i; do case $i in -d*)dl=`len ${i//[-abce-z]/}` v=v; ((dl>2))&&set -x;;
-c|-clean) _clean=1;_die=1;; -i|-init) _init=1;_stop=1;_clean=1;;
-s|-stop) _stop=1;_die=1;; -p|-pprefix) _pfx=1;;
-k|-key) cCfg="$cCfg --keyFile key";_key=1;;
@sakateka
sakateka / parallel_logs_rotate.sh
Last active October 26, 2015 06:43
parallel many logs rotate
#!/bin/bash
pigz_mv() { g="$1-$(date +%Y%m%d-%s).gz"; pigz -k "$1" && mv "$1".gz "$g" && truncate -s0 "$1"; }
plog_pigz_mv() {
local logs="$@" ts=$(date '+%Y%m%d-%s');
pigz -k $logs;
for l in $logs; do
mv ${l}.gz ${l}-${ts}.gz && truncate -s0 $l;
done
@sakateka
sakateka / c.sh
Created January 8, 2016 02:21
Interactive C Shell
c(){
local go_libs="-lm" go_flags="-g -Wall -include allheads.h -O0"
local prompt="C > "
local first_line="int main(int argc, const char *argv[]){"
local end_line="}"
local code prev_code line
local HISTFILE="~/.c.hist"
#while read -erp "C > " line; do
@sakateka
sakateka / lua.go
Last active November 24, 2016 20:38
lua plugin benchmark
package main
import (
"fmt"
"reflect"
"strconv"
luar "github.com/layeh/gopher-luar"
lua "github.com/yuin/gopher-lua"
)
coproc ZKLOCK {
zk-flock -w 10 -x 81 -c $ZK_FLOCK_CONFIG $LOCK_NAME "bash -c 'echo Locked; read'"
if (($? == 81)); then
echo "LockBusy"
else
echo "Failed"
fi
}
zk_stdin=${ZKLOCK[1]}
read -u ${ZKLOCK[0]} zk_reply 2>/dev/null
@sakateka
sakateka / result.txt
Last active October 14, 2017 08:27
Shuffle slice indices vs append
go test -bench=. -benchmem shuffle_test.go
goos: linux
goarch: amd64
BenchmarkIndex-4 100000000 12.5 ns/op 0 B/op 0 allocs/op
BenchmarkAppend-4 1000000 1423 ns/op 661 B/op 0 allocs/op
PASS
ok command-line-arguments 2.707s
@sakateka
sakateka / result_2017.txt
Last active February 20, 2021 06:48
threaded malloc test
$ clang -g -Wall -O3 threaded_malloc.c -o threaded_malloc -pthread
$ # ptmalloc2
$ /usr/bin/time -v ./threaded_malloc
100,000,000 allocations in 2439ms (41000410/s)
100,000,000 deallocations in 13101ms (7633005/s)
100,000,000 allocations in 14536ms (6879471/s)
100,000,000 deallocations in 13306ms (7515406/s)
100,000,000 allocations in 14947ms (6690305/s)
100,000,000 deallocations in 2424ms (41254125/s)
Command being timed: "./threaded_malloc"
var server = java.lang.management.ManagementFactory.getPlatformMBeanServer();
var mb = java.lang.management.ManagementFactory.newPlatformMXBeanProxy(
server,
"com.sun.management:type=HotSpotDiagnostic",
com.sun.management.HotSpotDiagnosticMXBean.class
);
mb.getDiagnosticOptions();
@sakateka
sakateka / config
Created February 28, 2023 19:40 — forked from tdack/config
#
# Automatically generated file; DO NOT EDIT.
# Linux/arm 4.4.11 Kernel Configuration
#
CONFIG_ARM=y
CONFIG_ARM_HAS_SG_CHAIN=y
CONFIG_NEED_SG_DMA_LENGTH=y
CONFIG_ARM_DMA_USE_IOMMU=y
CONFIG_ARM_DMA_IOMMU_ALIGNMENT=8
CONFIG_MIGHT_HAVE_PCI=y
@sakateka
sakateka / build_kernel.sh
Created February 28, 2023 19:47 — forked from tdack/build_kernel.sh
Build the kernel for the Next Thing Co C.H.I.P.
#!/bin/bash
# Desktop build
MAKE="make -j 4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-"
# C.H.I.P. build
#MAKE="make"
CDIR=$PWD
LINUX=$CDIR/CHIP-linux
WIFI=$CDIR/RTL8723BS