Skip to content

Instantly share code, notes, and snippets.

View samdelagarza's full-sized avatar

Sam De La Garza samdelagarza

View GitHub Profile
geocoder.geocode( { 'address': unitOfWork}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var result = {};
result.address = unitOfWork.replace(/\+/g,' ');
result.location = results[0].geometry.location.b + ',' + results[0].geometry.location.c;
displayMarkerStack.push(results[0].geometry.location);
finishedStack.push(result);
$("body").trigger('addressComplete');
define([
// notice the text! prefix
// this tells require.js to
// use the text plugin to
// retrieve the template
'text!./myTemplate.htm'
], function(myTemplate){
// use your template here
});
Backbone.View.extend({
template: 'my-view-template',
render: function () {
var deferred = new $.Deferred(),
promise = deferred.promise(),
that = this;
require('/templates/' + this.template + '.html', function (tmpl) {
deferred.resolve(that.$el.html(tmpl));
@samdelagarza
samdelagarza / example-user.js
Created May 4, 2012 13:34 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@samdelagarza
samdelagarza / 1.js
Created May 4, 2012 17:49 — forked from mxriverlynn/1.js
ajax command wrapper
var signForm = $.ajax({
type: "POST",
url: "/some/form",
dataType: "JSON",
data: myData
});
signForm.done(function(response){
// handle success here
});
@samdelagarza
samdelagarza / latency.txt
Created May 31, 2012 20:20 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
var date = new Date();
date.toLocaleDateString().split(',')[1].trim().split(' ')[0];
├───src
│ ├───client
│ │ ├───apps
│ │ │ ├───balance
│ │ │ │ └───tests
│ │ │ │ └───mocha
└────BalanceViewModel_spec.js
│ │ │ │ └───BalanceViewModel.js
└───tools
├───requirejs
require.config({
config: {
i18n: {
locale: myLocale
}
}
});
@samdelagarza
samdelagarza / cellUpdateBehavior.js
Created November 14, 2012 16:14
can this be made more performant?
define(['core', './topics'], function (core, topics) {
var valueFilter = /\D/g,
widthClasses = [], i,
jsLintLintDoesNotLikeLiteralsHere = true,
updateQueue = [],
pubsub = core.pubsub,
updatingInstances = {};
pubsub.subscribe(topics.pause, function (ev, instanceId) {
// delete to keep the object small, and keep the lookup time short.