Skip to content

Instantly share code, notes, and snippets.

View jmillerdesign's full-sized avatar

J. Miller jmillerdesign

View GitHub Profile
@jmillerdesign
jmillerdesign / gist:1553772
Last active August 11, 2023 23:00
Get YouTube video ID from URL
<?php
/*
Works for the following inputs and more:
dQw4w9WgXcQ
http://www.youtube.com/?v=dQw4w9WgXcQ
http://www.youtube.com/embed/dQw4w9WgXcQ
http://www.youtube.com/username#p/c/5555550123/0/dQw4w9WgXcQ
http://www.youtube.com/v/dQw4w9WgXcQ
http://www.youtube.com/v/dQw4w9WgXcQ?feature=autoshare&version=3&autohide=1&autoplay=1
http://www.youtube.com/watch?v=dQw4w9WgXcQ&hd=1&t=26s
@jmillerdesign
jmillerdesign / gist:1604737
Last active March 31, 2019 03:53
Google Maps Geolocation
<?php
/**
* GoogleGeo
*
* Google maps geolocation, to find coordinates of a location
* @author J. Miller
*/
class GoogleGeo {
// GoogleMaps API Key
@jmillerdesign
jmillerdesign / gist:1610602
Created January 14, 2012 07:24
Output a standardized JSON response for an API call
<?php
/**
* Output a JSON response for an API call
*
* @param array $data Data to return
* @param boolean|string $status Status type
* Available status types:
* - true (outputs 'ok')
* - false (outputs 'error')
@jmillerdesign
jmillerdesign / gist:4283199
Created December 14, 2012 06:38
Slugify a string
/**
* Convert a human-readable string into a slug
*
* 'Sample input string!' gets converted to 'sample-input-string'
*
* @param {string} string Source string
* @param {integer} maxLength Maximum length of slug (defaults to 100)
* @return {string} Slug
*/
var convertToSlug = function (string, maxLength) {
@jmillerdesign
jmillerdesign / gist:4489197
Created January 8, 2013 23:51
Download a remote file to a local file
<?php
/**
* Download a remote file to a local file
*
* @param string $url URL to remote file
* @param string $localPathToFile Absolute path to local file where it will be saved
* @return boolean True if file saved successfully
*/
function downloadFile($url, $localPathToFile) {
@jmillerdesign
jmillerdesign / tar_over_ssh.sh
Created January 16, 2014 18:36
Useful to move many files (thousands or millions files) over ssh. Faster than scp because this way you save a lot of tcp connection establishments (syn/ack packets).
tar -cf - relative/path/to/dir | gzip -c | ssh user@example.com 'cd ~/path/to/dir; tar xfz -'
# If using a fast lan (I have just tested gigabyte ethernet) it is faster to not compress the data so the command would be:
# tar -cf - relative/path/to/dir | ssh user@example.com 'cd ~/path/to/dir; tar xf -'
@jmillerdesign
jmillerdesign / gist:8602870
Created January 24, 2014 18:13
Fix Messages on Mac when it stops displaying badge notifications and sound
launchctl unload /System/Library/LaunchAgents/com.apple.soagent.plist && launchctl load /System/Library/LaunchAgents/com.apple.soagent.plist && killall Dock
<?php
App::uses('Model', 'Model');
App::uses('String', 'Utility');
class AppModel extends Model {
/**
* @author Reed Dadoune
* distanceQuery
@jmillerdesign
jmillerdesign / strToInt.php
Created March 23, 2014 08:33
Convert any string to an integer between 0-9
<?php
/**
* Convert any string to an integer between 0-9
*
* @param string $str Any string
* @return integer Integer between 0-9
*/
function strToInt($str) {
preg_match('/\d/', md5((string) $str), $matches, PREG_OFFSET_CAPTURE);
@jmillerdesign
jmillerdesign / gist:9920243
Last active February 17, 2016 22:15
MySQL dump to backup to .gz
# .gz
mysqldump -h 'db.example.com' -u'username' -p'password' 'database' --single-transaction | gzip -c | cat > 'database_backup_2014-01-01.sql.gz'
# .sql
mysqldump -h 'db.example.com' -u'username' -p'password' 'database' --single-transaction > 'database_backup_2014-01-01.sql'