Skip to content

Instantly share code, notes, and snippets.

View djosix's full-sized avatar
🐑
In a relationsheep

Yuan-Kui Li djosix

🐑
In a relationsheep
View GitHub Profile
@creachadair
creachadair / wake-on-change.md
Last active November 20, 2023 04:37
Waiting for a Value to Change in Go

Waiting for a Value to Change in Go

When multiple goroutines share access to a value that will periodically change, readers may wish to wait for a value to be updated before reading the value again. This can be solved using a condition variable:

var val *Thing
var mu = new(sync.Mutex)
var cond = sync.NewCond(mu)

func wait(old *Thing) *Thing {
@m-radzikowski
m-radzikowski / script-template.sh
Last active May 4, 2024 04:13
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@robskillington
robskillington / prometheus.proto
Last active May 10, 2024 18:28
Example Python Prometheus remote write client
// Copyright 2016 Prometheus Team
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@erdii
erdii / copy_elasticsearch_index_to_other_server.sh
Last active December 28, 2022 10:43
Copy an elasticsearch index definition (settings and mapping - no data) to another server
# copy index definition
INDEX_NAME="my_index"
curl -X GET "http://source-server:9200/$INDEX_NAME" | curl -X PUT "http://destination-server:9200/$INDEX_NAME" -d @-
# copy mapping for "my_doc_type"
DOC_TYPE="my_doc_type"
curl -X GET "http://source-server:9200/$INDEX_NAME/_mapping" | jq .$INDEX_NAME.mappings.$DOC_TYPE | curl -X PUT "http://destination-server:9200/$INDEX_NAME/_mapping/$DOC_TYPE" -d @-
@calebstewart
calebstewart / ghidra-9.0.desktop
Created March 9, 2019 15:51
Desktop File for Ghidra 9.0
[Desktop Entry]
Categories=Application;Development;
Comment[en_US]=Ghidra Software Reverse Engineering Suite
Comment=Ghidra Software Reverse Engineering Suite
Exec=/opt/ghidra/ghidraRun
GenericName[en_US]=Ghidra Software Reverse Engineering Suite
GenericName=Ghidra Software Reverse Engineering Suite
Icon=/opt/ghidra/support/ghidra.ico
MimeType=
Name[en_US]=Ghidra 9.0
@viritt
viritt / cloudflare_update.script
Last active December 26, 2023 16:14 — forked from kiler129/cloudflare_update.script
Automatic script for Mikrotik RouterOS updating record on CloudFlare.
#########################################################################
# ================================================== #
# $ Mikrotik RouterOS update script for CloudFlare $ #
# ================================================== #
# #
# - You need a CloudFlare account & api key (look under settings), #
# a zone and A record in it #
# - All variables in first section are obvious, except CFid, #
# To obtain CFzoneid use following command in any unix shell: #
# curl -X GET "https://api.cloudflare.com/client/v4/accounts" -H "X-Auth-Email: YOUR_EMAIL" -H "X-Auth-Key: YOUR_API_KEY" -H "Content-Type: application/json" | python -mjson.tool
@fnky
fnky / ANSI.md
Last active May 12, 2024 13:47
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@jmbjorndalen
jmbjorndalen / asyncio_executors_threads_procs.py
Created April 26, 2018 08:10
Combining Python 3 asyncio coroutines with thread pool and process pool executors
#!/usr/bin/env python3
# Combining coroutines running in an asyncio event loop with
# blocking tasks in thread pool and process pool executors.
#
# Based on https://pymotw.com/3/asyncio/executors.html, but this version runs both
# threads and processes at the same time and interleaves them with asyncio coroutines.
#
# All appears to be working.
#
@chrisdone
chrisdone / gist:02e165a0004be33734ac2334f215380e
Last active May 11, 2024 14:01
Build and run minimal Linux / Busybox systems in Qemu

Common

export OPT=/opt
export BUILDS=/some/where/mini_linux
mkdir -p $BUILDS

Linux kernel