Skip to content

Instantly share code, notes, and snippets.

View doitlikejustin's full-sized avatar

Justin Scarpetti doitlikejustin

View GitHub Profile
@hakre
hakre / dl-file.php
Created January 2, 2012 21:41
Wordpress login to download uploaded files
<?php
/*
* dl-file.php
*
* Protect uploaded files with login.
*
* @link http://wordpress.stackexchange.com/questions/37144/protect-wordpress-uploads-if-user-is-not-logged-in
*
* @author hakre <http://hakre.wordpress.com/>
* @license GPL-3.0+
@drewjoh
drewjoh / custom.js
Created January 27, 2012 13:55
Dynamic (AJAX) loaded Bootstrap Modal (Bootstrap 2.1)
$(document).ready(function() {
// Support for AJAX loaded modal window.
// Focuses on first input textbox after it loads the window.
$('[data-toggle="modal"]').click(function(e) {
e.preventDefault();
var url = $(this).attr('href');
if (url.indexOf('#') == 0) {
$(url).modal('open');
} else {
@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 / 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 / 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 / reset_dns_lion.sh
Created July 26, 2013 20:29
Reset DNS cache in OS X Lion
sudo killall -HUP mDNSResponder
@doitlikejustin
doitlikejustin / disable_core_updates.php
Created August 1, 2013 23:51
Disable WordPress updates (functions.php)
//Diasable Core Updates # 3.0+
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_version_check' );
@doitlikejustin
doitlikejustin / no_www.htaccess
Created August 1, 2013 23:58
To WWW or not to WWW in .htaccess
#Force the no-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
@doitlikejustin
doitlikejustin / gzip.htaccess
Created August 4, 2013 21:37
gzip compression in .htaccess
<IfModule mod_deflate.c>
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
@doitlikejustin
doitlikejustin / browser_caching.htaccess
Created August 4, 2013 21:41
Browser caching using Expires headers in .htaccess
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"