Skip to content

Instantly share code, notes, and snippets.

View dmgig's full-sized avatar
🏠

Dave M. Giglio dmgig

🏠
View GitHub Profile
@dmgig
dmgig / php_encryption_test.php
Created April 20, 2016 18:48
PHP Public Key Encryption
<?php
$publicKey = "file://Users/dgiglio/.ssh/mykey.pem";
$plaintext = "String to encrypt";
openssl_public_encrypt($plaintext, $encrypted, $publicKey);
echo $encrypted; //encrypted string
@dmgig
dmgig / timeline_table.php
Created April 20, 2016 18:50
Timeline Table
<?php
require 'common.php';
// base dateframes
$dateframe = new DateFrame('1960-01-01', '1974-04-01');
$dateframes = $dateframe->asMonthIntervals(1);
$dateframes = array_reverse($dateframes);
@dmgig
dmgig / eol-cat.sh
Last active April 20, 2016 20:25
fix line endings during cat
cat windows-EOL.txt | tr '\r' '\n'
@dmgig
dmgig / grep_ip.sh
Last active June 1, 2016 19:03
grep regex for ip addresses
#!/usr/bin/env bash
tail -n 1000 /var/log/my.log | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"
@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
@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 / 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 / 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 / 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 / grep-for-hexcolors
Created February 3, 2017 18:44
grep for hexcolors
grep -nr '#[a-fA-F0-9]\{3,6\}' .