Skip to content

Instantly share code, notes, and snippets.

@alyssaq
alyssaq / jsconfasia.md
Last active February 13, 2024 07:59
2013 jsconf.asia
@alyssaq
alyssaq / gist:8415699
Created January 14, 2014 09:36
Macbook Pro Envrionment
Sublime
https://github.com/revolunet/sublimetext-markdown-preview
@alyssaq
alyssaq / inheritance.md
Last active February 13, 2024 07:58
Javascript Inheritance
function Animal(name) {
  this.name = name;
};
Animal.prototype.move = function(meters) {
  console.log(this.name+" moved "+meters+"m.");
};

function Snake() {
  Animal.apply(this, Array.prototype.slice.call(arguments));

};

@alyssaq
alyssaq / dom-query.js
Last active February 13, 2024 07:58
DOM query
// based on https://gist.github.com/Potfur/5576225 & https://github.com/james2doyle/saltjs
// more info: https://plus.google.com/109231487156400680487/posts/63eZzzrBSb6
window.$ = function(s) {
var c = {
'#': 'ById',
'.': 'sByClassName',
'@': 'sByName',
'=': 'sByTagName'}[s[0]];
return document[c?'getElement'+c:'querySelectorAll'](s.slice(1))
};
@alyssaq
alyssaq / batch_add_mongodb.js
Last active February 13, 2024 07:58
Batch add Documents to Mongodb
var mongoose = require('mongoose');
var DATA = require('../data/dataSources');
var dataSourceSchema = new mongoose.Schema({
sourceid: {type: Number, index: true},
status: {type: String, default: 'active'},
name: String,
provider: {type: String, lowercase: true, default: 'google_adwords'},
updated: {type: Date, default: Date.now}
});
@alyssaq
alyssaq / ui-patterns
Created July 11, 2014 11:24
UI Patterns
Interacting with data stores:
- Restful API access
- Local storage
Rendering data to ui: Views
Models:
- Represent your data: POJO
- Read/write properties on the data
- Persist data to the server
- Responding to user interaction/
event listeners that fire when data changes
@alyssaq
alyssaq / jsbin.yokaxi.css
Last active February 13, 2024 07:57
Bouncing smiley face
.smile {
position: absolute;
top: 0;
left: 60%;
width: 100px;
height: 100px;
margin-left: -50px;
}
@-webkit-keyframes circle {
@alyssaq
alyssaq / highlight.txt
Last active February 13, 2024 07:57
Sublime text/template highlight
To support HTML highlighting of underscore/handlebar/html templates in Sublime Text 2:
Sublime > Preferences > Browse Packages...
Open HTML > HTML.tmLanguage
Line 286:
Comment:
<!-- <string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)</string> -->
Add:
<string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)(?!.*type=["']text/*.(template|html)['"])</string>
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.4.8/fabric.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<canvas id="c" width="400" height="400"></canvas>
@alyssaq
alyssaq / sort_objects.js
Last active February 13, 2024 07:57
Sort object property keys in Javascript
function objectToArray(obj) {
var keys = Object.keys(obj);
return keys.map(function(key) {
return [key, obj[key]];
});
}
function arrayToObject(arr) {
var obj = {};
arr.forEach(function(tuple) {