Skip to content

Instantly share code, notes, and snippets.

@gobwas
gobwas / ring.go
Created May 12, 2016 16:42
Ring buffer
type ring struct {
data []byte
size int
pos int
len int
}
func newRing(size int) *ring {
return &ring{
@gobwas
gobwas / index.html
Created January 29, 2016 05:47
Untitled benchmark (http://jsbench.github.io/#0eebb4391da13333b579) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Untitled benchmark</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@gobwas
gobwas / index.html
Created January 29, 2016 05:46
Find in linked list (http://jsbench.github.io/#fad70366408e0e2b748d) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Find in linked list</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@gobwas
gobwas / algorithm.md
Last active January 14, 2016 12:42
Glob
  1. Построить синтаксическое дерево из строки шаблона
  2. Скомпилировать программу с учетом переданных разделителей S
    1. (A) Пусть N - дерево, результат п.1
    2. (F) Скопмилировать N
      1. Если N это nodePattern
        1. Обойти дочерние элементы. Пусть M это список программ
          1. Взять следующий дочерний узел N;
          2. Пусть P это результат применения (A) к N;
          3. Пусть P' это результат применения оптмизаций к P
  3. Положить P' в M
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>UUID</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@gobwas
gobwas / generator.js
Last active December 1, 2015 18:30
Generator object
var inherits = require("inherits-js");
var Generator;
/**
* @abstract
* @class Generator
* @constructor
*/
Generator = function() {
var self = this;
@gobwas
gobwas / gcd.go
Created November 20, 2015 14:09
GCD
package gcd
import "fmt"
import "math/big"
func Dedup(l []int64) []int64 {
list := make([]int64, len(l))
copy(list, l)
last := len(list) - 1
@gobwas
gobwas / race.go
Last active November 13, 2015 15:22
Go slice race condition example
package main
import (
"fmt"
"time"
)
type List struct {
Items []int
}
@gobwas
gobwas / actor.js
Created October 22, 2015 15:28
Callable object
function Actor(min, max) {
var self = this;
this.id = Math.floor(min + Math.random() * (max - min + 1));
var actor = function() { return self.action.apply(actor, arguments); }
Object.setPrototypeOf(actor, this);
return actor;
}
@gobwas
gobwas / alloc.js
Created September 3, 2015 20:47
Alloc error
var bigInt = 1000000000;
console.log(process.argv);
function asBuf() {
var buf = new Buffer("");
for (var i = 0; i < bigInt; i++) {
if (i % 10000 == 0) console.log(process.memoryUsage()['rss'] / 1024 / 1024 + 'mb');
buf = Buffer.concat([buf, new Buffer("a")]);