Skip to content

Instantly share code, notes, and snippets.

View tlongren's full-sized avatar
🎯
Focusing

Tyler Longren tlongren

🎯
Focusing
View GitHub Profile
@tlongren
tlongren / theme-options.php
Created May 6, 2011 20:14
theme options page from HTML5Press
<?php
// Default options values
$html5press_options = array(
'back_to_top' => true,
'featured_image_size' => 'large',
'featured_cat' => '',
'num_featured' => '5'
);
@tlongren
tlongren / functions.php
Created June 3, 2011 04:44
load html5press scripts
// Register all the javascript and css we need to accompany those scripts
add_action( 'init', 'html5press_register_scripts' );
function html5press_register_scripts() {
if ( !is_admin() ) {
/**
* Modernizr enables HTML5 elements & feature detects
* For optimal performance, use a custom Modernizr build: www.modernizr.com/download/
*/
wp_enqueue_script( 'modernizr', get_stylesheet_directory_uri() . '/js/modernizr-2.0.min.js', '', '2.0' );
@tlongren
tlongren / maintenance-mode.php
Created July 21, 2011 15:43
Enable WordPress Maintenance Mode
// Enable maintenance mode
add_action('get_header', 'html5press_maintenance_mode');
function html5press_maintenance_mode() {
wp_die('Maintenance, please come back soon.');
}
@tlongren
tlongren / gist:4021002
Created November 5, 2012 23:04
Possible Slow Query Fix
add_filter('pre_get_posts', 'optimized_get_posts', 100);
function optimized_get_posts() {
global $wp_query, $wpdb;
$wp_query->query_vars['no_found_rows'] = 1;
$wp_query->found_posts = $wpdb->get_var( "SELECT COUNT(*) FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')" );
$wp_query->found_posts = apply_filters_ref_array( 'found_posts', array( $wp_query->found_posts, &$wp_query ) );
$wp_query->max_num_pages = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']);
return $wp_query;
@tlongren
tlongren / mysql-ssh-tunnel.txt
Created November 30, 2012 19:37
MySQL Query Browser through SSH Tunnel
~$ ssh root@dev.phandroid.com -L 3306:127.0.0.1:3306 -N
~$ ctrl-z
~$ bg <---background the tunnel
~$ mysql-query-browser
Connect to 127.0.0.1 with credentials from /root/.my.cnf
~$ fg <---bring tunnel to foreground
~$ ctrl-c <---end tunnel
@tlongren
tlongren / gist:5066629
Created March 1, 2013 18:18
Google+ style CSS buttons.
input.button, a.button, span.button {
color: #6e6e6e;
text-decoration: none;
padding: 2px 12px;
position: relative;
display: inline-block;
text-shadow: 0 1px 0 #fff;
-webkit-transition: border-color .218s;
-moz-transition: border .218s;
-o-transition: border-color .218s;
@tlongren
tlongren / worms.pl
Created April 11, 2013 21:45
Scan Apache logs for Nimda or Code Red worm attempts
#!/usr/bin/perl
###########################################################################
# This parses apache access log files for nimda or code red attempts. #
# It will return the number of attempts and will show the last one and #
# who it came from.. #
###########################################################################
# Author: Tyler L. Longren
# E-mail: tlongren@gmail.com
# URL: http://longren.org
#
@tlongren
tlongren / consoleOut.txt
Created April 14, 2013 02:51
Chrome Console with fineuploader
[FineUploader] Processing 1 files or inputs... /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:10
[FineUploader] Sending upload request for 0 /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:10
[FineUploader] xhr - server response received for 0 /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:10
[FineUploader] responseText = /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:10
[FineUploader] Error when attempting to parse xhr response text (SyntaxError: Unexpected end of input) /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:12
qq.log /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:12
qq.FineUploaderBasic.log /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:37
qq.UploadHandler.log /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:48
parseResponse /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:215
onComplete /http://www.longren.org/nexus4/jquery.fineuploader-3.3.1.js:223
@tlongren
tlongren / fine-uploader.js
Created April 19, 2013 02:37
Cross Site Ajax with Fine Uploader
function createUploader() {
var uploader = new qq.FineUploader({
element: document.getElementById('bootstrapped-fine-uploader'),
debug: false,
request: {
endpoint: 'http://sub.domain.com/upload.php',
paramsInBody: false,
params: {
folder: '<?=$folder?>',
mirror: "<?=$_SESSION['u_name']?>"
@tlongren
tlongren / example.php
Last active December 23, 2020 13:32
PHP Clean URL (SLUG) Generator
<?php
$slug = slugit("thank you for visiting");
echo $slug;
// returns: thank-you-for-visiting
?>