Skip to content

Instantly share code, notes, and snippets.

🕶️
Being Awesome

Rob Parham Pamblam

🕶️
Being Awesome
View GitHub Profile
@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();
}
@Pamblam
Pamblam / scale and cover image.js
Created Feb 12, 2020
Functions that take an image uri and scale them to fit or fill a given area;
View scale and cover image.js
function loadImage(src){
return new Promise((r,e)=>{
var img = new Image();
img.onload = ()=>r(img);
img.onerror = e;
img.src = src;
});
}
async function scaleAndFitImage(src, w, h) {
@Pamblam
Pamblam / Selector Generator.js
Created Jan 27, 2020
When run in the console it creates a UI to help find selectors for any element on the page.
View Selector Generator.js
var SelectorGenerator = (function(){
var removed_elements = [];
var selectedElement = null;
var modalBg = null;
var outline = null;
var modal = null;
var running = false;
@Pamblam
Pamblam / Sending Apple push notifications with APN service and .p8 key .php
Created Jan 16, 2020
Sending Apple push notifications with APN service and .p8 key
View Sending Apple push notifications with APN service and .p8 key .php
<?php
// Path to the .p8 file downloaded from apple
// see: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token-based_connection_to_apns#2943371
$authKey = "AuthKey_S97G28Y3JP.p8";
// Team ID (From the Membership section of the ios developer website)
// see: https://developer.apple.com/account/
$teamId = 'asdfasdf';
@Pamblam
Pamblam / shallowSourceSearch.js
Last active Jan 6, 2020
Search source codeof a webpage, including it's linked stylesheets and scripts.
View shallowSourceSearch.js
/**
* Used to find function names or any other strings in sources of a web page.
* @param {string} needle - The string to find
* @param {boolean} caseMatch - Is search case sensitive?
*/
async function shallowSourceSearch(needle, caseMatch = false) {
var matches = [], files = [];
if (!caseMatch) needle = needle.toLowerCase();
const searchFile = async path => {
try {
@Pamblam
Pamblam / git_history_delete
Created Nov 26, 2019
Delete git repo history
View git_history_delete
#!/usr/bin/env bash
REMOTE=$(git config --get remote.origin.url)
rm -rf .git
git init
git add .
git commit -m "Deleted repo history"
git remote add origin $REMOTE
git push -u --force origin master
@Pamblam
Pamblam / csv.js
Created Nov 21, 2019
Parse csv strings per RFC 4180
View csv.js
class CSV{
constructor(data, has_header){
this.has_header = has_header;
this.headers = [];
this.rows = [];
this.headers = [];
this.raw = data;
this._iterator = 0;
this._in_quote = false;
You can’t perform that action at this time.