Skip to content

Instantly share code, notes, and snippets.

View sukima's full-sized avatar

Devin Weaver sukima

View GitHub Profile
// Convert the format string from moment's "L" to a format usable by
// [bootstrap-datepicker][1].
//
// Call it with:
//
// momentFormatToDatePicker(moment.localeData().longDateFormat("L")).
//
// [1]: https://bootstrap-datepicker.readthedocs.org/en/latest/options.html#format
function momentFormatToDatePicker(format) {
// The actual translation is more detailed:
// script tags are HTML, don't put them in JavaScript Files.
// <script type="text/javascript" src="js/jquery.min.js"></script>
// <script type="text/javascript">
// Indent your code! It organizes levels and lets you know what statements are in what scope.
// Organization is key in programming, Don't make it harder for yourself.
$(document).ready(function() {
$(document).on('click', '.day', function() {
$('.times-' + this.value).toggle();
});
@sukima
sukima / BetterCommitMessages.md
Last active May 10, 2024 00:08
My guidelines for writing better commit messages
#!/usr/bin/env node
var debug = require('debug')('doc-fetcher');
var Promise = require('bluebird');
var path = require('path');
var htmlparser = require('htmlparser');
var select = require('soupselect').select;
var request = Promise.promisifyAll(require('request'));
var fs = Promise.promisifyAll(require('fs'));
var cookieJar = request.jar();
@sukima
sukima / .vimrc
Created December 20, 2014 17:40
Auto close parenthisis in VIM
" Section: AutoClose {{{2
" Auto close parenthesis
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
function getPromise() {
return new Promise(function(resolve, reject) {
// Do something asynchronous
setTimeout(function() { resolve('Async Value'); }, 500);
})
.then(function(value) {
return 'New Async Value';
});
}
// The frame work I need to use defines the following API:
//
// MyObject = {
// addEventListener: function(name, listenerCallback) {...},
// removeEventListener: function(name, listenerCallback) {...},
// };
//
// MyObject
// is an object and the events are stored pervasivly (this is not an instance
// that can be Garbage Collected).
@sukima
sukima / promise-spec.js
Created December 1, 2014 17:43
How to use Jasmine and test promises
// require bluebird
// require jasmine
function myPromise() {
return Promise
.delay(200)
.then(funciton() {
return 'foobar';
});
}
var Promise = require('bluebird');
function HTTPResponse(status, responseText) {
this.name = 'HTTP Response Object';
this.message = 'Used to type HTTP Responses';
this.status = status;
this.responseText = responseText;
}
function hasStatus(status) {

In an effort to rain in some of the complexity in Titanium based projects I have found few coding conventions and patterns that improve my ability to comprehend my code base better.

Some strings might need to be created dynamically based on data. Most Titanium projects include Alloy which includes Backbone and hence includes Underscore. You can also include Underscore manually. In either case it is worth it!

Tools worth having