Skip to content

Instantly share code, notes, and snippets.

// write reduce without Array.reduce
// @param {Array} list
// @param {Function} fn takes (acc, result)
// @acc {*} acc is the starting point or working accumulator
const reduce (list, fn, acc) => {
let i = 0;
var len = list.length;
while(i < len) {
acc = fn(acc, list[i])
@theptrk
theptrk / circle.html
Created August 10, 2016 01:04
This is a circle in css
<!DOCTYPE html>
<html>
<head>
<title>Circle</title>
<style type="text/css">
.circle-container {
width: 150px;
height: 150px;
line-height: 150px;
text-align: center;
@theptrk
theptrk / KaleActions.js
Created September 8, 2015 06:37
Flux with promises
import alt from '../libs/alt';
class KaleActions {
create(data) {
return new Promise((resolve, reject) => {
var post = $.ajax({
type: 'POST',
data: data,
url: '/kaleapi',
});
@theptrk
theptrk / SomeComponent.jsx
Created August 7, 2015 06:27
bindContext takes an array and binds a context
import React from 'react'
import bindContext from './path/to/bindContext';
export default class SomeComponent extends React.Component {
constructor() {
super();
// ========== Too verbose ==========
// this.toggleEventForm = this.toggleEventForm.bind(this);
// this.handleSubmit = this.handleSubmit.bind(this);
@theptrk
theptrk / rust-black-scholes
Created June 16, 2014 17:59
Black Scholes Formula in Rust
/* The Black and Scholes (1973) Stock option formula */
use std::f64;
fn black_scholes(putCallFlag:&str, s:f64, x:f64, t:f64, r:f64, v:f64) -> f64 {
let d1 = ( (s / x).ln() + (r + v * v / 2.0) * t) / ( v * t.sqrt() );
let d2 = d1 - v * t.sqrt();