Skip to content

Instantly share code, notes, and snippets.

View Pamblam's full-sized avatar
🕶️
Coding

Rob Parham Pamblam

🕶️
Coding
  • Our Town America
  • Tampa Bay, Florida
View GitHub Profile
@Pamblam
Pamblam / tapswipe.js
Created September 27, 2017 19:42
listen for tap and swipe on the same element, simultaneously...
/**
* listen for tap and swipe on the same element, simultaneously...
*/
let tapSwipe = (()=>{
var lastSwipe = 0;
return (ele, cb) => {
let isAction = false;
let downAt = {x:0, y:0};
let downHandler = (e) => {
downAt = {x: e.touches[0].pageX, y: e.touches[0].pageY};
@Pamblam
Pamblam / imgur_anon_upload.php
Last active November 16, 2017 15:30
PHP function for anonymous image upload using the Imgur API.
<?php
/**
* Anonymous image upload using imgur API
* @param $client_id String - The client ID (See: https://imgur.com/account/settings/apps)
* @param $img_path String - The path to image to be uploaded (or tempname of uploaded image)
* @return String|Bool - false on failure or URL of uploaded image on success.
*/
function imgur_anon_upload($client_id, $img_path){
if(!file_exists($img_path) || !is_readable($img_path)) return false;
@Pamblam
Pamblam / upScroller.js
Created January 19, 2018 17:05
This is a class that adds items to the top of an element when it's scrolled up, starting the element at the very bottom. See: https://stackoverflow.com/a/48346059/1444609
class upScroller{
constructor(ele = document.body){
this.renderedItems = 0;
this.ele = ele; var i=0;
this.initBoxContents();
}
initBoxContents(){
if(this.ele.scrollHeight == this.ele.clientHeight)
@Pamblam
Pamblam / isClickable.jQuery.js
Created January 31, 2018 02:54
Determine if the first element in a jQuery set is accessible to the user
/**
* Determine if the first element in a jQuery set is accessible to the user
*/
$.fn.isClickable = function() {
if (!this.length) return false;
const getZIndex = e => {
if (e === window || e === document) return 0;
var z = document.defaultView.getComputedStyle(e).getPropertyValue('z-index');
if (isNaN(z)) return getZIndex(e.parentNode);
@Pamblam
Pamblam / arrayChunk.js
Last active February 1, 2018 13:23
Break an array into chunks of a certain size
/**
* Break an array into chunks of a certain size
* @param {array} array - The array to break up
* @param {integer} chunksSize - The size of each subarray
* @returns {Array} - Array of subarrays
*/
function arrayChunk(array, chunksSize){
var i, j, chunk = chunksSize, chunks = [];
for (i = 0, j = array.length; i < j; i += chunk) {
chunks.push(array.slice(i, i + chunk));
<?php
/*
* Makes an HTTP request via GET or POST, and can download a file
* @returns - Returns the response of the request
* @param $url - The URL to request, including any GET parameters
* @param $params - An array of POST values to send
* @param $filename - If provided, the response will be saved to the
* specified filename
*/
@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 / Versionator.java
Last active April 2, 2018 17:55
Check for updates in the play store and prompt user to update if an update is available.
package com.geneticcoder.Versionator;
// Check here for updates: https://gist.github.com/Pamblam/53cb2b1c90dea09d4872084956d17b5c
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.AsyncTask;
/**
* Format a date using PHP date shorthand
* @param {Date} date - A Javascript Date object
* @param {String} format - The format of the outputted date
* @returns {String} - The formatted date
*/
function formatDate(date, format) {
if (isNaN(date.getTime())) return "Invalid Date";
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
@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
#