Skip to content

Instantly share code, notes, and snippets.

View jmillerdesign's full-sized avatar

J. Miller jmillerdesign

View GitHub Profile
@jmillerdesign
jmillerdesign / strToInt.js
Last active August 29, 2015 14:01
Convert any string into an integer
/**
* Convert any string into an integer
*
* @param {string} str Input string
* @return {integer} Integer
*/
var strToInt = (function () {
var map = {};
var size = 0;
var hash;
@jmillerdesign
jmillerdesign / slug.php
Created May 10, 2014 05:07
Slugify a string
<?php
/**
* Convert a human-readable string into a slug
*
* 'Sample input string!' gets converted to 'sample-input-string'
*
* @param string Source string
* @return string Slug
* @author Cake Development Corporation (http://cakedc.com)
@jmillerdesign
jmillerdesign / gist:3df27b72a2b7bcd946ed
Last active March 30, 2021 01:55
Embed a YouTube video responsively
<style>
.embed-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
overflow: hidden;
max-width: 100%;
height: auto;
}
.embed-container iframe,
@jmillerdesign
jmillerdesign / gist:11159841
Created April 21, 2014 23:18
Restore default file & folder permissions
find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;
@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'
@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);
<?php
App::uses('Model', 'Model');
App::uses('String', 'Utility');
class AppModel extends Model {
/**
* @author Reed Dadoune
* distanceQuery
@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
@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 [email protected] '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 [email protected] 'cd ~/path/to/dir; tar xf -'
@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) {