Skip to content

Instantly share code, notes, and snippets.

🕶
Being Awesome

Rob Parham Pamblam

View GitHub Profile
@Pamblam
Pamblam / php_check_deprecated_functs
Created Apr 4, 2019
lists usages of deprecated PHP functions (as of PHP7.3)
View php_check_deprecated_functs
#!/usr/bin/env node
// lists usages of deprecated PHP functions (as of PHP7.3)
// Usage: ./php_check_deprecated_functs /path/to/project
const path = require("path");
const fs = require("fs");
const root = process.argv[2];
if(!root){
@Pamblam
Pamblam / php_parent_constructor_checker
Created Apr 4, 2019
Update old-style PHP parent constructor calls
View php_parent_constructor_checker
#!/usr/bin/env node
// Update old-style PHP parent constructor calls
// eg $this->parentConstructor() becomes parent::__construct()
// Usage: ./php_parent_constructor_checker /path/to/project
const path = require("path");
const fs = require("fs");
const root = process.argv[2];
@Pamblam
Pamblam / php_constructor_updater
Last active Apr 3, 2019
Update old-style PHP constructor
View php_constructor_updater
#!/usr/bin/env node
// Update old-style PHP constructor
// Usage: ./php_constructor_updater /path/to/project
const path = require("path");
const fs = require("fs");
const root = process.argv[2];
if(!root){
@Pamblam
Pamblam / levenshteinMatches.php
Created Mar 12, 2019
Find the closest matches to a given word.
View levenshteinMatches.php
<?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 / extractPhoneNumbers.php
Created Mar 11, 2019
extract us phone numbers from a string
View extractPhoneNumbers.php
<?php
/**
* Extract and format phone numbers from a string
* @param string $str
* @return array
*/
function extractPhoneNumbers($str){
$phones = array();
$p = preg_match_all('/\b\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})\b/', $str, $matches);
@Pamblam
Pamblam / extractCompanyName.php
Created Mar 11, 2019
extract company name from a string
View extractCompanyName.php
<?php
/**
* Given a multiline string, this function returns an array of lines
* that probably contain a company name based.
* https://www.harborcompliance.com/information/company-suffixes
* @param str $str - multiline string
* @param bool $fuzzy - consider common OCR mistakes
* @return array
*/
@Pamblam
Pamblam / runcmd.php
Last active Mar 11, 2019
run a command
View runcmd.php
<?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 Mar 7, 2019
left, right, center and justify text in an image usign native php functions
View text alignment with gd and .php
<?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 Mar 18, 2019
PRACTICAL EXAMPLES OF FETCH
View fetch examples .js
// 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())
}
// POST request with data, JSON response
@Pamblam
Pamblam / checksum.js
Created Feb 1, 2019
generate a checksum for a list of files to ensure project integrity
View checksum.js
// 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',
You can’t perform that action at this time.