Skip to content

Instantly share code, notes, and snippets.

View dandean's full-sized avatar
🌧️
It's raining.

Dan Dean dandean

🌧️
It's raining.
View GitHub Profile
var TitleWrapper = function()
{
/* .
. Blah blah blah
. */
var onMute = function()
{
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="soundmanager/script/soundmanager2.js"></script>
<script type="text/javascript" src="index.js"></script>
<title>Grrrr!</title>
</head>
<body>
<p id="debug1">Nothing works! &hearts;</p>
app.get("/users/:username/sites", function(req, res) {
riak.add("sites")
.map(predicates.findByPropertyValue, ["owner", req.params.username])
.run(function(e, result, meta) {
if (e) {
res.fail("There was an error while getting sites for this user.", meta.statusCode);
return;
}
res.ok(result, meta.statusCode);
var App = function() {
var musicLoopFlag = 0,
delay = null,
frameNumber = 0,
afterFirstLoop = 0,
self = this;
this.setup = function() {
var assetCount = 59; // One for each image in the animation, plus one for the intro and one
// for the loop of the song
@dandean
dandean / gist:745284
Created December 17, 2010 17:07
Array.slice.js
// ES5 Array.slice polyfill.
// Lets you easily turn array-like objects into actual arrays:
// Array.slice(arguments).map(...);
if (!Array.slice) {
Array.slice = function(array, start, end) {
return Array.prototype.slice.call(array, start, end);
};
}
@dandean
dandean / riak-bucket-prefixing.js
Created December 10, 2010 21:35
Random idea around extending riak-js to support automatic prefixing of bucket names. Could come in handy for a riak database in use by multiple applications.
var riakClient = require("riak-js/client");
var riakHttpClient = require("riak-js/http_client");
riakClient.prototype.bucketPrefix = "";
riakClient.prototype.getBucketName = function(name) {
var prefix = "";
if (this.bucketPrefix) prefix = this.bucketPrefix + "_";
return prefix + name;
};
@dandean
dandean / dynamically-named getters and setters.js
Created October 24, 2010 04:21
Creating dynamically named getters and setters on an object
/**
* And this is the winning version thanks to @gf3. Using Object.keys().forEach()
* is faster than for..in as benchmarked by @creationix here:
* https://gist.github.com/75d0278890e6c5833add
* According to @jdalton, this is because for..in looks up the prototype chain
* while Object.keys looks at own keys.
**/
var obj1 = {
a: "a",
@dandean
dandean / gist:552319
Created August 26, 2010 21:45 — forked from gf3/gist:166083
// Truncate a string to the closest word
String.prototype.truncateToWord = function(length) {
return this
.slice(0, length + 1)
.split(/\s+/)
.slice(0, -1)
.join(" ");
};
// Examples
var Evented = (function() {
var id = -1;
function uid() {
id++;
return "evented" + id;
}
function getID(obj) {
if (!("__eventedID" in obj)) {
var Router = require('geddy-core/lib/router').Router;
router = new Router();
router.match('/').to({controller: 'Main', action: 'index'});
router.resource('stuffs');
exports.router = router;