TIL
Git Undos (2025-02-24)
Undo: Created a commit
- Run
git reset --soft HEAD~
.
Undo: Deleted a commit
- Run
git reflog
to display the list of recent head commits. - Copy the first one's hash.
- Run
git reset
, thengit stash
to set changes aside. - Run
git reset --hard COPIED_HASH
to revert to the previous head commit. - Run
git stash pop
to restore stashed changes.
Undo: Rebased a branch (reword, move, delete, fixup)
- See above.
Undo: Pulled from a remote
- See above.
Undo: Pushed to a remote
- Find the output of the
git push
command to undo. - On the last line of the output, copy the first commit hash.
- Run
git push force COPIED_HASH
. - If the remote branch was changed since your push, the new changes will silently be overwritten.
Undo: Created a branch
- Run
git branch -d BRANCH_NAME
.
Undo: Deleted a branch
- Find the output of the
git branch -d
command to undo. - Copy the commit hash.
- Run
git branch BRANCH_NAME COPIED_HASH
.
Undo: Staged a file
- To unstage the whole file, run
git restore --staged FILE_PATH
. - To unstage specific hunks, instead run
git reset -p FILE_PATH
, and manually select the hunks.
Undo: Unstaged a file
- To stage the whole file, run
git add FILE_PATH
. - To stage specific hunks, instead run
git add -p FILE_PATH
, and manually select the hunks. - If some of the staged changes were not in the working directory, they cannot be recovered.
Undo: Confirmed a conflict resolution
- Abort the current rebase by running
git rebase --abort
. - Restart the rebase from scratch. Recreate the same rebase list, perform the same message edits, and redo every conflict resolution yourself.
Zoom (2025-02-13)
You can share multiple windows, which will hide switches and other windows but allow multiple apps!
Excel (2025-01-14)
You can reference the same cell in every sheet with =SUM('*'!A1)
. It will probably expand to a sheet range: =SUM(Demian:Susan!A1)
.
cosmopolitan (2024-12-08)
fat binaries, including redbean and greenbean : greenbean might only provide a static page (404 for everything else)
Update: cosmopolitan libc (2025-01-12)
Compile C into a fat binary (run on any platform). https://justine.lol/cosmopolitan/index.html
GIT rebase branch (2024-08-07)
A ── B ── C (<- dev)
── D ── E (<- branch)
git rebase dev {branch} --onto origin/{base}
A ── B ── C (<- dev)
── D ── E (<- branch)
HTML/CSS/JS Playground (2024-07-29)
CSS Transparent Variable Colors (2024-07-29)
color: color-mix(in srgb, var(--color) 50%, transparent);
Statistics (2024-06-27)
Odds : % = chance of happening : F = factor to multiply by (840) : D = GCD(%, F) : = ((% x F) / D) out of (F / D)
Chance of Happening X times : N = X out of N : % = chance of happening : Ways = Combinations(N, K) : = Ways x POW(%, X) x POW(1-%, N-X)
Combinations : K out of N : = N! / (K! x (N-K)!) : shuffles are considered the same : divide Permuations by number of shuffles
Permutations : K out of N : = N! / (N-K)! : shuffles are considered different
Linux: deleting large folders
Using rsync is 3x faster than rm.
mkdir empty
rsync -aP --delete empty/ target/
HTML: <em>
vs <i>
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/em#i_vs._em
<em>
is for emphasis:He did <em>WHAT</em>??
<i>
is for titles and other uses that don't denote emphasis:We watched <i>Good Omens</i> last night.
SQLITE: LIMIT 0,30
- 0 is offset
- 30 is number
7z update option
7z u {archive} {paths}
Will : keep unmatched (wildcards, exclusions) : keep deleted : add new : update newer : ignore older : update same : no anti-items
7z excluding folders
& '....\Program Files\7-Zip\7z.exe' a .\Desktop\Documents.20230612.7z .\Documents\git\ .\Documents\GitHub\ .\Documents\htdocs\ .\Documents\VILLANOVA\ -xr!node_modules -xr!.git -xr!fonts
Javascript: Variable Keys in Maps
let x = "apple";
return { [x]: 10 }; // { "apple": 10 }
return { ...state, [x]: 10 };
return { ...state, apples: { [fav]: 10 } };
Python: venv
2023-04-28
Using Python's built in virtual environment means that all libraries are installed locally, allowing you to edit the libraries if understanding or functionality escapes you.
python -m venv ./.venv ## Creates a virtual env in the current folder
source .venv/bin/activate ## Activates the venv
PHP multi-thread
One
// returns the PID of the child to the parent
// the child will receive a 0
$isChildProcess = pcntl_fork() === 0;
if ($isChildProcess) {
doAsyncTask();
}
Many
// A pool of threads
foreach ($urls as $index => $page) {
if (pcntl_fork() === 0) {
doAsyncTask();
break; // no grandchildren!
}
}
Bash Inputs
From Files
$var = (cat file.txt)
Prompts
echo -n "username: "
read -r user
echo -n -s "password: "
read -r pwd
SQL: Ordered List of Values
2021-04-20
You can quickly get an ordered list of ids or values by joining to a temporary table.
SELECT f.id, dbo.professors.* FROM dbo.professors
JOIN (VALUES (33),(33),(33),(90),(90)) as f(id)
ON f.id = dbo.professors.professor_id;
id professor_id name
33 33 Sir Isaac Newton
33 33 Sir Isaac Newton
33 33 Sir Isaac Newton
90 90 Carl Sagan
90 90 Carl Sagan
Javascript: Forward Declaration
2019-08-20
Many linters check for functions to exist before they're referenced. With circular calling, you need to declare a function before it's defined. TIL this is called forward declaration.
let bind = function bindForward() {};
function ajax(url) {
load(url).then(bind);
}
bind = function bind() {
$("a").click(ajax);
};
Javascript: Destructuring
2019-08-08
When destructuring, JS only assigns the deepest nested keys:
const req = { query: { person: { first: "Chris", last: "Hallberg" } } };
const {
query: {
person: { first, last },
},
} = req;
console.log(query); // undefined
console.log(person); // undefined
console.log(first); // "Chris"
console.log(last); // "Hallberg"
You can also assign names that don't match the keys you're grabbing. Just be careful with your brackets.
const req = { query: { data: "apples" } };
var { query: data } = req; // rename query to data
console.log(data); // { data: "apples" }
var {
query: { data },
} = req; // destruct data from query
console.log(data); // apples
Warning: In browsers, name
seems to be assigned to "[object Object]" somewhere along the line, so be careful.
Javascript: Destructuring as parameters
2019-09-19
I learned today that you can destructure variables as part of a function declaration or as part of a for-of loop:
function getHeight({ height }) {
return height;
}
getHeight({ width: 10, height: 200, depth: 7 }); // 200
const points = [
{ x: 3, y: 4 },
{ x: 5, y: 5 },
];
for (let { x, y } of points) {
console.log(`distSq = ${(x ** 2, y ** 2)}`);
}
// distSq = 25
// distSq = 50
Javascript: Destructuring as default parameters
2019-09-24
It's been a good month for destructuring. Building on the previous revelation, you can set parameter defaults with destructuring.
function showConfig({ tabSize = 2, theme = "Nord" } = {}) {
console.log(`Theme: ${theme}, Tab Size: ${tabSize}`);
}
showConfig({ tabSize: 4, theme: "Monokai" }); // Theme: Monokai, Tab Size: 4
showConfig({ theme: "Monokai" }); // Theme: Monokai, Tab Size: 2
showConfig(); // Theme: Nord, Tab Size: 2
WebVR
Oculus Quest Debugging
2019-09-07
I couldn't find any official way to get debugging info from the Oculus Quest since it only connects over Wi-Fi (if at all) and the SteamVR logs don't pick up anything.
So I dropped a text element into the world and used that as my string log. You can put this element inside the camera if you want it to be visible as a UI element, but I didn't do that.
<a-text id="log" value="Hello!" color="#000" align="center" position="0 2 -5"></a-text>
const logEl = document.getElementById("log");
function log(msg) {
logEl.setAttribute("value", msg);
}
// For updating messages
function debug() {
requestAnimationFrame(debug);
log(blueGun.object3D.matrix.toArray().join(","));
}
requestAnimationFrame(debug);
// For everything else
try {
// do a backflip
} catch (e) {
log(e);
}
Move the World, Not the Camera
2019-09-07
I have a few game concepts that involve pulling the player along or changing their view but trying to override the default WebVR camera is a pain.
If you do manage to get control of the camera (either with groups or with rigs) you need to then manually ensure you draw both eye "cameras" anyway. It's just more work that it's worth when you can move the whole world instead!
A heirachy like this makes this quite easy to do:
- scene
- camera
- world
- hand controllers
- all physical items
Thank you, Stefan Judis for the idea and encouragement.