Skip to content

Instantly share code, notes, and snippets.

@troutacular
troutacular / is_localhost
Created May 30, 2015 00:02
PHP - Check if localhost
// Check if we are in a local environment
function is_localhost() {
// set the array for testing the local environment
$whitelist = array( '127.0.0.1', '::1' );
// check if the server is in the array
if ( in_array( $_SERVER['REMOTE_ADDR'], $whitelist ) ) {
@troutacular
troutacular / gist:536c2633a3bf4bb55009
Created July 12, 2015 18:47
WordPress Archives by Year/Month
<?php
global $wpdb;
$limit = 0;
$year_prev = null;
$months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'post' GROUP BY month , year ORDER BY post_date DESC");
foreach($months as $month) :
$year_current = $month->year;
if ($year_current != $year_prev){
if ($year_prev != null){?>
@troutacular
troutacular / gist:048767800182a6caf0bb
Created July 12, 2015 19:13
PNG with SVG Alpha Transparency
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@troutacular
troutacular / attributes
Created July 12, 2015 19:26
CSS Attribute Selectors
/* From Chis Coyier: https://css-tricks.com/attribute-selectors/ */
/*
Attribute exactly equals certain value
<h1 rel="external">Attribute Equals</h1>
*/
h1[rel="external"] { color: red; }
/*
Attribute contains certain value somewhere
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*/
// Enable WP_DEBUG mode
define('WP_DEBUG', true);
@troutacular
troutacular / kaufman-royal-slider
Created October 6, 2015 22:26
Kaufmann bad url for royalslider
orig: <iframe src="https://www.youtube.com/embed/%id%"?rel=1&autoplay=1&showinfo="0" frameborder="no"></iframe>
fix: <iframe src="https://www.youtube.com/embed/%id%?rel=1&autoplay=1&showinfo=0" frameborder="no"></iframe>
@troutacular
troutacular / Package Control.sublime-settings
Created October 21, 2015 22:38
Sublime 3 Package Install
{
"bootstrapped": true,
"in_process_packages":
[
],
"installed_packages":
[
"1337 Color Scheme",
"ACF Snippets",
"Color Highlighter",
@troutacular
troutacular / gist:f083fa913427044631ce
Last active October 27, 2015 20:10
Gulp Directory Structure Options
# Option 1
public/
src/
index.html
img/
js/
app.js
scss/
dist/
@troutacular
troutacular / js-mulitple-timeouts
Last active October 28, 2015 22:04
JS: Multiple Timeouts
/**
* TimeOuts
* ========
*
* Use the functions below to handle mutliple timeouts
*
* New timeout
* timeOuts['ID'] = setTimeout(someFunction('values'), 250);
*
* Clear specific timeout
@troutacular
troutacular / gulp-inject-single-mutiple
Created November 5, 2015 22:17
Gulp Inject - Single and Multiple
gulp.task('scripts_insert', ['vendor_scripts', 'site_scripts'], function () {
var transform = function(filepath, file, i, length) {
return '<script src="' + filepath + '" async></script>';
};
return gulp.src(paths.js.template)
.pipe(inject(gulp.src(paths.js.dest.lib + '/*.js', {read: false}), {addRootSlash: false, transform: transform}))
.pipe(gulp.dest(base_paths.templates));