Skip to content

Instantly share code, notes, and snippets.

View ahamilton9's full-sized avatar

Andrew Hamilton ahamilton9

View GitHub Profile
@ahamilton9
ahamilton9 / promises.js
Created November 8, 2022 19:29
On Promises
new Promise( ( resolve, reject ) => {
resolve('result');
})
.then(() => {console.log('resolved');}, () => {console.log('rejected');})
.catch(() => {console.log('error thrown');});
// resolved
new Promise( ( resolve, reject ) => {
reject('error');
})
@ahamilton9
ahamilton9 / OAuthRequestSigningService.php
Created May 19, 2021 18:22
Generates the Authorization header for OAuth 1.0 signed requests
<?php
namespace App\Services;
use GuzzleHttp\Psr7\Request;
/**
* Generates the Authorization header for OAuth 1.0 signed requests
*
* Heavily based off of the request signing code in Abraham\TwitterOAuth. Built generically, but
@ahamilton9
ahamilton9 / boilerplate.html
Created May 10, 2021 17:02
Real HTML Boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Title</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" integrity="sha512-NhSC1YmyruXifcj/KFRWoC561YpHpc5Jtzgvbuzx5VozKpWvQ+4nXhPdFgmx8xqexRcpAglTj9sIBWINXa8x5w==" crossorigin="anonymous" />
</head>
<body>
//
</body>
@ahamilton9
ahamilton9 / RespondEarly.php
Created February 12, 2021 16:25
Respond early to a PHP request and keep processing
<?php
// Provide a success response early
// Modified from: https://stackoverflow.com/a/42245266
function respondEarly() {
if(session_id()) {session_write_close();}
if(is_callable('fastcgi_finish_request')) {
fastcgi_finish_request();
return;
@ahamilton9
ahamilton9 / prompt-promise.js
Created June 25, 2020 18:18
Prompt Promise for Modals
function promptPromise(message) {
return new Promise(function(resolve, reject) {
// Open the modal and pass it message, resolve, and reject
// Have the modal call resolve(<response if you need one>) on confirm, reject() on cancel
});
}
var button = document.getElementById('action');
button.addEventListener('click', function() {
@ahamilton9
ahamilton9 / bells.js
Created March 30, 2020 19:57
$ to 🕭 Bookmarklet
/**
* Converts dollar signs to bell symbols
* Tom Nook prefers it this way
*/
var node,
nodes = [],
walk = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT,
null,
@ahamilton9
ahamilton9 / junitRender.php
Last active May 29, 2019 15:51
Simple JUnit Renderer
#! /usr/bin/php
<?php
// Load the content
$content = file_get_contents('junit.xml');
$xml = simplexml_load_string($content);
// Include: Tablesort
echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.1.0/tablesort.min.js"></script>';
@ahamilton9
ahamilton9 / authyDump.js
Last active May 7, 2019 14:06
Dump your Authy Chrome Extension Secrets as QR Codes
// Go to Extensions > Developer Mode On > Authy Details > main.html Console
// Once you're there, open the main browswer and decrypt Authy
console.clear();
console.warn('TOTP QR Codes. Authenticate Authy if nothing appears. Copied to clipboard.');
output = '';
appManager.getModel().forEach(function(i){
if(i.markedForDeletion === false){
//output += '"' + i.name + '",' + i.decryptedSeed; // Just the Secret, no QR Code
output += '"' + i.name + '",' + 'https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/'+encodeURIComponent(i.name)+'%3fsecret='+i.decryptedSeed+'%26issuer='+i.accountType+"\n";
}
@ahamilton9
ahamilton9 / clearCaches.bat
Last active October 3, 2017 21:59
Clear Icon and Thumbnail Caches for Windows 10
:: Put into .bat file, right click, Run as Administrator
:: Dev Notes:
:: @ Don't print this command
:: echo off Don't print any further commands, but leave their output
:: >nul Hide this command's output
:: &:: The command has ended ("&") and the rest of the line is a comment ("::")
@echo off
@ahamilton9
ahamilton9 / boilerplate.html
Created April 17, 2017 18:52
True bare-bones boilerplate for HTML5.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Title</title>
</head>
<body>
Content
</body>
</html>