Skip to content

Instantly share code, notes, and snippets.

View VehpuS's full-sized avatar
🦔

Moshe Jonathan Gordon Radian VehpuS

🦔
View GitHub Profile
@VehpuS
VehpuS / mod-a-b.js
Created March 10, 2022 17:13
Calculating modulo with other arithmetic functions (thanks to https://stackoverflow.com/questions/35155598/unable-to-use-in-glsl for the idea)
// neither recursion nor looping is necessary to compute a mod b. That's easily done by a - (b * floor(a/b)).
const mod = (a, b) => a - (b * floor(a/b))
// Simple, but powerful when running on platforms that lack the function but have the floor function (i.e. GLSL for deck.gl)
// Thanks to https://stackoverflow.com/questions/35155598/unable-to-use-in-glsl for the idea
@VehpuS
VehpuS / awaitable-img.ts
Created February 13, 2022 15:31
Awaitable loaded image object - useful for drawing to canvas, getting dimensions
const getLoadedImg = (url: string) => new Promise<HTMLImageElement>(resolve => {
const img = new Image();
img.crossOrigin = "anonymous";
img.src = url
img.onload = function () {
resolve(img);
}
});
@VehpuS
VehpuS / gdal-install-mac.md
Created January 21, 2022 08:47
How to install GDAL on a new Mac (hint: not brew, surprisingly)

Common

On Mac OS X you can install the “GDAL Complete” Framework from kyngchaos.com.

GDAL applications are run through the Mac OS X Terminal. The first time you install the GDAL package there is one additional step to make sure you can access these programs. Open the Terminal application and run the following commands:

New Oses (zsh):

vi ~/.zshenv
@VehpuS
VehpuS / concurrent_executor_map_order_proof.py
Created November 2, 2021 09:21
Proof that concurrent.future's executor.map returns values in order
import time
import random
import concurrent.futures
e = concurrent.futures.ThreadPoolExecutor(4)
s = range(10)
def sleep_and_return(i):
time.sleep(random.randint(3,7))
return i
@VehpuS
VehpuS / for-each-glob-match.sh
Created August 22, 2021 08:36
Run a bash command on every glob match
#!/bin/bash
for glob in $(ls *.json); do echo $glob; done

Git pre-commit hook for large files

This hook warns you before you accidentally commit large files to git. It's very hard to reverse such an accidental commit, so it's better to prevent it in advance.

Since you will likely want this script to run in all your git repos, a script is attached to add this hook to all git repos you create / clone in the future.

Of course, you can just download it directly to the hooks in an existing git repo.

Installation

@VehpuS
VehpuS / git_archive.md
Created August 8, 2021 11:30
Getting a specific file / folder in a specific commit / branch from a remote git

git archive --remote=git@.... --format=tar branch-or-commit path/in/git > output.tar

@VehpuS
VehpuS / LICENSE
Last active August 8, 2021 11:40
This license applies to all public gists https://gist.github.com/vehpus, unless specified otherwise in the gist itself
MIT License
Copyright (c) 2021 Moshe Jonathan Gordon Radian
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
furnished to do so, subject to the following conditions:
@VehpuS
VehpuS / .eslintignore
Created July 17, 2021 17:48
Auto linting / testing / prettifying on commits - template package.json, .eslintrc, .prettierrc, .prettierignore, .husky, .eslintignore, commitlint.config.js files from a react native project - demonstrating a setup that worked, possibly to be maintained with my continuous best practiices
node_modules
dist
.expo
.expo-shared
web-build
@VehpuS
VehpuS / center-on-screen.css
Created July 16, 2021 05:24
A quick reference to cool ways to center elements
.el {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 0;
transform: translateY(calc(50vh - 50%));
}