Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
jaytaylor / LXC-LXD-2.x-curl-API.md
Created March 4, 2018 22:56
HOWTO: Curl the LXD unix.socket file.

It is possible to use curl to query the LXD unix.socket directly:

curl --unix-socket /var/lib/lxd/unix.socket http:/1.0/containers | jq .

Example output:

{
@jaytaylor
jaytaylor / cf.sh
Last active March 7, 2023 04:27
CloudFlare command-line DNS management shell script, now with CloudFlare v4 API support!
#!/usr/bin/env bash
##
# @author Jay Taylor [@jtaylor]
# @date 2013-08-15
#
# @description CloudFlare management script.
#
# Path ENV VAR override.
@jaytaylor
jaytaylor / json-deepmerge.py
Created January 19, 2023 16:23
JSON object merge tool.
#!/usr/bin/env python3
"""
JSON object merge tool.
Based on mergedeep and Python3 JSON Stream State Machine.
References:
https://github.com/clarketm/mergedeep
@jaytaylor
jaytaylor / ._README.md
Last active December 27, 2022 03:11
Python scripts to Remove, modify, or create a file without changing the modification time of the parent directory.

*_preserving_parent_mtime.py

Python programs to remove or modify files without changing the modification time of the parent directory.

Quick Install

curl -fSLO https://gist.github.com/jaytaylor/e2e0b53baf224f4e973b252370499de7/raw/bc175ba7008626ebc3f356c16f8240ebe578c5a0/rm_preserving_parent_mtime.py
curl -fSLO https://gist.github.com/jaytaylor/e2e0b53baf224f4e973b252370499de7/raw/bc175ba7008626ebc3f356c16f8240ebe578c5a0/mv_preserving_parent_mtime.py
chmod a+x rm_preserving_parent_mtime.py mv_preserving_parent_mtime.py
@jaytaylor
jaytaylor / rm_preserving_parent_mtime.py
Last active December 27, 2022 03:10
Removes a file or directory while preserving the modification time (mtime) of the parent directory.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Removes a file or directory while preserving the modification time (mtime) of
the parent directory.
Pure-python implementation.
See also:
@jaytaylor
jaytaylor / ._base64-url-shortener-poc.md
Last active December 16, 2022 10:39
URL shortener Base-62 encoder / decoder C++ Proof-of-Concept
@jaytaylor
jaytaylor / timeout.sh
Created September 11, 2013 18:18
Mac OS-X does not come with the delightfully useful `timeout` program. Thankfully a rough BASH equivalent can be achieved with only 2 perl statements.
#
# Mac OS-X does not come with the delightfully useful `timeout` program. Thankfully a rough BASH equivalent can be achieved with only 2 perl statements.
#
# Originally found on SO: http://stackoverflow.com/questions/601543/command-line-command-to-auto-kill-a-command-after-a-certain-amount-of-time
#
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
## Example usage:
#
@jaytaylor
jaytaylor / serving.py
Last active July 25, 2022 12:22
MyFancyRequestHandler extends the werkzeug BaseRequestHandler to provide HTTP request execution time to the server log. NB: The associated tutorial is: http://jaytaylor.com/blog/?p=305
import time
from werkzeug.serving import BaseRequestHandler
class MyFancyRequestHandler(BaseRequestHandler):
"""Extend werkzeug request handler to suit our needs."""
def handle(self):
self.fancyStarted = time.time()
rv = super(MyFancyRequestHandler, self).handle()
return rv
@jaytaylor
jaytaylor / gitmodules-sorter.md
Created May 4, 2017 17:41
Sort .gitmodules, also easily adaptable to sort files in blocks (e.g. 4 lines at a time, or arbitrary region at a time).
@jaytaylor
jaytaylor / math.sh
Created August 8, 2019 21:33
Math functions from python as bash "builtins".
#!/usr/bin/env bash
##
#
# @author Jay E. Taylor <jay@jaytaylor.com>
#
# @description Math functions for bash!
#
##