Skip to content

Instantly share code, notes, and snippets.

@AndreKR
AndreKR / SimpleCountDownTimer.java
Created Jul 30, 2021
A simpler Android CountDownTimer
View SimpleCountDownTimer.java
package foo;
import android.os.CountDownTimer;
public class SimpleCountDownTimer {
boolean repeat;
Runnable action;
CountDownTimer c;
@AndreKR
AndreKR / BleStateMachine.java
Created Jul 12, 2020
Read a BLE characteristic on Android
View BleStateMachine.java
package com.example.android.app;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
@AndreKR
AndreKR / logrus.go
Last active Oct 7, 2019
Initializing logrus
View logrus.go
// The state of Go logging libraries is disheartening...
import (
"github.com/mattn/go-colorable" // not ansicolor because github.com/mgutz/ansi recommends colorable
log "github.com/sirupsen/logrus"
"github.com/x-cray/logrus-prefixed-formatter"
"golang.org/x/crypto/ssh/terminal"
"os"
)
@AndreKR
AndreKR / tgit_dmerge.txt
Last active Mar 29, 2019
TortoiseGit + DiffMerge
View tgit_dmerge.txt
"C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe" -m -t1=%yname -t2=%bname -t3=%tname -result=%merged %mine %base %theirs
@AndreKR
AndreKR / get_all_kubernetes_resources.md
Created Dec 13, 2018
Get all resources in a Kubernetes cluster
View get_all_kubernetes_resources.md

kubectl api-resources --verbs=list -o name | xargs -n 1 -t kubectl get --ignore-not-found --all-namespaces

@AndreKR
AndreKR / model_vs_sync.md
Created Aug 24, 2017
Vue.js v-model vs. v-bind.sync
View model_vs_sync.md

Vue.js: v-model vs. v-bind:<propname>.sync

These examples use the expression foo as the data source in the parent.

Prop name Event name
v-model="foo" value by default input by default
v-bind:<propname>.sync="foo" arbitrary update:<propname>

v-model

@AndreKR
AndreKR / latest_gitlab_artifacts.txt
Last active Sep 13, 2017
Download the latest artifacts from GitLab
View latest_gitlab_artifacts.txt
# ZIP:
wget --header="PRIVATE-TOKEN: $GITLAB_TOKEN" "https://<gitlab>/<group>/<project>/builds/artifacts/master/download?job=<jobname>"
or
wget --header="PRIVATE-TOKEN: $GITLAB_TOKEN" "https://<gitlab>/<group>/<project>/-/jobs/artifacts/master/download?job=<jobname>"
# Single file:
wget -O /path/to/file --header="PRIVATE-TOKEN: $GITLAB_TOKEN" "https://<gitlab>/<group>/<project>/builds/artifacts/master/raw/<filename>?job=<jobname>"
@AndreKR
AndreKR / go_release_build.txt
Last active May 20, 2018
Build smaller executables with Go
View go_release_build.txt
go build -gcflags=all=-trimpath=c:\path\to\trim -asmflags=all=-trimpath=c:\path\to\trim -ldflags=all="-s -w"
upx ...
View exedir.go
var exeDir = getExeDir()
func getExeDir() string {
if os.Getenv("EXEDIR") != "" {
return os.Getenv("EXEDIR")
} else {
return filepath.Dir(os.Args[0])
}
}
@AndreKR
AndreKR / http_context.go
Created Jun 11, 2017
Go http + context
View http_context.go
// While the Go documentation promotes the context package for keeping track of request context and cancelation, to
// actually use it for canceling work in http requests some plumbing is necessary:
// getCancelableContextFromResponseWriter gets a context.Context that is canceled when the client (browser) closes the connection
func getCancelableContextFromResponseWriter(w http.ResponseWriter) context.Context {
// Create a context that can be handed down to the workers to relay cancellation
ctx, cancelContext := context.WithCancel(context.Background())
// Get a channel that receives a value when the request is canceled