Skip to content

Instantly share code, notes, and snippets.

@kwd
kwd / gist:3149538
Created July 20, 2012 08:19 — forked from jnaskali/gist:2632774
Bash: extract compressed files
# Extract Files ( https://wiki.archlinux.org/index.php/Bashrc_helpers )
extract() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) tar xvJf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
@kwd
kwd / gist:3149541
Created July 20, 2012 08:19 — forked from jnaskali/gist:2420386
PHP: Match HTML/XML tag with regex
function get_tag( $tag, $xml ) {
$tag = preg_quote($tag);
preg_match_all('{<'.$tag.'[^>]*>(.*?)</'.$tag.'>.'}',
$xml,
$matches,
PREG_PATTERN_ORDER);
return $matches[1];
}
// source http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers
@kwd
kwd / gist:3149543
Created July 20, 2012 08:20 — forked from jnaskali/gist:2358711
Bash: find and replace within multiple files
perl -pi -e 's/find/replace/g' *.php
@kwd
kwd / .htaccess
Created July 20, 2012 08:20 — forked from jnaskali/.htaccess
htaccess: Redirect to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
@kwd
kwd / gist:3149546
Created July 20, 2012 08:20 — forked from jnaskali/gist:2043064
jQuery: Add additional row(s) to table
$('#myTable > tbody:last').append('<tr>...</tr><tr>...</tr>');
@kwd
kwd / gist:3149547
Created July 20, 2012 08:20 — forked from jnaskali/gist:2006108
MYSQL: Select min/max row from each category
SOURCE: http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
+--------+------------+-------+
| type | variety | price |
+--------+------------+-------+
| apple | gala | 2.79 |
| apple | fuji | 0.24 |
| apple | limbertwig | 2.87 |
| orange | valencia | 3.59 |
| orange | navel | 9.36 |
@kwd
kwd / gist:3149549
Created July 20, 2012 08:20 — forked from jnaskali/gist:2000279
CSS: Image Replace
.imageReplace {
border:0;
font: 0/0 a;
text-shadow:none;
background-color:transparent;
}
@kwd
kwd / gist:3149552
Created July 20, 2012 08:20 — forked from jnaskali/gist:2000247
htaccess: Host domain in subdirectory
# IF newdomain AND not subdir THEN redirect to subdir
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
RewriteCond %{REQUEST_URI} !^/domain
Rewriterule ^(.*)$ /domain/$1 [L]
@kwd
kwd / gist:3149555
Created July 20, 2012 08:20 — forked from jnaskali/gist:2000221
htaccess: allow ip through htpassword protection
Deny from all
Order deny,allow
AuthType Basic
AuthName “Restricted”
AuthUserFile /path_to_password/.htpasswd
Require valid-user
Allow from 192.168.1.10
Satisfy Any
@kwd
kwd / gist:3149556
Created July 20, 2012 08:21 — forked from jnaskali/gist:2000188
htaccess: Generic canonization (both no-www2www and www2no-www)
Non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]