Skip to content

Instantly share code, notes, and snippets.

@amakhrov
amakhrov / _.md
Created October 30, 2012 18:48
just another inlet to tributary
@amakhrov
amakhrov / timer
Created December 3, 2012 19:52
timer for profiling
var timer = {
start: function (s) {
this.stop();
this.name = s;
this.startts = Date.now();
},
stop: function () {
if (!this.name) return;
this.endts = Date.now();
@amakhrov
amakhrov / node-amqp
Created July 21, 2014 17:41
Example usage of node-amqp
module.exports = function (nconf) {
var amqp = require('amqp'),
winston = require('winston');
var config = nconf.get('amqp');
var externalMessageCallback;
var openQueue = function (conn, queueName, passive, cb) {
var queueOptions = {
@amakhrov
amakhrov / perf.js
Created September 22, 2016 05:47
Compare performance of inlined try/catch vs try/catch extracted into a separate function
function parse(json, defaultValue) {
try {
return JSON.parse(json);
} catch (e) {
return defaultValue;
}
}
var json = JSON.stringify({a: 1, b: 2, c: 3, d: 4});
class MyReactButton extends React.Component {
constructor() {
this.state = {name: ‘my-name’};
}
onClick() {
console.log(this.state.name);
}
render() {
const asyncA = () => Promise.resolve('A');
const asyncB = () => Promise.resolve('B');
const asyncC = (name) => Promise.resolve(`${name}+C`); // e.g. "A+C"
// Please write a function that requests these 3 async functions and combines the results into a single object:
const callAsync = () = { ... }
callAsync().then(result => console.log(result)); // should print: {a: 'A', b: 'B', c: 'A+C'}
// asyncA and asyncB are independent, should be called in parallel
const asyncA = () => Promise.resolve('A');
const asyncB = () => Promise.resolve('B');
// Please write a function that calls these 2 async functions in parallel and combines the results into a single object.
// asyncA and asyncB are independent, should be called in parallel.
const callAsync = () => {
// your code should be here
// ...
}
const asyncA = () => Promise.resolve('A');
const asyncC = (prefix) => Promise.resolve(`${prefix}+C`); // e.g. "x+C"
// Please write a function that calls these 2 async functions and combines the results into a single object.
// asyncC takes the "prefix" argument - should be the resolved result of the asyncA() promise (which means asyncC depends on asyncA).
// Basically, first need to call asyncA, then pass the result to asyncC, then combine the both results into the single output object.
const callAsync = () => {
// your code should be here
// ...
}
@amakhrov
amakhrov / HtmlComponent.js
Created August 29, 2018 03:35
React HTML rendering
const someHtmlContent = '<strong>highlighted text</strong> and regular text';
const HtmlComponent = () => {
return (
<div>
<h2>Rendering HTML content below</h2>
<div>/* How do you put the html content inside? */</div>
</div>
);
}
swagger: '2.0'
info:
title: Test
description: Test
version: 4.0.0
host: crunchbase.com
schemes:
- https
basePath: /v4
produces: