Skip to content

Instantly share code, notes, and snippets.

View vorandrew's full-sized avatar

Andrew Vorobyov vorandrew

View GitHub Profile
@vorandrew
vorandrew / blackscholes.js
Created September 4, 2012 16:44 — forked from joaojeronimo/blackscholes.js
Black-Scholes in Javascript: A rewrite of http://www.espenhaug.com/black_scholes.html
/*
PutCallFlag: Either "put" or "call"
S: Stock Price
X: Strike Price
T: Time to expiration (in years)
r: Risk-free rate
v: Volatility
This is the same one found in http://www.espenhaug.com/black_scholes.html
but written with proper indentation and a === instead of == because it's
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
Promise = require 'bluebird'
co = require 'co'
# Callbacks
wait = (n, cb) ->
setTimeout ->
cb null, n
, 1000
@vorandrew
vorandrew / protips.js
Created October 27, 2015 07:33 — forked from nolanlawson/protips.js
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@vorandrew
vorandrew / axioms.go
Last active April 8, 2016 16:35
Channels
package main
func main() {
var c chan string
c <- "let's get started" // deadlock
<-c // deadlock
c := make(chan string)
close(c)
c <- "let's get started" // panic
val, open := <-c // val = zero, open = false
@vorandrew
vorandrew / update_insert.coffee
Created May 8, 2016 18:45
More eloquent way to do this?
yield Promise.map data, (oneEvent)->
eventModel = new Event oneEvent
eventModel.fetch().then (fromDB) ->
return do eventModel.save if not fromDB?
fromDB.save oneEvent
@vorandrew
vorandrew / expected_outlog.txt
Created November 28, 2017 14:58
Logging is not working
$ node index.js
[-isodate-] INFO init start
[-isodate-] INFO init end
123
#!/bin/sh
set -e
# Code generated by godownloader. DO NOT EDIT.
#
usage() {
this=$1
cat <<EOF
$this: download go binaries for apex/up
@vorandrew
vorandrew / example.js
Created February 25, 2018 21:08
Group by flow
let data = _.flow(
_.groupBy('country_id'),
_.map(
_.flow( // city group by level
_.groupBy('city_id'),
_.map(
_.flow( // person group by level
_.groupBy('person_id'),
_.map(vals => {
return {
function MakeArray(size) {
for (var i = 1; i <= size; i++) {
this.length = size;
this[i] = 0;
}
}
/*