Skip to content

Instantly share code, notes, and snippets.

View khrykin's full-sized avatar

Dmitry Khrykin khrykin

  • Helsinki, Finland
View GitHub Profile
@khrykin
khrykin / fader.js
Created January 19, 2020 13:44
Logarithmic fader (envelope) in javascript
/**
* Fades values in and out logarithmically.
* @param {number} sampleRate - Number of samples per duration unit
* @param {number} duration - Duration of an envelope
* @param {number} unity - Unity approximation
*/
function Fader(sampleRate, duration, unity = 0.999) {
this._sampleDuration = duration / sampleRate;
let T = -duration / Math.log(1 - unity);
@khrykin
khrykin / main.cpp
Created July 4, 2019 12:03
Get current day's duration in C++
#include <ctime>
#include <chrono>
#include <string>
#include <sstream>
#include <iomanip>
#include <iostream>
using Timestamp = std::time_t;
using DayComponents = std::tm;
using Duration = std::chrono::duration<double>;
@khrykin
khrykin / connectLocalStore.js
Created January 22, 2018 14:13
Connect local redux store to a component
import React, { Component } from 'react'
import hoistNonReactStatic from 'hoist-non-react-statics'
import { createStore, bindActionCreators } from 'redux'
/**
* This is a HOC that attaches its own redux store to a component -
* the store lives and dies with the component.
*
* Usecase:
* When you don't feel comfortable with this.setState(), but