Skip to content

Instantly share code, notes, and snippets.

View joshuabaker's full-sized avatar

Joshua Baker joshuabaker

View GitHub Profile
@joshuabaker
joshuabaker / extract.php
Created April 22, 2012 19:49
PHP powered ZIP extraction
<?php
// List the ZIP archives that you want to extract
$files = array(
'Archive.zip',
'test.txt.zip',
);
// The directory where the ZIPs should be extracted to
$extract_to = dirname(realpath(__FILE__));
@joshuabaker
joshuabaker / Sanitise for web
Last active January 6, 2022 10:30
Name Mangler snippet to sanitise filenames for web.
[concatenate
[lowercase
[findRegularExpression
"-+"
in [findRegularExpression
"([^a-zA-Z0-9-])"
in [findRegularExpression
"([^A-Z])([A-Z])"
in <name>
replace with "$1 $2"
@joshuabaker
joshuabaker / .htaccess
Created August 17, 2012 15:58
ExpressionEngine .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Prevent access to system directory
RewriteRule ^/?system - [F]
# Prevent access to member pages
RewriteRule ^(index.php)?/?member - [F]
@joshuabaker
joshuabaker / app.js
Created December 12, 2012 17:16
This is about as close as I got to a Path style window based navigation system in Titanium. It works with a few quirks. The UI paradigm was abandoned in favour of something more suitable.
var menuWindow = Titanium.UI.createWindow({
backgroundColor: '#222'
});
var feedWindow = Titanium.UI.createWindow({
backgroundColor: '#fff'
});
var feedContainer = Titanium.UI.createScrollView({
top: 0,
@joshuabaker
joshuabaker / get_tweets.php
Created December 17, 2012 14:27
Incomplete PHP script to scrape twitter.com for a specific user’s timeline. It’s incomplete because the email functionality has not been completed. The idea here was to email it to IFTTT, Evernote or similar for archiving.
<?php
// Enter your Twitter screen name
$screen_name = 'joshuabaker';
// Optionally enter your email address
$from_email = '';
// -------------------------------------------------------------------
@joshuabaker
joshuabaker / mysql_backup.sh
Created January 5, 2013 16:07
Shell script to backup MySQL databases into separate directories/files. Written to backup my local databases to Dropbox but could be easily adapted. The `trash` config item can be used to move files to a specified directory instead of erasing them. Be warned; This script cleans up after itself by decompressing and comparing, via MD5 hashes, the …
#!/bin/bash
#
# Joshua Baker (http://joshuabaker.com/)
# 2013
#
# Backup MySQL databases to separate directories, compressed with GZIP
# and timestamped. Also cleans up after itself, comparing GZIP
# contents via MD5 hashes.

ExpressionEngine 2.x cookies

With the recent 2.5 update, EllisLab have addressed this issue head on. They've added a new set_cookie_end hooks to hijack cookie setting and given us a new Cookie Consent module. You can read more about it in their two blog posts The Cookie Consent Module & EU Cookie Legislation and ExpressionEngine 2.5.0 Released.

The cookies in 2.x are in fact largely the same as 1.x: it's their implementation in the core that is different.

Non essential

@joshuabaker
joshuabaker / image_search.txt
Created January 20, 2013 16:59
Search Google using an image URL.
https://www.google.com/searchbyimage?image_url=http://24.media.tumblr.com/tumblr_lqw7zkGBfw1qa5kr2o1_500.jpg
@joshuabaker
joshuabaker / custom-select.html
Created June 12, 2013 13:20
Works in modern browsers and IE8+. Example: http://jsbin.com/ujovob/1/
<!DOCTYPE html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>
$(function() {
$('.select').each(function() {
var self = $(this),
span = self.children('span'),
slct = self.children('select').change(function() {
span.text(slct.children(':selected').text());
@joshuabaker
joshuabaker / gist:6320601
Created August 23, 2013 15:27
JavaScript test for CSS3 columns. Helpful to avoid having to use Modernizr.
(function() {
var style = document.createElement('div').style;
return ('columnCount' in style || 'MozColumnCount' in style || 'WebkitColumnCount' in style);
}());