Skip to content

Instantly share code, notes, and snippets.

Avatar

Ori Livneh atdt

View GitHub Profile
@atdt
atdt / homebrew-gnubin.md
Created Sep 21, 2020 — forked from skyzyx/homebrew-gnubin.md
Using GNU command line tools in macOS instead of FreeBSD tools
View homebrew-gnubin.md

macOS is a Unix, and not built on Linux.

I think most of us realize that macOS isn't a Linux OS, but what that also means is that instead of shipping with the GNU flavor of command line tools, it ships with the FreeBSD flavor. As such, writing shell scripts which can work across both platforms can sometimes be challenging.

Homebrew

Homebrew can be used to install the GNU versions of tools onto your Mac, but they are all prefixed with "g" by default.

All commands have been installed with the prefix "g". If you need to use these commands with their normal names, you can add a "gnubin" directory to your PATH from your bashrc.

View init.lua
hs.loadSpoon("Lunette")
spoon.Lunette:bindHotkeys()
--[[
- menubar items
- print(hs.inspect(...))
hs.alert.show(string.format("mode: %s x %s", mode.w, mode.h))
--]]
local function sendSystemKey(key)
@atdt
atdt / knockd.conf
Last active Jul 26, 2020
knockd.conf
View knockd.conf
[options]
UseSyslog
[ssh]
sequence = 1000,2000,3000 # change me
seq_timeout = 5
start_command = ufw insert 1 allow from %IP% to any port 22
tcpflags = syn
cmd_timeout = 10
stop_command = ufw delete allow from %IP% to any port 22
@atdt
atdt / knock.py
Created Jul 26, 2020
Port-knocking client (e.g. for knockd) in Python
View knock.py
#!/usr/bin/env python3
# Port-knocking client
# Usage: knock HOST PORT [PORT...]
import socket
import sys
try:
host = sys.argv[1]
ports = [int(p) for p in sys.argv[2:]]
View gist:d36bcfec2907e190b118083b75c5037d
I don't get the appeal of dungeon crawlers. It seems like i could recreate the essential experience by opening Microsoft Excel scrolling down 10,000 pages with the down cursor key, and then typing "the most marvelous trousers of them all".
@atdt
atdt / benchmark_webp
Last active Jun 6, 2020
Benchmark webp vs png for images on enwiki main page
View benchmark_webp
#!/usr/bin/env bash
while IFS= read -r URL ; do
echo "$URL"
echo "WEBP:"
wrk -c1 -t1 -d5 -H 'accept: image/webp' --latency "$URL"
echo ""
echo "PNG:"
wrk -c1 -t1 -d5 --latency "$URL"
@atdt
atdt / or_null.txt
Created May 25, 2020
Names of functions in MediaWiki that return 'X or (null|false)'
View or_null.txt
# Names of functions in MediaWiki that return 'X or (null|false)'
# git grep -A2 -P '@return .*(\||or )(null|false)' -- '*.php' | grep -Po '(?<=function )[^(]+(?=\()' | sort
acquireServerStatesLoopGuard
addInterwikiResults
backendFromPath
buildFileObjectListing
cacheGet
canonicalizeLoginData
castFromLinkTarget
@atdt
atdt / apcu_vs_opcache.php
Last active Dec 13, 2019
loading i10n messages from opcache vs apc
View apcu_vs_opcache.php
<?php
// apcu vs. opcache benchmark
// loads mediawiki en messages from cache 1000 times
// you need languages/i18n/en.json in the same directory as this script.
//
// ini settings you need:
// zend_extension=opcache.so
// opcache.enable=1
// opcache.enable_cli=1
// extension=apcu.so
@atdt
atdt / package.json
Last active Aug 7, 2019
for code next
View package.json
{
"name": "furry-garbanzo ",
"description": "blah blah blah",
"author": "atdt@google.com",
"version": "0.0.1",
"devDependencies": {
"jshint":"^2.10.0"
},
"scripts": {
"test": "jshint **/*.js"
@atdt
atdt / human_duration.py
Created May 19, 2019
Human-readable duration
View human_duration.py
def human_duration(seconds):
if seconds <= 1:
return '0 seconds'
units = (
('day', 86400),
('hour', 3600),
('minute', 60),
('second', 1),
)
parts = []
You can’t perform that action at this time.