Skip to content

Instantly share code, notes, and snippets.

View mikedugan's full-sized avatar

Mike Dugan mikedugan

View GitHub Profile
@mikedugan
mikedugan / aliases
Created November 7, 2013 14:59
useful bashrc and zshrc stuffs
alias ls='ls -lah'
alias ld='ls -d .*'
alias ez='exec zsh'
alias tf="sftp mike@tick"
alias .2='cd ../../'
alias .3='cd ../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../../'
alias h='history'
alias j='jobs -1'
@mikedugan
mikedugan / sed
Created November 7, 2013 14:58
a bunch of good sed snippets
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
# triple space a file
@mikedugan
mikedugan / r_count_files
Created November 7, 2013 14:58
recursively count files in a dir
$!/bin/bash
find . -type d -print0 | while read -d '' -r dir; do
files=("$dir"/*)
printf "%5d files in directory %s\n" "${#files[@]}" "$dir"
done
@mikedugan
mikedugan / .htaccess
Created November 7, 2013 14:56
useful htaccess stuffs
#single page redirects
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/
#entire site redirect
Redirect 301 / http://newsite.com/
#automatically append or prepend files
php_value auto_prepend_file "/real/path/to/file/functions.php"
php_value auto_append_file "/real/path/to/file/footer.php"
@mikedugan
mikedugan / xml.php
Created November 7, 2013 14:55
general purpose xml reader
<?php
//useful in combination with scandir() function and a foreach loop
if (file_exists('test.xml') {
$xml = simplexml_load_file('test.xml');
$node1 = $xml->node1;
$node2 = $xml->node1->node2;
$n2attr = $node2['someAttr'];
}
@mikedugan
mikedugan / validators.php
Created November 7, 2013 14:55
general purpose validators
<?php
$email = $_POST('email'):
$number = $_POST('number');
$d = $_POST('day');
$m = $_POST('month');
$y = $_POST('year');
$answer = $_POST('answer');
//returns true if the email is valid
@mikedugan
mikedugan / util.php
Created November 7, 2013 14:54
the util.php file
<?php
/**
* util.php
*
* util.php is a library of helper functions for common tasks such as
* formatting bytes as a string or displaying a date in terms of how long ago
* it was in human readable terms (E.g. 4 minutes ago). The library is entirely
* contained within a single file and hosts no dependencies. The library is
* designed to avoid any possible conflicts.
*
@mikedugan
mikedugan / textmessage.php
Created November 7, 2013 14:54
very simple mail-to-sms
<?php
//check http://en.wikipedia.org/wiki/List_of_SMS_gateways for gateways and compile into this function as needed
mail("[email protected]", "", "Your packaged has arrived!", "From: David Walsh <[email protected]>\r\n");
?>
@mikedugan
mikedugan / stringclean.php
Created November 7, 2013 14:53
string cleaner upper
<?php
function clean($value) {
// If magic quotes not turned on add slashes.
if(!get_magic_quotes_gpc())
// Adds the slashes.
{ $value = addslashes($value); }
// Strip any tags from the value.
@mikedugan
mikedugan / social-getter.php
Created November 7, 2013 14:53
gets various data from social networks
<?php
ini_set('error_reporting',E_ALL);
ini_set('display_errors',1);
ini_set('html_errors',1);
function getTweetCount($url) {
$url = urlencode($url);
$twitterEndpoint = "http://urls.api.twitter.com/1/urls/count.json?url=%s";
$fileData = file_get_contents(sprintf($twitterEndpoint, $url));
$json = json_decode($fileData, true);