Skip to content

Instantly share code, notes, and snippets.

View jrobinsonc's full-sized avatar
🎯
Focusing

Jose Robinson jrobinsonc

🎯
Focusing
View GitHub Profile
@jrobinsonc
jrobinsonc / isDefined.ts
Last active February 13, 2024 15:44
Type Guard Functions for Various Data Types
function isDefined<T>(arg: T | undefined | null): arg is T {
return arg !== undefined && arg !== null;
}
/**
* @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 / 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 / parseMarkdownLinks.js
Last active November 18, 2023 21:44
Markdown Link Parser
@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 <me@joserobinson.com> (https://joserobinson.com/)",
"homepage": "https://gist.github.com/jrobinsonc/d90262c5fad0ad2a253ba46d33cf13b9",
"repository": {
"type": "git",
@jrobinsonc
jrobinsonc / time_elapsed_string.php
Created February 16, 2014 17:35
time elapsed string
<?php
function time_elapsed_string($ptime)
{
$etime = time() - $ptime;
if ($etime < 1)
{
return '0 seconds';
}

PHPExcel Cheat Sheet

Documentation

Snippets

Install.

composer require phpoffice/phpexcel
@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 / dealing-with-www.md
Last active October 27, 2021 16:16
HTACCESS Snippets

Dealing with WWW

Redirect all traffic to use 'www.'

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]