Skip to content

Instantly share code, notes, and snippets.

View jrobinsonc's full-sized avatar
🎯
Focusing

Jose Robinson jrobinsonc

🎯
Focusing
View GitHub Profile
/**
* @param time - The time in 24 hours format
* @returns The time in 12 hours format
*/
export function convertTime24to12(time: string): string {
const [hours, minutes]: number[] = time.split(':').map(Number);
const meridiem: 'PM' | 'AM' = hours >= 12 ? 'PM' : 'AM';
return `${hours % 12 || 12}:${minutes
.toString()
.padStart(2, '0')} ${meridiem}`;
@jrobinsonc
jrobinsonc / parseMarkdownLinks.js
Last active November 18, 2023 21:44
Markdown Link Parser
@jrobinsonc
jrobinsonc / PromiseResolution.ts
Last active November 23, 2023 18:53
Promise Resolution with Resolver and Rejector
/**
* Function that returns a promise along with resolver and rejector functions
*
* @template T The type of the resolved value
* @returns {{ promise: Promise<T>, resolver: (arg: T) => void, rejector: (error: Error) => void }}
*/
const PromiseResolution = <T>() => {
let resolver!: (arg: T) => void;
let rejector!: (error: Error) => void;
@jrobinsonc
jrobinsonc / isDefined.ts
Last active August 3, 2024 17:06
Type Guard Functions for Various Data Types
function isDefined<T>(arg: T | undefined | null): arg is T {
return arg !== undefined && arg !== null;
}
@jrobinsonc
jrobinsonc / package.json
Last active August 31, 2023 17:27
Parse CLI arguments
{
"name": "@jrobinsonc/parse-cli-arguments",
"description": "Parse CLI arguments.",
"version": "1.0.0",
"main": "parse-cli-arguments.js",
"license": "ISC",
"author": "Jose Robinson <[email protected]> (https://joserobinson.com/)",
"homepage": "https://gist.github.com/jrobinsonc/d90262c5fad0ad2a253ba46d33cf13b9",
"repository": {
"type": "git",
@jrobinsonc
jrobinsonc / wp-clean.sh
Last active October 29, 2021 20:21
Clean installation of WordPress using WP CLI
# Delete all comments
wp comment delete $(wp comment list --format=ids)
# Delete posts revisions
wp post delete --force $(wp post list --post_type='revision' --format=ids)
@jrobinsonc
jrobinsonc / vscode-phpstan-task.md
Last active September 18, 2021 18:39
VSCode task problemMatcher for PHPStan

Use PHPStan to check your PHP files in VSCode

First, install the composer package: composer require --dev phpstan/phpstan.

Then, add this code to your .vscode/tasks.json:

{
  "label": "PhpStan",
 "detail": "Run PhpStan",
@jrobinsonc
jrobinsonc / regex-patterns.md
Last active September 18, 2021 14:53
Regex patterns
@jrobinsonc
jrobinsonc / vscode-psalm-task.md
Last active September 18, 2021 18:39
VSCode task problemMatcher for Psalm

Use Psalm to check your PHP files in VSCode

First, install the composer package: composer require --dev vimeo/psalm.

Then, add this code to your .vscode/tasks.json:

{
      "label": "Psalm",
 "detail": "Run Psalm",