Skip to content

Instantly share code, notes, and snippets.

@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
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: backup
namespace: jenkins
spec:
schedule: 0 17 * * * # 00:00 GMT+7
successfulJobsHistoryLimit: 5
failedJobsHistoryLimit: 5
jobTemplate:
{
"workbench.colorCustomizations": {
"[Default Dark+]": {
"focusBorder": "#404552",
"foreground": "#D3DAE3",
"button.background": "#383C4A",
"button.foreground": "#FFF",
"input.border": "#F5F6F7",
"input.background": "#393f4c",
"input.foreground": "#FFF",