Skip to content

Instantly share code, notes, and snippets.

@cspotcode
cspotcode / quick-start.md
Last active August 29, 2015 14:08
Stylus Quick-Start

Cool beans! I'm coming at this from a Windows perspective, but this should work well in Linux or Mac as well.

  1. Install NodeJS. On Windows, you go to the website, run the installer, and click "Next" a few times. http://nodejs.org/

  2. Install stylus using NodeJS's package manager, npm, which has been automatically installed for you. Open a terminal and run:

     npm install -g stylus
    
  3. Create your Stylus code and save it as something like my-styles.styl. You can probably rename your existing .css file to .styl without changing anything else.

@cspotcode
cspotcode / bookmarklet-source.js
Last active August 29, 2015 14:12
JS code to launch the Doodle Wizard with fields pre-populated for today
// Initialize URL parameters
var params = {
type: 'date',
levels: 3, // 2 == yes-no poll, 3 = yes-no-ifneedbe poll
locale: 'en',
title: 'Ultimate Pickup @ The Bubble',
location: 'Harvard Bubble',
description: '',
name: 'Magazine Beach Pickup',
eMailAddress: 'me@nosuchsite.com' // Poll admin link is emailed to this address
@cspotcode
cspotcode / requirejs-config.js
Last active August 29, 2015 14:17
RequireJS wrap config that calls external define() once and uses an internal AMD shim
// Build configuration for libfoo
{
// ......
wrap: {
start:
`
;(function(global, outerDefine) {
var require, define;
`,
end:
@cspotcode
cspotcode / README.md
Last active August 29, 2015 14:27
Storing DefinitelyTyped definitions in npm

###Pros:

  • npm as CDN; no more GitHub API and rate limiting
  • npm provides search & indexing
  • package.json provides metadata
  • handles multiple version numbers
  • npm is download client; simpler tsd CLI

###Cons:

@cspotcode
cspotcode / GG2_leveldata_format.json
Created January 12, 2012 01:34
New GG2 map format
/* New format for GG2 leveldata.
* This JSON document fully describes a GG2 level.
* It can be embedded into a PNG with GG2DLL,
* packed up in a zip along with any BG/WM images,
* sent over the network, etc.
*
* Also this should be ready for future improvements and changes, unlike the terrible older format.
*/
@cspotcode
cspotcode / gist:5594389
Created May 16, 2013 19:32
How to do Object.create in JS engines that don't support it
SuperClass = function() {}
SubClass = function() {}
SubClass.prototype = Object.create(SuperClass.prototype);
// Or, if the JS engine doesn't have Object.create...
var ctor = function() {}
ctor.prototype = SuperClass.prototype;
@cspotcode
cspotcode / example.js
Created December 17, 2015 23:32
Parsing streaming JSON with Oboe
var oboe = require('oboe');
var stream = require('stream');
var Readable = stream.Readable;
var Writable = stream.Writable;
var readable = new Readable();
readable._read = function() {};
readable.push('{"some": "json"}{"more": [1, 2, 3], "json": true}{"final json object": 12345}{"stream continues...');
readable.push(null);
@cspotcode
cspotcode / all-sprites.js
Created June 8, 2013 01:23
example of loading many json files using RequireJS
// all-sprites.js
define([
require('text!sprite1.json'),
require('text!sprite2.json'),
require('text!sprite3.json'),
require('text!sprite4.json')
]);
// event handlers as methods
object object0 {
create() {
event_bind(ev_step, _ev_step);
}
script _ev_step() {
// do stuff
// Given an array of numbers, returns either the index containing that number
// or `undefined` if the array doesn't contain that number.
// Assumes that `list` is a non-sparse JavaScript array, that all items in the list are integers,
// and that the list is sorted in ascending order (obviously)
// Assumes that `value` is an integer.
function binarySearch(list, value) {
// Lower bound = minimum possible index
var lowerBound = 0;