Skip to content

Instantly share code, notes, and snippets.

View JamesGelok's full-sized avatar
:shipit:

James JamesGelok

:shipit:
View GitHub Profile
@JamesGelok
JamesGelok / git-prev-branch-readme.md
Last active December 8, 2023 14:55
Git shortcut command `git prev-branch [steps]`

Git Previous Branch Command in Node.js

This script provides a custom Git command git prev-branch [steps], allowing you to check out a previously used Git branch by specifying how many steps back in the branch history you wish to go.

Installation

  1. Save git-prev-branch.js to a directory in your PATH (e.g. ~/git-prev-branch.js).
  2. Make the script executable: chmod +x git-prev-branch.js
  3. Rename the script to remove the .js extension: mv git-prev-branch.js git-prev-branch
@JamesGelok
JamesGelok / A
Created November 16, 2023 11:01
O
A
function addLoggingToMethods(classInstance: any) {
const originalMethods = {};
// Store references to the original methods
for (const key of Object.getOwnPropertyNames(classInstance.prototype)) {
const method = classInstance.prototype[key];
if (typeof method === 'function') {
originalMethods[key] = method;
}
}
@JamesGelok
JamesGelok / getterOf.ts
Last active March 8, 2022 14:58
Creates a function to get path from the current collection
import _ from "lodash";
/**
* Creates a function to get path from the current collection.
*
* @example
* ```ts
* const getEnglishTitle = getterOf("title.en")
* const en = getEnglishTitle({ title: { en: "Hi", es: "Hola" } })
* // en === "Hi"
@JamesGelok
JamesGelok / downloadListOfAllNodePackages.js
Created December 27, 2021 21:21
Download List of All Node Pakcages
const fs = require("fs");
const https = require("https");
https
.get("https://replicate.npmjs.com/_all_docs", (resp) => {
let chunkNum = 0;
let stream = fs.createWriteStream("./append.txt", { flags: "a" });
console.log(new Date().toISOString());
// A chunk of data has been received.
console.log(
"%c.",
"display: inline-block; background-image: url('https://tinyurl.com/wrz7rd6j'); background-size: cover; padding: 100px 100px; border: 5px solid transparent; border-image: linear-gradient(to bottom right, #b827fc 0%, #2c90fc 25%, #b8fd33 50%, #fec837 75%, #fd1892 100%); border-image-slice: 1;; font-size: 11px; line-height: 1px; font-family: monospace; color: transparent;",
);
@JamesGelok
JamesGelok / AllObjectPaths.tsx
Created October 6, 2021 18:59
FAILED to extend this to match natural indexing syntax better. Hopefully I can get back to this another time https://stackoverflow.com/questions/12787781/type-definition-in-object-literal-in-typescript
export type AllObjectPaths<TObj extends Readonly<UTIL.ExplicitObjectLiteral>> = TObj extends Record<
infer Key extends AllowedKeys ? AllowedKeys : never,
UTIL.ExplicitObjectLiteral
>
? {
// 1. Create an object literal type (`{}`) from `TObj`, where all the individual
// properties are mapped to a string type if the value is not an object
// or union of string types containing the current and descendant
// possibilities when it's an object type.
// Does this for every property in `TObj` that is a string or number
@JamesGelok
JamesGelok / example.txt
Created September 14, 2021 13:36
example file
example file
@JamesGelok
JamesGelok / DARK-MODE-README.md
Last active August 16, 2021 23:32
Read me with light mode vs dark mode

Example

Hard refresh after changing modes to see the image change from light mode to dark mode:

Image is hosted at this gist.

@JamesGelok
JamesGelok / GitHub-Light-Mode-Dark-Mode.svg
Last active August 16, 2021 23:27
GitHub Light Mode Dark Mode
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.