Skip to content

Instantly share code, notes, and snippets.

View yefremov's full-sized avatar

Jeff yefremov

  • Riga, Latvia
View GitHub Profile

Keybase proof

I hereby claim:

  • I am yefremov on github.
  • I am yefremov (https://keybase.io/yefremov) on keybase.
  • I have a public key ASA2nE5PKBOyqw-c-V_wcWJ_nGgrn0k78saYFX9RAvItAwo

To claim this, I am signing this object:

@yefremov
yefremov / count.c
Created July 3, 2017 20:28
Coroutines in C (go macros)
//
// count.c
//
// Based on a a Duff's device
// https://pusher.com/sessions/meetup/the-realtime-guild/realtime-stream-processing-with-coroutines
//
#define go static int __resume__ = 0; \
if (__resume__) goto __RESUME__;
@yefremov
yefremov / coro.c
Created July 3, 2017 20:14
Coroutines in C
//
// coro.c
//
// Based on a a Duff's device
// https://pusher.com/sessions/meetup/the-realtime-guild/realtime-stream-processing-with-coroutines
//
/*
* Coroutine.
@yefremov
yefremov / functions.js
Last active April 16, 2017 04:45
Data Science Math Skills
// Data Science Math Skills
// https://www.coursera.org/learn/datasciencemathskills/home/welcome
// Sigma summation
function sigma(n, i, f) {
var sum = 0;
while (i <= n) {
sum += f(i++);
}
@yefremov
yefremov / report.js
Last active April 8, 2017 07:04
Report browser performance timing and navigation data
function report() {
try {
return {
userAgent: 'navigator' in window && navigator.userAgent,
timing: 'performance' in window && performance.timing,
navigation: 'performance' in window && performance.navigation,
chrome: 'chrome' in window && chrome.loadTimes(),
serviceWorker: 'serviceWorker' in navigator,
};
@yefremov
yefremov / nextTick.js
Last active March 13, 2017 20:55
Simple browser version of nextTick function
// https://github.com/kriskowal/q/blob/d373079d3620152e3d60e82f27265a09ee0e81bd/q.js#L101-L248
// Use the fastest possible means to execute a task in a future turn
// of the event loop.
var nextTick = (function () {
var head = {task: null, tail: null};
var tail = head;
var flushing = false;
@yefremov
yefremov / nordic.js
Last active March 11, 2017 09:48
If you know map, I will teach you monads
//
// https://www.youtube.com/watch?v=2jp8N6Ha7tY
//
// Capitalize the first letter of a string, or all words in a string.
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.substring(1);
}
@yefremov
yefremov / capitalize.js
Created March 10, 2017 22:26
Capitalize the first letter of a string, or all words in a string
/**
* Capitalize the first letter of a string, or all words in a string.
*
* @param {string}
* @returns {string}
* @example
*
* capitalize('foo bar baz');
* => "Foo bar baz"
@yefremov
yefremov / uncurryThis.js
Created March 7, 2017 02:39
Making `uncurryThis()` safe to use in the presence of untrusted code
// How does one write a JavaScript meta-program that can operate reliably on
// other objects in its JavaScript context (in a browser – within the same
// frame), despite the loading of arbitrary code later into that same frame?
// The problem is that the later code may arbitrarily modify, override, or
// remove methods on the primordial built-in objects. To make the problem
// tractable, we assume that the meta program consists of modules that are
// first evaluated before their frame has become corrupted.
function uncurryThis(func) {
@yefremov
yefremov / iterator.js
Last active February 20, 2017 16:40
Two versions of a collection iterator factory
function iterate(iterable) {
var index = -1;
return function next() {
return ++index < iterable.length ? iterable[index] : null;
}
};
function makeIterator(iterable) {
var index = -1;