Skip to content

Instantly share code, notes, and snippets.

<?php
if (!file_exists('path/to/directory')) {
mkdir('path/to/directory', 0777, true);
}
@Dare-NZ
Dare-NZ / jquery_image_preloader.js
Created May 26, 2013 22:41
jQuery image preloader function, pass an url/id and it will run the callback once the image has loaded. Natch.
preload_image : function(image, callback) {
$preload_images = $('#preload-images');
if($preload_images.size() < 1)
$preload_images = $('<div id="preload-images" style="display:none" />').prependTo('body');
$preload_images.append('<img data-id="' + image.id + '"src="' + image.src + '" />');
$preload_images.find(' img[data-id=' + image.id + ']').load(function(e){
if(typeof(callback) == 'function') callback();
});
}
@Dare-NZ
Dare-NZ / pattern_array_merge.php
Last active December 17, 2015 13:19
Does what it says on the tin, merges three arrays to a looping pattern
<?php
$pattern = array(0,0,0,1,2,2,2);
$news_array = array('news1','news2','news3','news4','news5','news6','news7','news8');
$video_array = array('video1','video2','video3','video4','video5','video6','video7','video8');
$photo_array = array('photo1','photo2','photo3','photo4','photo5','photo6','photo7','photo8','photo9','photo10','photo11','photo12','photo13');
$asset_array = array($news_array, $video_array, $photo_array);
$type_count = sizeof($asset_array);
$pattern_count = sizeof($pattern) - 1;
@Dare-NZ
Dare-NZ / useful_regex.txt
Created May 14, 2013 08:29
Useful regex
http://(.[^;,{}?&]+?).domain.com
<?php get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<h1><?php the_title() ?></h1>
<?php the_content() ?>
<?php endwhile; ?>
<?php get_footer(); ?>
@Dare-NZ
Dare-NZ / minify.php
Created May 9, 2013 01:01
A minification php script I created to max out Googles page speed score
<?php
header('Content-Type: text/html; charset=utf-8');
function getAjax($url = false) {
if($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
@Dare-NZ
Dare-NZ / pagespeed.htaccess
Created May 9, 2013 01:00
The .htaccess I used to max out googles page speed score
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 200 hours"
ExpiresDefault "access plus 1 month"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/x-shockwave-flash A3600
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
@Dare-NZ
Dare-NZ / wp_export_csv.php
Created May 9, 2013 00:52
A php file that takes a WP table and saves as a CSV
<?php
require_once('../../../../wp-load.php');
global $wpdb;
$wpdb->show_errors();
$table_name = $wpdb->prefix . "arg_signups";
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
newsletter_install();
@Dare-NZ
Dare-NZ / getAvgLuminance.php
Last active February 13, 2023 07:35
A php function that gets the average brightness of an image
<?php
function getAvgLuminance($filename, $num_samples=30) {
// needs a mimetype check
$img = imagecreatefromjpeg($filename);
$width = imagesx($img);
$height = imagesy($img);
$x_step = intval($width/$num_samples);
$y_step = intval($height/$num_samples);
function createLightbox(lightbox_content, lightbox_class) {
$('body').append('<div class="lightbox-wrap" ><div class="lightbox-position"><div class="lightbox ' + lightbox_class + '" /></div></div>');
$lightbox = $('.lightbox');
$lightbox_position = $('.lightbox-position');
$lightbox_wrap = $('.lightbox-wrap');
$lightbox_wrap.css({
position : 'fixed',
left : 0,