This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | |
#Importing an Excel table into Postgres | |
# 1) Save Excel file in a .csv format with just 1 header | |
# ex: | |
example_file.csv | |
# 2) Save file in C:/PostgreSQL/9.3/data (important that this file is within "data") | |
# so Postgres has the right file permissions | |
# 3) Need to create an empty table schema capable of storing the data | |
# 4) ex: |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) |
OlderNewer