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 / slowLoop.js
Last active March 2, 2018 13:59
Run an asynchronous operation on each item in an array, waiting for the previous iteration to complete before doing the next one
/**
* Execute the loopBody function once for each item in the items array,
* waiting for the done function (which is passed into the loopBody function)
* to be called before proceeding to the next item in the array.
* @param {Array} items - The array of items to iterate through
* @param {Function} loopBody - A function to execute on each item in the array.
* This function is passed 3 arguments -
* 1. The item in the current iteration,
* 2. The index of the item in the array,
* 3. A function to be called when the iteration may continue.
@Pamblam
Pamblam / README.md
Last active August 9, 2018 16:58
Seconds to elapsed time in readable English in Javascript, PHP and BASH

Elapsed Time in various languages

Seconds to elapsed time in readable English in:

  • Javascript
  • PHP
  • BASH
@Pamblam
Pamblam / uninstall.sh
Created May 31, 2018 16:00
Helper script to deep uninstall stuff from Mac
#!/usr/bin/env bash
# uninstall
#
# Helper script to deep uninstall stuff from Mac
#
# Usage example 1
# uninstall firefox
# Will find all files installed by firefox and ask for confirmation before removing them
#
@Pamblam
Pamblam / setURLValue.js
Last active May 31, 2018 22:33
Sets the value of a query string parameter
// Sets the value of a query string parameter if it exists else adds it
// keeping hash value and all other values intact
function setQSParam(url, key, value=''){
var qs = url.substr(~url.indexOf("?")?url.indexOf("?")+1:url.length);
var hash = qs.substr(~url.indexOf('#')?qs.lastIndexOf('#'):qs.length);
url = url.substr(0, url.length-hash.length);
qs = qs.substr(0, qs.length-hash.length);
var sep = !qs&&url.substr(-1)!=='?'?'?':!!qs&&url.substr(-1)!=='&'?'&':'';
var added=0,nqs=[],k,v,parts;
@Pamblam
Pamblam / getBrowserName.js
Last active June 4, 2018 20:01
Get the name of the browser in javascript
function getBrowserName(){
var nAgt = navigator.userAgent;
var browserName = navigator.appName;
var nameOffset, verOffset;
if ((verOffset = nAgt.indexOf("Opera")) != - 1) browserName = "Opera";
else if ((verOffset = nAgt.indexOf("MSIE")) != - 1) browserName = "Microsoft Internet Explorer";
else if ((verOffset = nAgt.indexOf("Chrome")) != - 1) browserName = "Google Chrome";
else if ((verOffset = nAgt.indexOf("Safari")) != - 1) browserName = "Safari";
else if ((verOffset = nAgt.indexOf("Firefox")) != - 1) browserName = "Mozilla Firefox";
else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
@Pamblam
Pamblam / make_splash.sh
Created June 13, 2018 17:06
Convert all splash screen images in a cordova project to a simple gradient with a logo overlay scaled to fit inside 80% of the image
#!/bin/bash
# Convert all splash screen images in a cordova project to a
# simple gradient with a logo overlay scaled to fit inside 80% of the image
project=/path/to/cordova/project
logo=/path/to/overlay/img.png
gradient1="rgba(0,99,81,1)"
gradient2="rgba(55,171,106,1)"
@Pamblam
Pamblam / Initial Setup.md
Created June 24, 2018 11:05
Installing And Setting Up Arch Linux to Dual Boot Alongside Window 10

Newb's Guide to installing Arch Next to Pre-installed Windows 10

The steps I took to dual boot Arch Linux alongside the preinstalled Windows 10 that came with my new Lenovo Ideapad. I used Ubuntu exclusively for the last 6 years so I'm Window's illiterate. I don't know a whole lot about the inner workings of Linux either.

Pre-Instllation Steps

Prepare the preinstalled Windows to share the system.

Verify the boot mode...

<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<canvas id="canvas" style="height:90vh;"></canvas>
<script>
@Pamblam
Pamblam / astro.js
Created July 17, 2018 16:15
Calculate moon phase, sun declination and julian date for any given date. Requires protodate.js
// requires protodate.js
// https://github.com/Pamblam/protodate
function calculateJulianDay(date){
var y = parseInt(date.format("Y"));
var m = parseInt(date.format("n"));
if(m === 1 || m === 2){
y -= 1;
m += 12;
}
@Pamblam
Pamblam / apk_rollback.sh
Last active August 1, 2018 14:49
Rollback to an old version of an app on the playstore by downloading the old apk and changing the version number
#!/bin/bash
# Download old version of SDK to rollback to
# Google Developer Console =>
# App releases =>
# Production (Manage Production) =>
# Release history =>
# Select the version that you want =>
# Click on Download button.