Skip to content

Instantly share code, notes, and snippets.

Avatar

Tyler Longren tlongren

View GitHub Profile
@tlongren
tlongren / theme-options.php
Created May 6, 2011
theme options page from HTML5Press
View theme-options.php
<?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 Jun 3, 2011
load html5press scripts
View functions.php
// 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 Jul 21, 2011
Enable WordPress Maintenance Mode
View maintenance-mode.php
// 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 Nov 5, 2012
Possible Slow Query Fix
View gist:4021002
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 Nov 30, 2012
MySQL Query Browser through SSH Tunnel
View mysql-ssh-tunnel.txt
~$ 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 Mar 1, 2013
Google+ style CSS buttons.
View gist:5066629
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 Apr 11, 2013
Scan Apache logs for Nimda or Code Red worm attempts
View worms.pl
#!/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 Apr 14, 2013
Chrome Console with fineuploader
View consoleOut.txt
[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 Apr 19, 2013
Cross Site Ajax with Fine Uploader
View fine-uploader.js
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 Dec 23, 2020
PHP Clean URL (SLUG) Generator
View example.php
<?php
$slug = slugit("thank you for visiting");
echo $slug;
// returns: thank-you-for-visiting
?>