Skip to content

Instantly share code, notes, and snippets.

@elnygren
elnygren / Dockerfile
Last active January 2, 2024 21:37
Nginx+Docker with autoreload on config changes for local development
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
RUN apt-get update && apt-get install -y inotify-tools
COPY watcher.sh /watcher.sh
RUN chmod +x /watcher.sh
CMD ["/watcher.sh"]
@vikyd
vikyd / getVal.sh
Last active September 12, 2018 03:07
Shell: get value from key=value file with value trim and key trim, and allow `=` ` space` in value
#!/bin/sh
# These vars and func are used to get value from a key=value file
# It will also trim the leading and trailing whitespace, tab
# Key with space after or before is supported
getVal(){
# cut `=` in val: https://unix.stackexchange.com/a/53315/207518
# grep: allow space after or before of key
# awk trim space after and before of value: https://unix.stackexchange.com/a/205854/207518
declare val=$(cat ${1} | grep "^ *${2} *=" | cut -d '=' -f 2- | awk '{$1=$1}1')
@vikyd
vikyd / getVal.bat
Last active September 12, 2018 03:08
Windows Batch: get value from key=value file with value trim, not allow `=` in value, not allow space after or before the key
@ECHO OFF
REM https://stackoverflow.com/a/9681923/2752670
SET myKey=abc2
SET myFile=keyval.txt
CALL :GetVal %myFile% %myKey% myVal
REM is string empty https://stackoverflow.com/a/2541820/2752670
IF [%myVal%] == [] (
ECHO no key: %myKey% in file: %myFile%
) ELSE (
@mahasak
mahasak / postman-bigint.js
Last active April 30, 2024 17:12
Postman Test Runner BigInt fix
var BigNumber,
isNumeric = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,
mathceil = Math.ceil,
mathfloor = Math.floor,
notBool = ' not a boolean or binary digit',
roundingMode = 'rounding mode',
tooManyDigits = 'number type has more than 15 significant digits',
ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_',
BASE = 1e14,
LOG_BASE = 14,
@alswl
alswl / hosts
Last active November 12, 2023 11:17
(deprecated, I bought xiaomi VIP)hosts for OpenWRT, for disable AD in xiaomi TV
127.0.0.1 api.ad.xiaomi.com
127.0.0.1 sdkconfig.ad.xiaomi.com
127.0.0.1 ad.mi.com
127.0.0.1 ad.xiaomi.com
127.0.0.1 ad1.xiaomi.com
127.0.0.1 adv.sec.miui.com
127.0.0.1 test.ad.xiaomi.com
127.0.0.1 new.api.ad.xiaomi.com
@mdonkers
mdonkers / server.py
Last active April 30, 2024 23:26
Simple Python 3 HTTP server for logging all GET and POST requests
#!/usr/bin/env python3
"""
License: MIT License
Copyright (c) 2023 Miel Donkers
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
@jesselucas
jesselucas / changroup.go
Last active April 17, 2024 14:33
Simple solution for using a WaitGroup with select{}
package main
import (
"fmt"
"sync"
"time"
)
func main() {
// Create a wait group of any size
@vcabbage
vcabbage / command-timeout-pre17.go
Last active May 20, 2021 07:33
Command timeout without context
package main
import (
"bytes"
"fmt"
"os/exec"
"time"
)
func main() {
@lopes
lopes / aes-cbc.py
Last active March 21, 2024 04:22
Simple Python example of AES in CBC mode.
#!/usr/bin/env python3
#
# This is a simple script to encrypt a message using AES
# with CBC mode in Python 3.
# Before running it, you must install pycryptodome:
#
# $ python -m pip install PyCryptodome
#
# Author.: José Lopes
# Date...: 2019-06-14
@subfuzion
subfuzion / curl.md
Last active May 6, 2024 09:53
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.