Skip to content

Instantly share code, notes, and snippets.

View u01jmg3's full-sized avatar
🔷
Coding Hard

Jonathan Goode u01jmg3

🔷
Coding Hard
View GitHub Profile
@u01jmg3
u01jmg3 / relative.php
Created February 20, 2017 10:33
From a timestamp return the relative time
<?php
function getRelativeTime($timestamp) {
$difference = strtotime(date('Y-m-d H:i:s')) - strtotime($timestamp);
$periods = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade'];
$lengths = [60, 60, 24, 7, 4.35, 12, 10];
// This was in the past
if ($difference >= 0) {
$ending = 'ago';
// This was in the future
@u01jmg3
u01jmg3 / contextMenu.xml
Last active March 7, 2018 15:45
N++ Customisation
<?xml version="1.0" encoding="UTF-8" ?>
<NotepadPlus>
<ScintillaContextMenu>
<Item MenuEntryName="Macro" MenuItemName="Select Current Line" />
<Item PluginEntryName="HTML Tag" PluginCommandItemName="Select tag contents only" ItemNameAs="Select Tag Contents" />
<Item MenuEntryName="Macro" MenuItemName="Delete Current Line" />
<Item MenuEntryName="Macro" MenuItemName="Remove Duplicate Lines" />
<Item id="0" />
<Item MenuEntryName="Macro" MenuItemName="Title Case" />
<Item MenuEntryName="Macro" MenuItemName="Sentence case." />
@u01jmg3
u01jmg3 / alias.cmd
Last active November 8, 2023 10:30
Pimp up the Windows command prompt
@echo off
:: Clear Microsoft version notice displayed by an
:: Administrator CMD & shells opened by Fork
cls
:: Enable unicode support
chcp 65001 >NUL
if exist .\laravel cd laravel
@u01jmg3
u01jmg3 / particles.html
Last active April 12, 2019 15:31
Particles
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Particles</title>
<style>body { background-color: #1a252f }</style>
</head>
<body>
@u01jmg3
u01jmg3 / sprintf.js
Created December 17, 2016 14:17
sprintf - simple function for formatting strings
/**
* Simple function for formatting strings.
*
* Replaces placeholders with values passed as extra arguments
*
* @param {string} format the base string
* @param ...args the values to insert
* @return {string} the replaced string
*/
function sprintf(format, ...args) {
@u01jmg3
u01jmg3 / is-numeric.js
Created November 22, 2016 11:09
JavaScript equivalent of PHP's `is_numeric()`
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
@u01jmg3
u01jmg3 / sanitize-wysiwyg-input.php
Last active November 14, 2016 10:54
Sanitize WYSIWYG input
<?php
/**
* Removes empty paragraphs, ordered and unordered lists
* Reconciles spacing
* Replaces curly quotes with straight equivalent
*
* @param $html
* @return string
*/
public static function sanitizeWysiwygInput($html)
@u01jmg3
u01jmg3 / random-colours.js
Created November 4, 2016 17:45
Generate random HEX colours
var c = document.getElementsByTagName('canvas')[0];
var x = c.getContext('2d');
x.fillStyle = '#' + ('00000' + (Math.random() * (1 << 24) | 0).toString(16)).slice(-6);
@u01jmg3
u01jmg3 / sync-timer-to-clock-minutes.js
Created October 28, 2016 07:54
Synchronise a timer to fire every new minute on a clock
var secondsRemaining;
let run_function = () => {
//
}
$(document).ready(function(){
run_function();
var time = new Date();
@u01jmg3
u01jmg3 / numbers-to-words.js
Last active October 28, 2016 07:47
Numbers to Words
const names = [{'0':'zero','1':'one','2':'two','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine' },{'0':'ten','1':'eleven','2':'twelve','3':'thirteen','4':'fourteen','5':'fifteen','6':'sixteen','7':'seventeen','8':'eighteen','9':'nineteen'},{'2':'twenty','3':'thirty','4':'forty','5':'fifty','6':'sixty','7':'seventy','8':'eighty','9':'ninety'},['','thousand','million','billion','trillion','quadrillion','quintillion','sextillion','septillion','octillion','nonillion','decillion','undecillion','duodecillion','t#000ecillion','quattuordecillion', 'quindecillion','sexdecillion','septdecillion','octdecillion','novemdecillion','vigintillion']];
let to_words = (s) => {
n = 0;
s = '' + s.split('').reverse();
var ns = s.slice(0, 3);
return (ns.length < 1)?'':to_words(s.slice(3,s.length),n+1)+((ns.length>1)?((ns.length==3&&ns[2]!='0')?names[0][ns[2]]+' hundred '+((ns[1]=='1')?names[1][ns[0]]+' ':(ns[1]!='0')?names[2][ns[1]]+' '+((ns[0]!='0')?names[0][ns[0]]+' ':''):(ns[0]!='0'