Skip to content

Instantly share code, notes, and snippets.

View collegeman's full-sized avatar

Aaron Collegeman collegeman

View GitHub Profile
<!--- establish parameters --->
<CFSET username = "bob" />
<CFSET public_key = "FT39JK3F" />
<CFSET private_key = "fj39dfjki302kjdf99j3lkdf902j389a" />
<!--- epoch expressed in seconds --->
<CFSET timestamp = round( (now().getTime()+getTimeZoneInfo().utcTotalOffset) / 1000) />
<CFSET to_hash = username & public_key & private_key & timestamp />
<!--- md5 hashsum of username and keys --->
<CFSET hashsum = lcase(hash(to_hash)) />
<!--- SSO url --->
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js"></script>
</head>
<body onload="console.log(this);">
<script>
// make sure our scripting is isolated
(function() {
// copy reference to existing onload event handler
// make sure our scripting is isolated
(function() {
// copy reference to existing onload event handler
var onload = window.onload;
// create our own onload event handler
window.onload = function() {
// call the other onload event
if (typeof onload == 'function') {
onload();
}
<!-- how to pull JSON from another domain and use it to generate HTML -->
<div id="container"></div>
<script>
$.ajax({
// path to the JSON file
url: 'http://yourdomain.com/data.json',
// use JSONP to get around cross-domain restrictions, see: http://api.jquery.com/jQuery.ajax/
dataType: 'jsonp',
// upon download
success: function(data) {
@collegeman
collegeman / add-to-functions.php
Created January 18, 2011 01:11
Sort two WordPress posts by the value of a meta key, "event-date," assumed to be a string parseable by strtotime
function sort_by_event_date($post1, $post2) {
$date1 = strtotime(get_post_meta($post1->ID, 'event-date', true));
$date2 = strtotime(get_post_meta($post2->ID, 'event-date', true));
// I've reversed this now so that it sorts in descending order, newest first:
return ($date1 == $date2) ? 0 : ($date1 > $date2 ? -1 : 1);
}
<?php
$posts = get_posts(array('category_name' => 'events', 'numberposts' => 8));
usort($posts, 'sort_by_event_date');
foreach($posts as $post) {
$event_date = strtotime(get_post_meta($post->ID, 'event-date', true));
$M = date('M', $event_date);
$d = date('d', $event_date);
$Y = date('Y', $event_date);
setup_postdata($post);
<?php
public function calcLevel($new_pts, $old_pts) {
$cur_pts = Member::getPoints($this->member_id, $old_pts);
if (!is_numeric($cur_pts)) {
$cur_pts = 0;
// sometimes we use $cur_pts = is_numeric($cur_pts) ? $cur_pts : 0;
}
if ($new_lev->level_id > $cur_lev) {
$this->new_lev = $new_lev->level_id;
@collegeman
collegeman / titanium-logging.js
Created February 14, 2011 03:19
I found this log() function very useful for exploring the Titanium API. The WebKit console is simply the best way to explore JavaScript objects. This implementation of a global log() function makes it easy to use the WebKit logger to inspect any object, i
(function(T, api) {
function log() {
if (window.console) {
window.console.log.apply(null, Array.prototype.slice.call(arguments));
} else {
api.prototype.log.apply(null, Array.prototype.slice.call(arguments));
}
}
T.UI.getMainWindow().showInspector(true);
@collegeman
collegeman / twitter-stream.php
Created February 25, 2011 19:22
Sampling Twitter stream
<?php
$keyword = '';
$username = '';
$password = '';
$ch = curl_init("http://stream.twitter.com/1/statuses/filter.json?track={$keyword}");
curl_setopt_array($ch, array(
CURLOPT_READFUNCTION => 'read_twitter_stream',
CURLOPT_USERPWD => '{$username}:{$password}',
CURLOPT_TIMEOUT => 0
@collegeman
collegeman / functions.php
Created February 26, 2011 22:56
The best way to hide the new WordPress admin bar from subscribers and other non-administrative users
<?php
// in functions.php
show_admin_bar(!is_admin() && current_user_can('edit_posts'));