Skip to content

Instantly share code, notes, and snippets.

View BenJam's full-sized avatar
💭
Will never update this again.

Benjamin Nickolls BenJam

💭
Will never update this again.
  • Bath
View GitHub Profile
@BenJam
BenJam / app.js
Created September 10, 2010 10:01
require.paths.unshift('../../express.js/lib')
require('express')
require('express/plugins')
configure(function(){
use(Logger);
use(Static);
set('root',__dirname);
});
@BenJam
BenJam / app.js
Created September 10, 2010 10:02
//REQUIRE
var express = require('express');
var app = module.exports = express.createServer();
//CONFIG
app.configure(function(){
app.use(express.methodOverride());
app.use(express.bodyDecoder());
app.use(app.router);
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));
@BenJam
BenJam / iOSDate
Created November 28, 2010 16:16
function to return iOS-like date's for lists etc.
function dateMe(date){
var now = new Date();
var d = new Date(date);
if(now.getDay()==d.getDay() && now.getMonth()==d.getMonth() && now.getFullYear()==d.getFullYear()){
return d.toTimeString().match(/\d+:\d+/);
}else if(now.getDay()==d.getDay()+1 && now.getMonth()==d.getMonth() && now.getFullYear()==d.getFullYear()){
return 'Yesterday';
}else{
return d.toLocaleDateString().match(/\d+\s\D{3}/);
}
@BenJam
BenJam / getAuthenticatedUserIniFrame.js
Created December 13, 2010 12:05
Ribbit iFrame oAuth hack
Ribbit.getAuthenticatedUserIniFrame = function(callback, name, windowOptions) {
var win = null;
var gotUrlCallback = function(result) {
console.log(result);
if (result.hasError) {
callback(new Ribbit.RibbitException("Cannot get request token, check application credentials.", 0)); //the request for an oAuth uri has gone wrong
} else {
var timeOutPoint = new Date().getTime() + 300000;
var pollApproved = function() {
var callback = function(val) {
@BenJam
BenJam / YQL.js
Created December 22, 2010 16:20
Using YQL to get around CORS, added Caching bonus!
$.getJSON("http://query.yahooapis.com/v1/public/yql?" +
"q=select%20*%20from%20html%20where%20url%3D%22" +
encodeURIComponent(uri) +
"%22&format=xml'&callback=?",
function(data) {
//do something CORS rules wouldn't let you
}
);
@BenJam
BenJam / smsButton.js
Created January 14, 2011 11:32
smsButton macro for TiddlyWiki/TiddlySpace
/***
|''Name:''|SMSButton|
|''Description:''|Ribbit-bases SMS of Tiddlers|
|''Author:''|BenJam|
|''CodeRepository:''|http://github.com/benjam/tiddlyspace-plugins|
|''Version:''|0.1|
|''Comments:''|Please make comments at http://github.com/benjam/tiddlyspace-plugins |
|''Requires:''|Ribbit plugin for authentication |
|''License:''|[[Creative Commons Attribution-ShareAlike 2.5 License|http://creativecommons.org/licenses/by-sa/2.5/]] |
Usage:
@BenJam
BenJam / Searcher.js
Created January 14, 2011 12:35
Very simple searcher show/hiding elements of the dom onChange for an inpux search box.
//searchController
function search(){
var searchTerm = $('#search').text();
$.forEach(elemement, $('#questions > li')){
if(!element.text().match(searchTerm)>0){
element.hide();
}else(
element.show();
)
@BenJam
BenJam / localStorageDb.js
Created January 31, 2011 07:05
A VERY basic CRUD op for localStorage from code in voice.gtd
function clearDb(){
localStorage.clear();
console.log("Cleared the local storage, god help us all.");
}
//hurrah HTML5 local storage, I'm using a singly linked list as i'm lazy.
function store(msgs){
if(!localStorage){
console.error('Browser doesn\'t support local storage, in memory only I\'m afraid');
return;
@BenJam
BenJam / csstransitions.html
Created March 31, 2011 16:06
my first attempt at hand-coding a 2D plane of windows for a SPA
<!DOCTYPE HTML>
<html>
<head>
<title>css transitions</title>
<script src="jquery-1.5.1.min.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
* {
margin: 0;
@BenJam
BenJam / preloadImages.js
Created April 25, 2011 20:59
Beautifully simple image preloader, sequenced and namespaced
preloadImages = {
count: 0 /* keep track of the number of images */
,loaded: 0 /* keeps track of how many images have loaded */
,onComplete: function(){} /* fires when all images have finished loadng */
,onLoaded: function(){} /*fires when an image finishes loading*/
,loaded_image: "" /*access what has just been loaded*/
,images: [] /*keeps an array of images that are loaded*/
,incoming:[] /*this is for the process queue.*/
/* this will pass the list of images to the loader*/