Skip to content

Instantly share code, notes, and snippets.

View dmgig's full-sized avatar
🏠

Dave M. Giglio dmgig

🏠
View GitHub Profile
@dmgig
dmgig / jQuery.serializeArray.js
Created June 27, 2017 21:11
jQuery serializeArray Change
/**
* take jQuery serializedArray output, and convert the elements which
* should be arrays (ie fieldnames[]) and make them arrays
*/
var fixSerializedArray = function(arr){
var workObj = {};
var newArr = [];
for(var i in arr){
if(workObj.hasOwnProperty(arr[i].name)){
console.log(typeof workObj[arr[i].name]);
@dmgig
dmgig / jquery-plugin-boilerplate.js
Last active April 4, 2017 20:13
jQuery Plugin Boilerplate
/* Fiddle: https://jsfiddle.net/dmgig/1rhetrhb/ */
(function ( $ ) {
var Plugin = function(el){
var plugin = {};
var config = {
backgroundColor: 'blue'
@dmgig
dmgig / tweet-archive.sh
Created February 20, 2017 01:02
Randomly tweet items from an archive.org collection
#! /bin/bash
# use the archive.org api and 't' tool to tweet random items from an archive.org collection
# you'll need two programs preinstalled:
# t: A command-line power tool for Twitter. https://github.com/sferik/t
# jq: A lightweight and flexible command-line JSON processor. https://stedolan.github.io/jq/
COLLECTION='my_collection'
ROWS=1000
ALTVURL='https://archive.org/advancedsearch.php?q=collection:'$COLLECTION'&fl\[\]=identifier,title&rows='$ROWS'&output=json'
@dmgig
dmgig / basic_ffmpeg_commands.md
Last active February 4, 2019 05:34
Basic ffmpeg commands

Some basic ffmpeg commands

convert file from one format to another

ffmpeg -i INPUT.mkv INPUT.mp4

batch convert files in folder

@dmgig
dmgig / grep-for-hexcolors
Created February 3, 2017 18:44
grep for hexcolors
grep -nr '#[a-fA-F0-9]\{3,6\}' .
@dmgig
dmgig / lineMath.js
Last active August 5, 2016 15:20
Get points between two points on simple grid (must be in a straight line)
/**
* Get points between two points on simple grid. Points must be in a straight line.
* Results will include start and end points
*
* @param A array x, y coordinates of one point
* @param B array x, y coordinates of second point
* @return false if points are not in a straight line or if points are the same else
* array of arrays of x, y coordinates between the two points.
*
* fixed so that coordinates can be in any direction from each other.
@dmgig
dmgig / screenshot.sh
Created July 13, 2016 21:30
Take screenshot, remove all older than 2 weeks (mac, requires cron job)
#!/bin/bah
/usr/sbin/screencapture -t jpg -x ~/Desktop/screenshots/$(date +%Y\-%m\-%d\_%H.%M.%S).jpg;
find ~/Desktop/screenshots/ -type f -name '*.jpg' -mtime +14 -exec rm {} \;
@dmgig
dmgig / data.php
Created July 11, 2016 20:32
Simple PHP Cache
<?php
$cacheDir = "cache";
$cacheFile = $cacheDir."/data-cache-".md5($_SERVER['QUERY_STRING']).".json";
$generFile = "data-generate.php";
if(!is_writable($cacheDir)){
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
}
@dmgig
dmgig / api.php
Last active June 14, 2016 00:19
Slim REST API with Local File Storage
<?php
set_include_path ('/home');
require 'vendor/autoload.php';
\Slim\Slim::registerAutoloader();
const DATALOC = "/home/data";
$allowed_objects = ['tests'];
$app = new \Slim\Slim();
@dmgig
dmgig / file_find_replace.sh
Created June 3, 2016 15:56
Find/Replace Inside Files and In Filenames (Mac 10.11)
#!/bin/bash
find /path/to/files -type f -exec sed -i "" 's/oldtext/newtext/g' {} \; # find/repalce inside files
find /path/to/files -type f -name "*" -exec sh -c 'mv "$0" "${0/oldfilenametext/newfilenametext}"' '{}' \; # find and replace in filenames