Skip to content

Instantly share code, notes, and snippets.

View netbrain's full-sized avatar
🤔

Kim Eik netbrain

🤔
View GitHub Profile
@netbrain
netbrain / nixos-wsl
Created October 6, 2023 07:32
nixos wsl
# Function to download the tar file
function Download-NixOS {
$url = "https://github.com/nix-community/nixos-wsl/releases/latest/download/nixos-wsl.tar.gz"
$output = "$env:TEMP\nixos-wsl.tar.gz"
Invoke-WebRequest -Uri $url -OutFile $output
return $output
}
# Function to check if WSL is installed and install if it's not
function Install-WSL {
@netbrain
netbrain / gist:288ba07edee771f5c7fd086a0ea9f62e
Last active July 7, 2024 05:02
Windows 11 + WSL + DOCKER + NVIDIA
# Setup WSL
wsl --update
wsl --install -d Debian
# Enter WSL
wsl
# Setup base system
sudo apt update
sudo apt install -y --no-install-recommends apt-transport-https ca-certificates curl gnupg2 vim
@netbrain
netbrain / errs.go
Created April 9, 2021 07:04
multiple errors
type errs []error
func (e errs) Error() string {
s := make([]string,len(e))
for i, err := range e {
s[i] = err.Error()
}
return strings.Join(s,",")
}
@netbrain
netbrain / capture.go
Last active September 14, 2020 08:33
Capture CGO output, realtime.
package main
//#include "capture.h"
import "C"
import (
"bufio"
"fmt"
"log"
"os"
"sync"
@netbrain
netbrain / gist:eca4bb501a0a4764833c705d6ebf0014
Last active January 27, 2020 06:09
various image oprations
//dump jpeg
curl "http://10.41.3.120/cgi-bin/faststream.jpg?stream=MxPEG&fps=0.1" | mxgconv_linux format=jpeg,of=img
//split images
find ./ | grep jpg |xargs -I@ convert -quality 100 -crop 640x480 @ @_cropped_%d.jpg
//preserve original filename in images
ls | xargs -I@ echo exiftool -Comment=@ @
//rename file to md5sum name
// A []C.int64_t slice backed by C memory.
// See: https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices
// Using [1<<27] instead of [1<<30] so it works on 32-bit architecture
@netbrain
netbrain / spit-test-train.sh
Last active January 27, 2020 06:12
Create test/train set example
#!/bin/bash
find /path/to/JPEGImages | grep jpg$ | shuf > files.list
cat files.list | wc -l
#180 = 10%
cat files.list | head -n 180 > test.txt
#rest goes into train.txt
cat files.list | grep -v -f test.txt > train.txt
@netbrain
netbrain / Bus.ts
Created December 12, 2018 08:00
Simple Typescript Event Bus
interface Subscription<T> {
id: number,
type: new () => T
fn: (event:T)=>any
}
class Bus {
private seq:number = 0;
private subscribers:Map<string,Array<Subscription<any>>> = new Map();
@netbrain
netbrain / retrans
Created February 8, 2018 10:54
retrans notes
/* RETRANSMISSION/FAST RETRANSMISSION/OUT-OF-ORDER
* If the segment contains data (or is a SYN or a FIN) and
* if it does not advance the sequence number, it must be one
* of these three.
* Only test for this if we know what the seq number should be
* (tcpd->fwd->nextseq)
*
* Note that a simple KeepAlive is not a retransmission
*/
@netbrain
netbrain / enc2geojson.sh
Created November 10, 2017 11:06
Convert enc files to geojson files
#!/bin/bash
ls *.000 | xargs -I @ bash -c "ogrinfo @ | awk '{if(NR>3)print \$2}' | xargs -I xxx ogr2ogr -f \"GeoJSON\" @_xxx.geojson @ xxx"