This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Works in modern browsers +IE9, but Modernizer has a polyfill baked in for function.bind | |
//From Sublime Nettuts tutorial, original credit from Paul Irish | |
var o=$( {}); | |
$.subscribe = o.on.bind('event name', eventData, function(event) { | |
/* Act on the event */ | |
}); | |
$.unsubscribe = o.off.bind(); | |
$.publish = o.trigger.bind(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
var o = $({ | |
on: 'subscribe', | |
trigger: 'publish', | |
off: 'unsubscribe' | |
}, function (key, api) { | |
$[api] = function() { | |
o[key].apply[o,arguments] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fin_item | |
.findAll({where: Sequelize.and({cik: 1800}, {fiscalyear: 2013}, {periodfocus: 'FY'}, {rootconcept: 'Statement of Income'}), order: 'preorder'}) | |
.success(function (result) { | |
console.log(result.length); | |
for (var i=0;i<result.length;i++) {console.log(result[i].values);} | |
}) | |
.error(function (err) { | |
console.error(err); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fin_item | |
.findAll({where: Sequelize.and({cik: 1800}, {fiscalyear: 2013}, {periodfocus: 'FY'}, {rootconcept: 'Statement of Income'}), order: 'preorder'}, {raw: true}) | |
.success(function (result) { | |
console.log(result.length); | |
console.log(result) | |
}) | |
.error(function (err) { | |
console.error(err); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env SQL | |
#Lets say you have a sec_sample table to which you want to add a id (surrogate) autoincremental PK: | |
ALTER TABLE sec_sample ADD column id serial; | |
UPDATE sec_sample SET id = nextval(pg_get_serial_sequence('sec_sample', 'id')); | |
ALTER TABLE sec_sample ADD PRIMARY KEY (id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Select | |
s.concept, | |
sum(case when s.fiscalyear =2009 then s.value else 0 end) as "2009", | |
sum(case when s.fiscalyear =2010 then s.value else 0 end) as "2010", | |
sum(case when s.fiscalyear =2011 then s.value else 0 end) as "2011", | |
sum(case when s.fiscalyear =2012 then s.value else 0 end) as "2012", | |
sum(case when s.fiscalyear =2013 then s.value else 0 end) as "2013", | |
sum(case when s.fiscalyear =2014 then s.value else 0 end) as "2014" | |
from (Select concept, fiscalyear, value, preorder from sec_sample | |
where cik=1288776 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bracket = []; | |
for (var d=0; d<list.length;d++){ | |
if (path.extname(list[d]) === ".".concat(ext)) { | |
bracket.push(list[d]); | |
} | |
} | |
//bracket = list.filter(function (d) { | |
// return path.extname(d) === ".".concat(ext); | |
//}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (var i=0;i<list.length;i++) { | |
console.log(list[i]); | |
} | |
//Equivalent to: | |
//list.forEach(function (i) { | |
//console.log(i) | |
//}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (var i=0; i<num; i ++) { | |
operation(); | |
} | |
//Equivalent to | |
if (num <= 0) {return;} //or just return see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return | |
operation() | |
return repeat(operation, --num) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"scope": "source.js", | |
"completions": | |
[ | |
{"trigger": "m\tm() Mithril", "contents": "m('${1:div}',{\n\t${2:style: { \\}}, \n\t${3:config: 'function name'}\n\t},[\n\t\t${4:'Children'}\n\t])"}, | |
{"trigger": "mi\tinput Mithril", "contents": "m('input${1:[type=]}', ${2:oninput:}, value: $3)"}, | |
{"trigger": "ma\tlink Mithril", "contents": "m('a[href=${1:/myroute}]', {config: ${2:m.route}}, ${3:'Myroute'})"}, | |
{"trigger": "mm\tmodule Mithril", "contents": "var mymodule = {};\n\nmymodule.vm = ${1:'Object literal \\{\\} or function Constructor'}\n\nmymodule.controller = function (options) {\n\t${2:mymodule.vm.init();}\n};\n\nmymodule.view = function (ctrl) {\n\treturn ${3:'view here'};\n}\nm.module(document${4:.body}, mymodule);"}, | |
{"trigger": "mp\tgetter/setter Mithril", "contents" : "m.prop(${1:'initial value'});"}, | |
{"trigger": "mw\tevent handler Mithril", "contents": "m.withAttr(${1:'string here'}, ${2:callback here})"}, |
OlderNewer