Skip to content

Instantly share code, notes, and snippets.

View vitkarpov's full-sized avatar
🔲
I help folks prepare for coding interviews

Viktor Karpov vitkarpov

🔲
I help folks prepare for coding interviews
View GitHub Profile
@vitkarpov
vitkarpov / callbacify.js
Last active November 11, 2017 08:47
Example of util.callbackify
const { callbackify } = require('util');
async function main() {
await Promise.resolve();
}
callbackify(main)(function(err) {
if (err) {
return console.error(err);
}
@vitkarpov
vitkarpov / promisify.js
Created November 11, 2017 08:12
Example of util.promisify
// @see http://2ality.com/2017/05/util-promisify.html
const { promisify } = require('util');
const fs = require('fs');
const readFileAsync = promisify(fs.readFile);
const filePath = process.argv[2];
readFileAsync(filePath, { encoding: 'utf8' })
@vitkarpov
vitkarpov / http2-example.js
Last active November 10, 2017 19:36
Example of http/2 landed in Node.js 9 without --expose-http2 flag
const http2 = require('http2');
const fs = require('fs');
const server = http2.createSecureServer({
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
});
server.on('error', (err) => console.error(err));
server.on('socketError', (err) => console.error(err));
@vitkarpov
vitkarpov / question.md
Created November 6, 2017 19:20
How do I get into a programming languages development?

How do I get into a programming languages development?

I'm a web developer and have been doing JavaScript both on client and server for quite a while. At some point I started to understand that I want to focus on JavaScript as a language and a tool for developers rather than using it as a JavaScript developer.

I'm wondering which theory basis and practical skills should I get if I want, for instance, to end up at V8 JavaScript runtime team?

@vitkarpov
vitkarpov / repeat-in-log-n.js
Last active July 29, 2017 15:51
Repeat in log n
/**
* Возвращает строку длины n состоящую из символов s
* Имеет логарифмическую сложность.
*
* @param {String} s
* @returns {String}
*/
function repeat(s, n) {
let ans = s;
let len = 1;
#!/bin/bash
#
# git-svn-diff originally by (http://mojodna.net/2009/02/24/my-work-git-workflow.html)
# modified by mike@mikepearce.net
# modified by aconway@[redacted] - handle diffs that introduce new files
# modified by t.broyer@ltgt.net - fixes diffs that introduce new files
# modified by m@rkj.me - fix sed syntax issue in OS X
#
# Generate an SVN-compatible diff against the tip of the tracking branch
.my-fancy-input {
position: relative;
width: 160px;
height: 20px;
border: 1px solid black;
}
.my-fancy-input input {
position: absolute;
background: transparent;
box-sizing: border-box;
.my-fancy-input {
font-size: 20px;
font-family: monospace;
letter-spacing: 10px;
}
@vitkarpov
vitkarpov / cracking-the-coding-interview-10-3.js
Last active May 12, 2017 04:47
"Cracking the coding interview", search, 10.3
/**
* Находит индекс указанного элемента x в массиве arr.
* Если такого элемента нет, вернет -1.
* Работает за O(log n).
* В худшем случае деградирует до O(n), при большом количестве одинаковых элементов.
* @param {array<number>} arr
* @param {number} x
* @returns {number}
*/
const search = (function() {
/**
* @example
* // 1
* jpath('.foo.bar', { foo: { bar: 1 } });
*
* // null
* jpath('.foo.bar.baz', { foo: 2 })
*/
const jpath = (function() {
function recursiveSearch(fields, source) {