Skip to content

Instantly share code, notes, and snippets.

View HoldYourWaffle's full-sized avatar
💭
I may be slow to respond.

Ravi van Rooijen HoldYourWaffle

💭
I may be slow to respond.
View GitHub Profile
@HoldYourWaffle
HoldYourWaffle / ClipCursor.ahk
Created May 26, 2023 19:01
AutoHotkey - Clip cursor to rectangle
#Requires AutoHotkey v2.0
; Source for AHK v1: https://www.autohotkey.com/boards/viewtopic.php?p=445668&sid=dee54807a74853039237b72c90610eae#p445668
ClipCursor(x := "", y := "", w := "", h := "") {
if p := x != "" {
VarSetStrCapacity(&RECT, 16)
p := StrPtr(RECT)
for k, v in [x, y, x + w, y + h] {
target := p + 4 * (k - 1)
NumPut("Int", v, target)
@HoldYourWaffle
HoldYourWaffle / GetJunctionTarget.ahk
Created May 26, 2023 18:56
AutoHotkey - Get directory junction target
#Requires AutoHotkey v2.0
GetJunctionTarget(Path) {
OutLogPath := A_Temp . "\AHK-GetJunctionTarget-fsutil.txt"
fsutil := A_ComSpec . " /c fsutil reparsepoint query `"" . Path . "`" > `"" . OutLogPath . "`""
ExitCode := RunWait(fsutil)
if (ExitCode != 0) {
throw Error(fsutil . " exited with exit code " . ExitCode)
}
@HoldYourWaffle
HoldYourWaffle / gapi-signin-translate.js
Created August 2, 2020 11:21
Translate gapi-rendered Google Sign-In button text programmatically
/** Utility function to change the text of a gapi-rendered Google Sign-In button */
function translateSignin(id, signinText, signedinText) {
const spans = document.getElementById(id).querySelectorAll('.abcRioButtonContents span');
if (spans.length !== 2) {
throw new Error(`Incorrect amount of sign-in span children (${spans.length} != 2)`);
}
spans.forEach(span => {
span.innerHTML = span.innerHTML.replace(/^Sign in with Google$/, signinText);
@HoldYourWaffle
HoldYourWaffle / BitBoolean.java
Created April 27, 2020 21:02
Utility class for storing 64 booleans in a long
public class BitBoolean {
private static final long[] indexToBitMask = new long[64];
static {
long mask = 1;
for (int i=0; i<64; i++) {
indexToBitMask[i] = mask;
mask *= 2;
}
@HoldYourWaffle
HoldYourWaffle / node-http-echo.js
Last active September 15, 2019 20:39
Simple node echo http server
// FIXME this leaks memory for some reason
const http = require('http');
const port = parseInt(process.argv[2]);
const server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'application/json');
res.write(stringify(req));
res.end();
});
@HoldYourWaffle
HoldYourWaffle / current-git-branch.gradle
Last active February 16, 2018 18:34 — forked from lordcodes/current-git-branch.gradle
Gradle function to get the current git branch
def getCurrentGitBranch() {
def gitBranch = "Unknown branch"
def workingDir = new File("${project.projectDir}")
def result = 'git rev-parse --abbrev-ref HEAD'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() == 0) gitBranch = result.text.trim()
return gitBranch
}
@HoldYourWaffle
HoldYourWaffle / git-pull-branches
Created February 4, 2018 11:03
Git setup all remote tracking branches
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
@HoldYourWaffle
HoldYourWaffle / git-clone-large
Last active August 13, 2019 08:48
Git-clone a huge repository
#!/bin/bash
git clone $1 --depth=1
# cd into the repo directory
a=$1
b="${a##*/}";
cd "${b%.*}"
for i in {1..100000..10}; do git fetch --depth=$i; done
git fetch --unshallow
@HoldYourWaffle
HoldYourWaffle / git-dangling-commits
Created January 19, 2018 09:14
Simple bash script that lists dangling commits with the description of the log entry to identify it. Based on @alexmchale 's ruby version.
#!/bin/bash
git fsck --lost-found 2>&1 | grep "dangling commit" | while read line; do
hash="${line:16}"
git show --oneline "$hash" 2>&1 | head -n 1;
done