Skip to content

Instantly share code, notes, and snippets.

Avatar
🕶️
Being Awesome

Rob Parham Pamblam

🕶️
Being Awesome
  • Our Town America
  • Tampa Bay, Florida
View GitHub Profile
@Pamblam
Pamblam / isSafeQuery.md
Created Jun 4, 2021
Check if an arbitrary SQL query is safe to run on the database.
View isSafeQuery.md

Note: This is posted as an answer to a StackOverflow question. Keeping it here for my own convenience.

I wanted a safer, more robust solution that didn't involve fully tokenizing query. Based on my experience writing SQL parsers (here, and here), I can say this solution is pretty bulletproof without having to use a full-featured query parser.

This is the best answer because:

  • It does not require a new SQL user with limited permissions
  • It does not require a new DB connection with limited permissions
  • It does not break if the query contains a string or a comment with the word "delete"
  • It allows complex queries with nested queries
@Pamblam
Pamblam / fontawesome_5_icons.json
Created May 3, 2021
All free Fontawesome 5 icon classnames and titles.
View fontawesome_5_icons.json
[
{
"class": "fab fa-500px",
"text": "500px"
},
{
"class": "fab fa-accessible-icon",
"text": "Accessible Icon"
},
{
@Pamblam
Pamblam / path parse.php
Created Feb 1, 2021
parse paths in php
View path parse.php
class fpParser{
public $path;
public $basename;
public $basename_noext;
public $basename_noext_noiteration;
public $extention;
public $directory_sep;
public $dir_tree;
public $iteration;
View animatedGuage.js
var img = document.getElementById('guage');
var percentDisplay = 73;
makeAnimatedGuage(img, percentDisplay);
function makeAnimatedGuage(img, percentDisplay, line_width = 10, guage_width = 500, font_size = 20, font_face = 'Arial'){
var current_pct = 0;
var target_pct = 65;
img.src = makeGuage(current_pct);
@Pamblam
Pamblam / loadAsset.js
Created Oct 14, 2020
Given a URL for a JS or CSS file, this function will load the asset and return a Promise which will reject on error or resolve when the asset is loaded.
View loadAsset.js
/**
* Given a URL for a JS or CSS file, this function will
* load the asset and return a Promise which will reject
* on error or resolve when the asset is loaded.
*/
function loadAsset(url){
return new Promise(async (resolve, reject)=>{
var asset;
if(url.trim().substr(-3).toLowerCase() === '.js'){
asset = document.createElement('script');
@Pamblam
Pamblam / createTextImage.js
Created Jul 21, 2020
Generate an image of text
View createTextImage.js
/**
* Generate an image of text
* @param {String} text - The text to convert to an image
* @param {Object} options - The rendering options of the text and image
* @property {String} options.color - The color of the text
* @property {Number} options.font_size - The size of the text in pixels
* @property {String} options.font_face - The font face to use
* @property {String} options.font_style - The font style (normal|italic|oblique|initial|inherit)
* @property {String} options.font_variant - The font variant (normal|small-caps|initial|inherit)
* @property {String|Number} options.font_weight - The font weight (normal|bold|bolder|lighter|number|initial|inherit)
@Pamblam
Pamblam / detect media queries.js
Created Jun 12, 2020
detect all media queries in use..
View detect media queries.js
(async function(d){
console.clear();
const styles = [];
const stylesheets = d.querySelectorAll("link[rel='stylesheet'][href]");
// get all stylesheet urls
const stylesheet_urls = [...stylesheets].map(s=>s.href);
// fetch the contents of the stylesheets
const ss_promises = stylesheet_urls.map(href=>{
return fetch(href).then(s=>s.text()).then(s=>{
return {
@Pamblam
Pamblam / getUnusedStyles.js
Last active Jun 5, 2020
Puts a message in the console for every loaded CSS style that is not being used on the page.
View getUnusedStyles.js
(async function(d){
console.clear();
const styles = [];
const stylesheets = d.querySelectorAll("link[rel='stylesheet'][href]");
// get all stylesheet urls *that are on the same domain*
const stylesheet_urls = [...stylesheets].map(s=>s.href).filter(uri=>{
uri1 = new URL(uri);
var uri2 = new URL(window.location.href);
if(uri1.host !== uri2.host) return false;
if(uri1.port !== uri2.port) return false;
View Switching to SSH.md

Switching a repo from http to ssh

Check for existing keys

ls -al ~/.ssh

Generate new key (substitute email)

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
View body composition calculations.js
class BodyMetrics {
constructor(params) {
Object.keys(params).forEach(key => {
this[key] = params[key];
});
this.results = {};
this.bodyFatPercentage();
this.bodyFatWeight();
this.bodyFatDensity();
}