Skip to content

Instantly share code, notes, and snippets.

Alan Edwardes alanedwardes

Block or report user

Report or block alanedwardes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alanedwardes
alanedwardes / Encoder.js
Created Jun 24, 2012
Simple JS object to encode text to its unicode character references for URLs and HTML. Makes displaying text and passing data to a server super safe.
View Encoder.js
/////////////////
// HTML EXAMPLES
/////////////////
// Encoder.html_entities("常用國字標準字體表"); "常用國字標準字體表"
// Encoder.html_entities("%"); "%"
// Encoder.html_entities("Pig: €3.99 (£6.77)"); "Pig: €3.99 (£6.77)"
/////////////////
// URL EXAMPLES
/////////////////
// Encoder.url_encode("常用國字標準字體表"); "%u5E38%u7528%u570B%u5B57%u6A19%u6E96%u5B57%u9AD4%u8868"
@alanedwardes
alanedwardes / iTunesGenreMap.php
Created Apr 4, 2012
Maps iTunes genre ID to a string.
View iTunesGenreMap.php
<?php
function iTunesGenreMap($code)
{
// iTunes Genre ID to string map
// Compiled from this page: http://code.google.com/p/php-reader/wiki/ISO14496
$code = ltrim($code, 0);
switch($code)
{
case 1:
return 'Blues';
View gist:1518434
length = Math.max(canvas.width, canvas.height);
// Make sure the rays are bigger than the canvas
midx = canvas.width / 2, midy = canvas.height / 2;
// Get the mid point of our canvas
var d = 12;
// how many rays (or divisions)
for(i = 0;i < d;i++){
angle = (Math.PI * 2 / d) * i;
View getXY.js
function getXY(x, y, d, a){
return {
x: x + d * Math.cos(a),
y: y + d * Math.sin(a)
};
};
@alanedwardes
alanedwardes / rays.js
Created Dec 24, 2011
Generates animated sun rays using HTML canvas
View rays.js
var rays = new Object({
canvas: false,
context: false,
interval: false,
offset: 0,
init: function(id, colour1, colour2){
this.canvas = document.getElementById(id);
this.context = this.canvas.getContext('2d');
this.canvas.style.background = colour1;
this.context.fillStyle = colour2;
@alanedwardes
alanedwardes / hexToRGB.js
Created Dec 15, 2011
JavaScript function to convert a hexadecimal colour representation to an RGB object, {r: n, g: n, b: n}
View hexToRGB.js
function hexToRGB(hex){
hex = hex.replace('#', '');
return {
'r': parseInt(hex.substring(0, 2), 16),
'g': parseInt(hex.substring(2, 4), 16),
'b': parseInt(hex.substring(4, 6), 16)
}
}
View gist:1420726
<form action="/posts/xyz/#comment-form" method="post">
<input type="text" name="email" value="" id="email_field" style="display:none" />
<div>
<label for="cname">Name <small>(If it's not real, it better be cool)</small></label>
<input name="name" type="text" id="cname" class="text" value=""/>
</div>
<div>
<label for="jerry_the_spider">Email <small>(optional, used for <a target="_blank" href="http://www.gravatar.com/">your avatar</a>)</small></label>
<input name="jerry_the_spider" type="text" id="jerry_the_spider" class="text" value=""/>
</div>
@alanedwardes
alanedwardes / gist:1396447
Created Nov 26, 2011
Evil bit of SQL to get the most recent posts from WordPress with media, the link to the media and the post ID.
View gist:1396447
SELECT posts.post_title, posts.ID post_id, media.ID media_id
FROM $wpdb->posts media
JOIN $wpdb->posts posts
ON posts.post_content LIKE CONCAT('%', media.guid, '%')
WHERE media.post_type = 'attachment'
AND posts.post_type = 'post'
AND posts.post_status = 'publish'
GROUP BY posts.ID
ORDER BY media.post_date DESC
LIMIT 0, 9
@alanedwardes
alanedwardes / mint.php
Created Oct 9, 2011
WordPress plugin to add mint to the blog's header (if the user isn't logged in) and to add a "Statistics" menu option with Mint in an iframe.
View mint.php
<?php
/*
Plugin Name: WordPress Mint Intergration
Description: Adds mint to the site's header (if the user isn't logged in), adds a "Statistics" menu option with Mint in an iframe.
Author: Alan Edwardes
Author URI: http://alan.edward.es/
Version: 1.0
*/
function add_mint_javascript(){
View AddEvent.js
// By Alan Edwardes - http://alanedwardes.com/contact
// Licensed under The GNU General Public License (GPL)
// -------------------------------------------------------------
// A simple events wrapper function for adding events that works
// cross browser, and allows you to use the first parameter of
// the callback function as a reference to the object that the
// event was fired from, which replaces IE's lack of support
// for the "this" variable.
//
// Ex. Usage:
You can’t perform that action at this time.