Skip to content

Instantly share code, notes, and snippets.

View Pamblam's full-sized avatar
🕶️
Coding

Rob Parham Pamblam

🕶️
Coding
View GitHub Profile
@Pamblam
Pamblam / thread.js
Last active May 18, 2023 13:21
Creating disposable threads in javascript.
// Call the function with at least one parameter.
// The last parameter must be a function that will run on it's own thread
// Any params that are passed to Thread() will be available in the thread function
// The last param of the thread function must be
function Thread(){
return new Promise((resolve, reject)=>{
var args = Array.from(arguments);
var func = args.pop();
@Pamblam
Pamblam / levenshteinMatches.php
Created March 12, 2019 19:03
Find the closest matches to a given word.
<?php
$here = realpath(dirname(__FILE__));
$handle = fopen("$here/wordlist.txt", "r") or die("Couldn't get handle");
$matches = levenshteinMatches($handle, $_GET['word']);
echo "<pre>";
print_r($matches);
@Pamblam
Pamblam / runcmd.php
Last active August 13, 2021 15:24
run a command
<?php
/**
* Run a command with optional stdin
* @param string $cmd - the command to run
* @param string|string[] $stdin - the stdin to feed to the command
* @param string $cwd - the working directory in which to run the command
* @return object containing exit_status, stdout, stderr and elapsed
*/
function runcmd($cmd, $stdin=null, $cwd=null){
@Pamblam
Pamblam / text alignment with gd and .php
Created March 7, 2019 17:12
left, right, center and justify text in an image usign native php functions
<?php
$text = "Your Text Here
this is a test of the things and stuff and things";
$font_size = "12";
$color = "#000000";
$font_file = "/Applications/XAMPP/xamppfiles/htdocs/otcb/app/fonts/OldStreetSigns.ttf";
$background = "#FFFFFF";
$wrap_width = "250";
$alpha = 0;
@Pamblam
Pamblam / fetch examples .js
Last active April 30, 2021 08:36
PRACTICAL EXAMPLES OF FETCH
// GET request with data, JSON response
function getJson(url, params={}){
var url = new URL(url);
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]))
return fetch(url)
.then(res=>res.json())
}
function getText(url, params={}){
@Pamblam
Pamblam / checksum.js
Created February 1, 2019 04:57
generate a checksum for a list of files to ensure project integrity
// This is 3 different files concatted for simplicity.
// USAGE:
// use in browser or via node to generate the checksum
var files = [
'listFiles.js',
'md5.js',
'private.properties',
'project.properties',
'project.xml',
@Pamblam
Pamblam / deep_compare.php
Created January 8, 2019 18:27
compare 2 data structures
<?php
// https://3v4l.org/ZcDnE
/**
* compare 2 data structures.
* - Doesn't handle things like NaN that don't compare.
* - returns true if $b has all the same properties as $a and all properties have same values.
*/
function deepCompare($a, $b){
@Pamblam
Pamblam / color_helper.js
Created January 7, 2019 15:15
get a primary and secondary color name, estimated color name, and brightness from an rgb color and generate random colors
// http://jsfiddle.net/eLbznqx0/
class Color {
constructor(rgb) {
this.rgb = rgb;
this.colormap = {
"110": "yellow",
"101": "magenta",
"011": "cyan",
"100": "red",
@Pamblam
Pamblam / filesystem_search.js
Last active April 3, 2019 13:38
Some file searching examples in node. 1) Find the root of a node project. 2) Recusrively search for a file or directory.
const path = require("path");
const fs = require("fs");
/**
* Find the lowest level parent directory with a
* node_modules directory and a package.json
* @returns {String|false}
*/
function find_root_project(){
@Pamblam
Pamblam / TinyJWT.php
Created November 26, 2018 15:02
JSON Web Tokens for legacy systems
<?php
/**
* JSON Web Tokens (RFC 7519)
* The smallest, simplest possible JWT class.
*
* This version is updated to not use openssl or hash_encrypt for use on an
* older system. If possible use the one linked below instead. Usage is the same.
*
* https://github.com/Pamblam/tinyJWT