Skip to content

Instantly share code, notes, and snippets.

@joeytwiddle
joeytwiddle / delicious_search_results.user.js
Created July 13, 2011 03:27 — forked from garcon/DeliciousGoogle.user.js
Delicious search results on Google
// ==UserScript==
// @name Delicious Search Results on Google
// @namespace gaillard
// @description Shows results from Delicious on Google search pages
// @include http://www.google.*/search?*q=*
// @include http://www.google.*/*
// @date 2009-03-07
// @version 0.1
// @GM_version 0.8.20080609.0
//
@joeytwiddle
joeytwiddle / callback_with_fallback.coffee
Created February 13, 2012 16:56
callbackWithFallback
# Takes: a callback function and a fallback function
# Returns: a callback function.
# Also: sets up a timeout, so that if the callback function is not called, the fallback function will be run
callbackWithFallback = (callback, fallback, waitSeconds) ->
waitSeconds = waitSeconds || 15
callbackHappened = false
robustCallback = () ->
@joeytwiddle
joeytwiddle / gist:3980560
Created October 30, 2012 14:37
Experimentum
class A
constructor: (@url, @data) ->
that = this
$.get @url, (data) =>
that.data = data
a = new A "/my-url/"
console.log a
@joeytwiddle
joeytwiddle / gist:6129653
Created August 1, 2013 08:49
A dirty patch to mongoose that allows a few deep-population queries to work, whilst breaking other things! Don't use it! :D
diff --git a/lib/model.js b/lib/model.js
index 53a21e1..ba76805 100644
--- a/lib/model.js
+++ b/lib/model.js
@@ -1944,6 +1944,13 @@ function populate (model, docs, options, cb) {
return cb();
}
+
+ // We may be asked to resolve path "comments._creator" but we are given the comments, so we only need to look into doc["_creator"], so let's drop the first part of the path. TOOD: Or should this be all but the last part?
@joeytwiddle
joeytwiddle / gist:6129676
Last active December 20, 2022 15:25
Deep population helper for mongoose
// Example usage:
// deepPopulate(blogPost, "comments comments._creator comments._creator.blogposts", {sort:{title:-1}}, callback);
// Note that the options get passed at *every* level!
// Also note that you must populate the shallower documents before the deeper ones.
function deepPopulate(doc, pathListString, options, callback) {
var listOfPathsToPopulate = pathListString.split(" ");
function doNext() {
if (listOfPathsToPopulate.length == 0) {
// Now all the things underneath the original doc should be populated. Thanks mongoose!
callback(null,doc);
@joeytwiddle
joeytwiddle / userChrome.css
Last active July 25, 2017 04:25
userChrome.css for TreeStyleTabs. Kill transparency, don't shadow text, squeeze the tabs closer together. This addresses some issues I had with TreeStyleTabs: Too much transparency, shadowed text sucks, tabs are too widely spaced.
/*
* Do not remove the @namespace line -- it's required for correct functioning
*/
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* set default namespace to XUL */
/* Joey's styles for TreeStyleTabs */
/* This one is probably not needed. */
.treestyletab-tabbar-toolbar {
opacity: 1.0 !important;
}
/*
* Do not remove the @namespace line -- it's required for correct functioning
*/
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* set default namespace to XUL */
/* This surrounds the location bar and the bookmarks toolbar */
#navigator-toolbox {
/* border: 1px solid black !important; */
}
/* Bookmarks Bar */
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
@joeytwiddle
joeytwiddle / Deriving values
Last active August 29, 2015 14:06
A better programming language
# Derivative Values
Often when programming we want access to values which are actually the result
of calculations on other values.
(In some fields, such values are called "invariants".)
There are more complex examples, but let's start with a simple one.
We have a rectangle, defined by its `top`, `left`, `width` and `height`.
@joeytwiddle
joeytwiddle / gist:fa05e497a09b073250b9
Created November 28, 2014 20:00
Sunride's console.log for Node adds date, file name, line number and function name to log lines
// It may be inefficient, and a little fragile (e.g. if Node changes its stacktrace
// formatting), but it can be a nice tool for developers when it works.
// ### sunlogger.js
var Logger = require('devnull');
var logger = new Logger({namespacing : 0});
var fs = require("fs");