Skip to content

Instantly share code, notes, and snippets.

SELECT
date_trunc('hour', dt) dt,
((array_agg(bid ORDER BY dt ASC))[1] +
(array_agg(ask ORDER BY dt ASC))[1])/2 o,
(MAX(bid) + MAX(ask))/2 h,
(MIN(bid) + MIN(ask))/2 l,
((array_agg(bid ORDER BY dt DESC))[1] +
(array_agg(ask ORDER BY dt DESC))[1])/2 c,
SUM(bid_vol) bid_vol,
SUM(ask_vol) ask_vol,
// Make a message bus object for use in your client-side (in-browser) code.
// The name (label) of a message type should be called the topic, in your code. This is standard pub/sub nomenclature.
// The payload is optional.
// Subscribers must be notified in the exact order that they originally subscribed.
// inside component A...
// messageBus.subscribe('new_signup', function(payload) {
// // do something with the payload
// });
const vowelDoubler = function (array) {
let count = 0;
for (let i = 0; i < array.length; i++) {
if (['a', 'e', 'i', 'o', 'u'].includes(array[i])) {
count++;
}
}
for (let i = array.length - 1, j = i + count; i >= 0; i--, j--) {
/**
* @param {number[]} nums
* @return {number[]}
*/
var productExceptSelf = function(nums) {
var output = nums.slice().fill(1);
var temp = 1;
for (var i = 0; i < nums.length; i++) {
output[i] = temp;
// O(n) space complexity solution
var kthSmallest = function(root, k) {
var stack = [];
var count = 0;
var node = root;
while (node) {
stack.push(node);
node = node.left;
}
var Tree = function (val) {
this.val = val;
this.children = [];
};
const hasPathToSum = function(node, targetSum) {
if (node.val === targetSum) {
return true;
}
// Prompt: tackling floating-point imprecision with the CashAmount class
class CashAmount {
constructor(double) {
this.pennies = parseInt(double * 100, 10);
}
totalInPennies() {
return this.pennies;
}
@kennyxcao
kennyxcao / static_server.js
Created September 14, 2017 20:47 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
var BinaryTree = function (value) {
this.value = value;
this.left = null;
this.right = null;
};
// Starting Level at root = 0
const findLargestLevel = function(node) {
var queue = [[node, 0]];
var levelSum = [];
@kennyxcao
kennyxcao / PascalTriangle.js
Last active August 31, 2017 17:04
PascalTriangle LeetCode Solution
/**
* @param {number} numRows
* @return {number[][]}
*/
var generate = function(numRows) {
var result = [];
for (var i = 0; i < numRows; i++) {
var row = [];