Skip to content

Instantly share code, notes, and snippets.

def real_uptime_ns():
from time import CLOCK_BOOTTIME
from time import clock_gettime_ns
from os import sysconf, sysconf_names
with open("/proc/self/stat") as f:
stat_fields = f.readline().split()
proc_start_since_boot_tick = float(stat_fields[21])
start_since_boot_sec = proc_start_since_boot_tick / sysconf(
sysconf_names["SC_CLK_TCK"]
$ErrorActionPreference = "Stop"
$global:ProgressPreference = "SilentlyContinue"
# Import the necessary .NET classes
Add-Type -TypeDefinition @'
using System.IO;
public class DirectoryHelper {
public static void CreateDirectoryIfNeeded(string path) {
if (!Directory.Exists(path)) {
@Ragnoroct
Ragnoroct / aws_signed_requests.py
Last active February 17, 2023 22:38
aws signed requests v4 using stdlib
"""
MIT License
Copyright (c) 2023 Will Bender
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
#!/usr/bin/env bash
# Diffs changelist to correct prettier format
#
# You can apply the prettier patch from this output
# xclip -out | git apply -
# pbpaste | git apply -
# cat /dev/clipboard | git apply -
git_root=$(git rev-parse --show-toplevel)
@Ragnoroct
Ragnoroct / node_requests.js
Last active January 27, 2022 01:20
network-requests-standard-lib
const https = require("https")
const http = require("http")
(async () => {
await httpsGetToFile("https://example.com/", "/tmp/example.com.txt", { headers: {"Range": "bytes=0-4"}})
})()
/**
* @param {string} uri
* @param {ClientRequestArgs} options
@Ragnoroct
Ragnoroct / git-recent
Last active March 30, 2023 21:33
Another git recent command to see your recently checked out files. It can also switch if you give a number argument.
#!/usr/bin/env bash
# Copyright (c) 2023 Will Bender. All rights reserved.
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
# See most recently checked out branches and easily switch to one
NUMBER=5 # Max branches to echo in list
@Ragnoroct
Ragnoroct / __fastgit_ps1.sh
Created February 26, 2020 19:45
Blazing fast simple git branch name for ps1
# Copyright (c) 2019 Will Bender. All rights reserved.
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
# Very fast __git_ps1 implementation
# Inspired by https://gist.github.com/wolever/6525437
# Mainly this is useful for Windows users stuck on msys, cygwin, or slower wsl 1.0 because git/fs operations are just slower
# Caching can be added by using export but PROMPT_COMMAND is necessary since $() is a subshell and cannot modify parent state.
# Linux: time __ps1_ps1 (~7ms)