Skip to content

Instantly share code, notes, and snippets.

View doitlikejustin's full-sized avatar

Justin Scarpetti doitlikejustin

View GitHub Profile
@doitlikejustin
doitlikejustin / unzip.php
Created July 26, 2013 18:16
Unzip ZIP file on server using PHP
<?php
$zip = new ZipArchive;
$res = $zip->open('./unzip.zip');
if($res === TRUE) {
$zip->extractTo('./');
$zip->close();
echo 'woot!';
} else {
echo 'doh!';
@doitlikejustin
doitlikejustin / import_sql.sh
Created July 26, 2013 18:20
Import SQL file on server into MySQL database
mysql -u USERNAME -p -h localhost DATABASE < FILENAME.sql
@doitlikejustin
doitlikejustin / wordpress.htaccess
Created July 26, 2013 18:27
Default WordPress .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
@doitlikejustin
doitlikejustin / check_ip_if.php
Created July 26, 2013 18:28
Check IP address if() statement
<?php if($_SERVER['REMOTE_ADDR'] == '999.999.999.999'): ?>
<?php /* HTML and other goodness goes here */ ?>
<?php endif; ?>
@doitlikejustin
doitlikejustin / string_to_slug.php
Created July 26, 2013 18:30
Convert string to slug
<?php
// will convert "Hello World!" to "hello-world"
function to_slug($string)
{
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
}
?>
@doitlikejustin
doitlikejustin / change_wp_url.sql
Created July 26, 2013 20:06
WordPress SQL replace old URL with new URL
SET @prefix = "wp_";
SET @old = "http://www.old.com";
SET @new = "http://www.new.com";
SET @sql1 = CONCAT('UPDATE ', @prefix, 'options SET option_value = REPLACE(option_value,?,?)');
SET @sql2 = CONCAT('UPDATE ', @prefix, 'posts SET guid = REPLACE(guid,?,?)');
SET @sql3 = CONCAT('UPDATE ', @prefix, 'posts SET post_content = REPLACE(post_content,?,?)');
PREPARE update1 FROM @sql1;
PREPARE update2 FROM @sql2;
@doitlikejustin
doitlikejustin / delete_svn_dirs.sh
Created July 26, 2013 20:28
Delete all .svn directories
find ./ -name ".svn" | xargs rm -Rf
@doitlikejustin
doitlikejustin / reset_dns_lion.sh
Created July 26, 2013 20:29
Reset DNS cache in OS X Lion
sudo killall -HUP mDNSResponder
@doitlikejustin
doitlikejustin / sql_replace.sh
Created July 26, 2013 20:30
Simple SQL REPLACE
UPDATE _table_ SET _field_ = REPLACE(_field_, '_old_value_', '_new_value_');
@doitlikejustin
doitlikejustin / change_user_group.sh
Created July 30, 2013 17:17
Changing Directory User and Group
chown -R USERNAME:psacln /var/www/vhosts/DOMAIN/httpdocs/ && chown USERNAME:psaserv /var/www/vhosts/DOMAIN/httpdocs/