Skip to content

Instantly share code, notes, and snippets.

defs = {};
modules = {};
function define(name, fn) {
defs[name] = fn;
}
function require(name) {
console.log("Loading " + name);
if (modules.hasOwnProperty(name)) return modules[name];
if (defs.hasOwnProperty(name)) {
var fn = defs[name];
@creationix
creationix / module.js
Created April 19, 2011 04:27
A super simple module system for browsers. Assumes all source files are concatenated and in browser.
define.defs = {};
define.modules = {};
function define(name, fn) {
define.defs[name] = fn;
}
function require(name) {
if (define.modules.hasOwnProperty(name)) return define.modules[name];
if (define.defs.hasOwnProperty(name)) {
var fn = define.defs[name];
define.defs[name] = function () { throw new Error("Circular Dependency"); };
@OnesimusUnbound
OnesimusUnbound / Coffeescript Modules
Last active September 25, 2015 09:38
Generator mixin's for underscore.js
/**
* counter
* =======
* Creates counter that will generate number, starting from `start` (default to 0)
* incrementing (or decrementing) by `step` (default to 1). Based on
* [Python's itertools.count](http://docs.python.org/library/itertools.html#itertools.count).
*
* cycle
* =====
* Returns a function that will generate items in `iterable` for each call,
<script type="text/javascript">
window.RAILS_ENV = '<%= RAILS_ENV %>';
window.SERVER_ROOT = '<%= DC.server_root %>';
window.SERVER_ROOT_HTTP = '<%= DC.server_root(:ssl => false) %>';
<% if workspace %>
Organizations.refresh(<%= @organizations.to_json %>);
<% if @current_account %>
<%= render :partial => 'accounts/current_account.js', :type => :js %>
Accounts.refresh(<%= @accounts.to_json %>);
Projects.refresh(<%= @projects.to_json({:account => @current_account, :include_collaborators => true}) %>);
@joubertnel
joubertnel / gist:870190
Last active July 8, 2023 12:52
HTML5 Canvas - Rendering of Text on high-DPI screens
<html>
<head>
<script src='http://code.jquery.com/jquery-1.5.1.min.js'></script>
</head>
<body>
<h2>Naive canvas</h2>
<canvas id="naive" width="400" height="50"></canvas>
<h2>High-def Canvas</h2>
@dawsontoth
dawsontoth / AndroidMenuNavigation.js
Created February 17, 2011 14:23
Menu based navigation in Appcelerator Titanium that supports the use of the "Back" button to go back a view.
// this is your app.js
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// define our main window and open it. it will be an activity (navBarHidden: true), and will control our child window views
Titanium.UI.createWindow({
navBarHidden: true,
backgroundColor: '#fff',
url: 'mainwindow.js',
exitOnClose: true
@dawsontoth
dawsontoth / InfiniteScrollableView.js
Created February 3, 2011 20:54
Infinite scrollable list.
/**
* We're going to create an infinite scrollable list. In this case, we're going to show a date. When you swipe left,
* you'll see yesterday. Then the day before yesterday, and so on. Swiping right shows you tomorrow, and so on.
*/
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var isAndroid = Ti.Platform.osname === 'android';
/**
* Track where we are in the infinite scrollable views, and define how large of a step goes between each view.
*/
var currentDate = new Date(), msIntervalBetweenViews = 1000/*ms*/ * 60/*s*/ * 60/*m*/ * 24/*h*/;
@olsonjeffery
olsonjeffery / gist:749108
Created December 20, 2010 22:21
issue with backbone + zepto in ff 3.6
The Error:
element["insertAdjacent" + (html instanceof Element ? "Element" : "HTML")] is not a function
http://localhost:8080/scripts/zepto.js
Line 145
the zepto.js is 5ecaa (HEAD of the zepto repo)
backbone.js is 261059 (HEAD of backbone's repo)
the stack looks like..
@orlin
orlin / undermix.coffee
Created December 15, 2010 18:59
underscore.js with strings and other mixins (a node.js module)
define (require, exports, module) ->
_ = require("underscore")
_.mixin require("underscore.string")
_.mixin
# Converts the arguments list to an Array
aToArr: (list) ->
if _.isArguments(list)
_.toArray(list).slice(0)
else
@jashkenas
jashkenas / 1-adjacency.js
Created December 10, 2010 22:18
Snippet from Zepto.js, translated to CoffeeScript.
var adjacencyOperators = {
append: 'beforeEnd',
prepend: 'afterBegin',
before: 'beforeBegin',
after: 'afterEnd'
};
for (key in adjacencyOperators)
$.fn[key] = (function(operator) {
return function(html){