Skip to content

Instantly share code, notes, and snippets.

View ghaiklor's full-sized avatar
🚧
Under wartime

Eugene Obrezkov ghaiklor

🚧
Under wartime
View GitHub Profile
@ghaiklor
ghaiklor / aoc-24-2.js
Last active January 5, 2016 16:48
Advent of Code (Day 24 Part 2)
const Combinatorics = require('./combinatorics');
const fs = require('fs');
const INPUT = fs.readFileSync('./input.txt', 'utf-8').split('\n').map(Number);
const TOTAL_SUM = INPUT.reduce((total, x) => total + x, 0);
const GROUP_WEIGHT = TOTAL_SUM / 4;
const VALID_PACKAGES = [];
for (var i = 1; VALID_PACKAGES.length === 0; i++) {
var combination = Combinatorics.combination(INPUT, ++i);
var cmb;
@ghaiklor
ghaiklor / aoc-25.js
Last active January 5, 2016 16:49
Advent of Code (Day 25)
const ROW = 3010;
const COLUMN = 3019;
const FIRST_CODE = 20151125;
const TARGET_INDEX = ((Math.pow(ROW + COLUMN - 1, 2) + ROW + COLUMN - 1) / 2) - ((ROW + COLUMN - 1) - COLUMN);
let result = FIRST_CODE;
for (var i = 1; i < TARGET_INDEX; i++) {
result = (result * 252533) % 33554393;
}
@ghaiklor
ghaiklor / iterm-fish-fisherman-meslo-osx.md
Last active July 18, 2024 08:26
iTerm 2 + fish + fisherman + Material Design + Meslo
@ghaiklor
ghaiklor / node-event-loop-demo.js
Created March 25, 2016 18:44
This example shows how you can block event loop in NodeJS
'use strict';
// The purpose of this example is to show
// how you can block the event loop with JavaScript.
// There is 3 routes
// / respond with Hello, World text
// /block uses JavaScript while for 5 seconds
// /non-block uses setTimeout for 5 seconds
// Do the following
@ghaiklor
ghaiklor / nodejs-prof-process-example.txt
Created April 19, 2016 11:15
Example of statistical profiling result in NodeJS
Statistical profiling result from isolate-0x101804a00-v8.log, (7436 ticks, 1 unaccounted, 0 excluded).
[Shared libraries]:
ticks total nonlib name
7431 99.9% /usr/local/bin/node
2 0.0% /usr/lib/system/libsystem_malloc.dylib
1 0.0% /usr/lib/system/libsystem_platform.dylib
[JavaScript]:
ticks total nonlib name
@ghaiklor
ghaiklor / nodejs-prof-process-example-2.txt
Created April 19, 2016 11:54
Example of statistical profiling result in NodeJS
Statistical profiling result from isolate-0x101804a00-v8.log, (107 ticks, 1 unaccounted, 0 excluded).
[Shared libraries]:
ticks total nonlib name
53 49.5% /usr/local/bin/node
47 43.9% /usr/lib/system/libsystem_kernel.dylib
2 1.9% /usr/lib/system/libsystem_malloc.dylib
1 0.9% /usr/lib/system/libsystem_platform.dylib
1 0.9% /usr/lib/system/libsystem_c.dylib
@ghaiklor
ghaiklor / sw-multiplex.js
Created September 29, 2016 13:37
Multiplexing downloads via Service Workers
/**
* Size of one chunk when requesting with Range
* @type {Number}
* @private
*/
const CHUNK_SIZE = 204800;
/**
* Concat two ArrayBuffers
* @param {ArrayBuffer} ab1
@ghaiklor
ghaiklor / NativeModule_compile.js
Created February 3, 2017 15:57
NativeModule.prototype.compile() sources
NativeModule.prototype.compile = function() {
var source = NativeModule.getSource(this.id);
source = NativeModule.wrap(source);
this.loading = true;
try {
const fn = runInThisContext(source, {
filename: this.filename,
lineOffset: 0,