Skip to content

Instantly share code, notes, and snippets.

@abihf
abihf / xdg-open
Created December 11, 2025 03:08
xdg-open using handler and app2unit
#!/bin/sh
url="${1}"
mime="$(handlr mime --json "${url}" | jq -r '.[0].mime')"
handler="$(handlr get --json "${mime}" | jq -r '.handler')"
exec app2unit "${handler}" "${url}"
@abihf
abihf / onejavdl.go
Created July 6, 2024 19:36
Download latest torrents from onejav
package main
import (
"context"
"fmt"
"io"
"log/slog"
"net/http"
"os"
"path/filepath"
@abihf
abihf / 1brc.go
Created March 16, 2024 20:58
Golang Implementation for 1 Billion Rows Challange
package main
import (
"bufio"
"bytes"
"errors"
"fmt"
"hash/maphash"
"io"
"os"
@abihf
abihf / glob-matcher.ts
Created October 7, 2020 20:32
Fast path router supporting glob
type MatcherNode<T> = {
children: Record<string, MatcherNode<T>>;
glob?: Array<MatcherNode<T>>;
glob2?: Array<MatcherNode<T>>;
value?: T;
};
// sorry, I exercise here.
class GlobMatcher<T> {
root: MatcherNode<T>;
@abihf
abihf / screen-record.sh
Created May 16, 2020 19:40
smooth screen recording with hevc/h265 hardware encoding
# need sudo
ffmpeg -device /dev/dri/card0 -f kmsgrab -framerate 60 -i - -vf 'hwmap=derive_device=vaapi,scale_vaapi=format=nv12' -c:v hevc_vaapi output-$(date +%s).mp4
# tested with amdgpu
@abihf
abihf / compression_test.go
Created April 16, 2020 05:16
GZip vs Brotli
package main
import (
"bytes"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
@abihf
abihf / covid19.py
Created April 6, 2020 16:31
Download Indonesia Covid19 Data as CSV
#!/usr/bin/env python3
import http.client
import json
import datetime
conn = http.client.HTTPSConnection("services5.arcgis.com")
def main():
cur_date = datetime.datetime.now().strftime('%Y-%m-%d')
@abihf
abihf / delete-offline-slaves.groovy
Last active April 8, 2020 19:03
Clean jenkins jobs
Jenkins.instance.slaves.each {
def comp = it.getComputer()
if (comp.isOffline()) {
comp.doDoDelete()
}
}
import jenkins.model.Jenkins
Jenkins.instanceOrNull.allItems(hudson.model.Job).each { job ->
if (job.isBuildable() && job.supportsLogRotator() && job.getProperty(jenkins.model.BuildDiscarderProperty) == null) {
println "Processing \"${job.fullDisplayName}\""
try {
job.setBuildDiscarder(new hudson.tasks.LogRotator ( 14, -1, 14, -1))
println "${job.fullName} is updated"
} catch (Exception e) {
// Some implementation like for example the hudson.matrix.MatrixConfiguration supports a LogRotator but not setting it
@abihf
abihf / README.md
Created February 25, 2020 15:41
EKS Restricted pod security policy

You might want to add some service account to ClusterRoleBinding/psp:privileged

kubectl apply -f eks-restricted-psp.yml

# delete default role binding
kubectl delete clusterrolebinding eks:podsecuritypolicy:authenticated