Skip to content

Instantly share code, notes, and snippets.

View lastguest's full-sized avatar
❄️
I may be slow to respond.

Stefano Azzolini lastguest

❄️
I may be slow to respond.
View GitHub Profile
@lastguest
lastguest / randomToken.js
Created June 25, 2020 13:23
[JS] Generate random, custom length, alphanumerical token
function randomToken(length){
const crypto = require("crypto");
let token = "";
for (let i = length >> 2 ; i >= 0 ; i--) token += crypto.randomBytes(4).readUInt32LE().toString(36);
return token, token.substr(0,length);
}
@lastguest
lastguest / belmont-link.css
Created February 29, 2020 14:41
Castlevania Wiki CSS Link FX
@lastguest
lastguest / memoize.js
Created February 16, 2020 17:06
Memoization decorator for javascript functions
/*
function memoize(f) {
return function(...p){
this._cache = this._cache || []
var k = p.join('|')
return this._cache[k] || (this._cache[k] = f(...p))
}
}
*/
const float lightnessSteps = 4.0;
float lightnessStep(float l) {
/* Quantize the lightness to one of `lightnessSteps` values */
return floor((0.5 + l * lightnessSteps)) / lightnessSteps;
}
vec3 dither(vec3 color) {
vec3 hsl = rgbToHsl(color);
@lastguest
lastguest / colorize-banner.md
Created February 28, 2019 13:56
How to colorize a banner

How to colorize a banner

(cat banner.txt | lolcat -f | sed -e 's/'$(echo "\033")'/\\033/g' | sed -e 's/^/echo -e "/g' | sed -e 's/$/"/g' > banner.ascii.sh) && source banner.ascii.sh
@lastguest
lastguest / .gitlab-ci.yml
Created February 4, 2019 23:46 — forked from foklepoint/.gitlab-ci.yml
Build and Push images to GCP Container Registry with Gitlab CI
image: docker:latest
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
variables:
DOCKER_DRIVER: overlay
GCP_PROJECT_ID: CHANGE-TO-GCP-PROJECT-ID
IMAGE_NAME: image_id
services:
@lastguest
lastguest / caffeina.provisioning.sh
Created September 7, 2018 12:59
[SHELL] Caffeina provisioner script
#!/bin/bash
set +e
echo "–––––––––––––––––––––––––––––––––"
echo "Caffeina provisioner"
echo "–––––––––––––––––––––––––––––––––"
echo "We need your password for privileged installation..."
sudo -Ei echo 'Thanks.'
@lastguest
lastguest / using.php
Last active September 7, 2018 12:58
[PHP] Pull namespace prefix into global scope
<?php
function using($ns) {
static $ns_cache = [];
$ns = trim($ns, '\\');
if (empty($ns_cache[$ns])) {
return spl_autoload_register($ns_cache[$ns] = function($class) use ($ns) {
return class_exists("$ns\\$class", false) && class_alias("$ns\\$class", $class, true);
}, true, false);
} else return false;
@lastguest
lastguest / CLI.php
Created September 7, 2018 12:57
[PHP] Core: CLI
<?php
class CLI {
const
BLACK = "\033[0;30m",
DARKGRAY = "\033[1;30m",
RED = "\033[0;31m",
LIGHTRED = "\033[1;31m",
GREEN = "\033[0;32m",
LIGHTGREEN = "\033[1;32m",
@lastguest
lastguest / RegEx.php
Created September 7, 2018 12:57
[PHP] Core: RegEx
<?php
class RegEx {
protected $pattern;
public function __construct($pattern){
$this->pattern = $pattern;
}
public function test($subject, $flags = 0){