Skip to content

Instantly share code, notes, and snippets.

View bhowe's full-sized avatar

Blake Howe bhowe

View GitHub Profile
@bhowe
bhowe / rewrite-rules-for-handle-file-downloads
Last active August 29, 2015 14:01
Simple way to limit wordpress downloads to users logged in
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ^.*(.zip|.exe)$
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule . /not-loggedin [R,L]
@bhowe
bhowe / .htaccess
Created May 18, 2014 12:32
Wordpress htaccess
Options All -Indexes
<files .htaccess>
Order allow,deny
Deny from all
</files>
<files readme.html>
Order allow,deny
Deny from all
</files>
<files license.txt>
@bhowe
bhowe / twitter-bearer-token
Created May 25, 2014 20:25
twitter bear token request. Remember they never expire will need to plugin your details.
// step 1
// step 1.1 - url encode the consumer_key and consumer_secret in accordance with RFC 1738
$encoded_consumer_key = urlencode($consumer_key);
$encoded_consumer_secret = urlencode($consumer_secret);
// step 1.2 - concatinate encoded consumer, a colon character and the encoded consumer secr et
$bearer_token = $encoded_consumer_key.':'.$encoded_consumer_secret;
// step 1.3 - base64-encode bearer token
$base64_encoded_bearer_token = base64_encode($bearer_token);
// step 2
@bhowe
bhowe / os-browser-sniff
Created May 26, 2014 18:34
good guess on users browser and os
<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];
function getOS() {
global $user_agent;
$os_platform = "Unknown OS Platform";
@bhowe
bhowe / gist:cd5bf1e8e86586ed83dd
Created August 21, 2014 19:39
Disable plugin updates for wordpress
add_filter( 'http_request_args', 'dm_prevent_update_check', 10, 2 );
function dm_prevent_update_check( $r, $url ) {
if ( 0 === strpos( $url, 'http://api.wordpress.org/plugins/update-check/' ) ) {
$my_plugin = plugin_basename( __FILE__ );
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[$my_plugin] );
unset( $plugins->active[array_search( $my_plugin, $plugins->active )] );
$r['body']['plugins'] = serialize( $plugins );
}
return $r;
@bhowe
bhowe / image-loop.php
Created October 28, 2014 23:08
Loop through all the images in a directory and print in a table
<?php
$dir = "*.jpg";
//get the list of all files with .jpg extension in the directory and safe it in an array named $images
$images = glob( $dir );
$count = 0;
echo "<table><tr>";
//extract only the name of the file without the extension and save in an array named $find
foreach( $images as $image ):
$count ++;
@bhowe
bhowe / vhost-manager
Last active August 29, 2015 14:12
Script used to manage vhosts pass it name and document root it will create folder, vhost, and dump in test file in there.
#!/usr/bin/env ruby
#install ruby - https://www.ruby-lang.org/en/documentation/installation/
#-------------------------------------------------------------------------------
#Make a directory to contain all the generated vhost config files:
#sudo mkdir /etc/apache2/extra/vhosts
#Add this line to your /etc/apache2/httpd.conf file:
#Include /private/etc/apache2/extra/vhosts/*.conf
@bhowe
bhowe / gist:235692424f9ad77d0ef2
Created January 9, 2015 01:21
Upload files to amazon s3 with php.
<?php
//This file has been modifed from running code if you have any problems contact info@wiseguystechnologies.com
//no direct access
if (!isset($_POST['sneaky'])) die("DIRECT ACCCESS NOT PERMITTED");
error_reporting(E_ALL);
ini_set('display_errors', '1');
$msg = '';
@bhowe
bhowe / gist:e909b42db3a98edc1951
Last active August 29, 2015 14:13
SQL to clean viagra spam from wordpress posts and pages
#clean your posts
SELECT * FROM wp_posts WHERE post_content LIKE '%<iframe%' and post_status='publish'
UNION
SELECT * FROM wp_posts WHERE post_content LIKE '%<noscript%' and post_status='publish'
UNION
SELECT * FROM wp_posts WHERE post_content LIKE '%display:%' and post_status='publish'
UNION
SELECT * FROM wp_posts WHERE post_content LIKE '%<div%' and post_status='publish'
UNION
@bhowe
bhowe / gist:b74bf68e242783cb5d75
Last active August 29, 2015 14:13
Install Wordpress Via SSH distilled and no frills
#----------------------------------------------------------------------------------------------------------------------
#Install WP via SSH
#-----------------------------------------------------------------------------------------------------------------------
#install db for wp
mysql -u root -p r87g4fFfgFs4
create database databasename;
CREATE USER 'myusername'@'localhost' IDENTIFIED BY 'mypasword';
GRANT ALL ON databasename.* TO 'myusername'@'localhost';