Skip to content

Instantly share code, notes, and snippets.

View andre487's full-sized avatar
🎠
My horse is amazing

Andrey Prokopyuk andre487

🎠
My horse is amazing
View GitHub Profile
@andre487
andre487 / .eslintrc
Last active August 29, 2015 16:46
Mocha bootstrap
{
"env": {"mocha": true},
"globals": {
"assert": false,
"sinon": false,
"chai": false
}
}
@andre487
andre487 / lint-javascript.bash
Last active August 29, 2015 16:34
Lint script for git hooks
#!/usr/bin/env bash
set -e
COLOR_RED="\e[0;31m"
COLOR_GREEN="\e[0;32m"
COLOR_YELLOW="\e[0;33m"
COLOR_RESET="\e[0m"
SEPARATOR="${COLOR_YELLOW}----------${COLOR_RESET}"
@andre487
andre487 / countUtf8Bytes.js
Created July 16, 2015 10:34
Get UTF-8 string length in bytes
/**
* Get UTF-8 string length in bytes
* @see http://stackoverflow.com/questions/2848462/count-bytes-in-textarea-using-javascript
*
* @param {String} string
* @returns {Number}
*/
function countUtf8Bytes(string) {
var utf8length = 0;
for (var i = 0; i < string.length; i++) {
@andre487
andre487 / app.js
Last active August 29, 2015 14:23
Sorting profiling
var fs = require('fs'),
profiler = require('v8-profiler'),
runSelectionSort = require('./selection-sort'),
runMergeSort = require('./merge-sort');
profiler.startProfiling('sort-app');
console.time('selection sort');
runSelectionSort();
// ==UserScript==
// @name Открыть Видео с диска
// @namespace yandex
// @include https://yadi.sk/*
// @version 1
// @grant none
// ==/UserScript==
window.addEventListener('load', main);
@andre487
andre487 / custom-error.js
Last active January 25, 2020 13:32
Crossbrowser custom error
/**
* Universal custom error class
* @param {String} message
* @param {Error} [prevError]
* @constructor
*/
function CustomError(message, prevError) {
if (!CustomError.isInstance(this)) {
// Can't use custom errors like `throw Error('Message')`
// because of stack capturing
@andre487
andre487 / checks.js
Created March 7, 2015 23:10
V8 checks
exports.fastElements = function(obj) {
if (%HasFastSmiElements(obj)) {
console.log('Fast SMI elements');
}
if (%HasFastSmiOrObjectElements(obj)) {
console.log('Fast SMI or Object elements');
}
if (%HasFastObjectElements(obj)) {
console.log('Fast Object elements');
}