Skip to content

Instantly share code, notes, and snippets.

View ValeriiVasin's full-sized avatar
🇺🇦

Valerii Vasin ValeriiVasin

🇺🇦
View GitHub Profile
@ValeriiVasin
ValeriiVasin / password.js
Created March 23, 2015 08:57
Reading password node.js
// Get a password from the console
function getPassword(done) {
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.setRawMode(true);
var password = '';
process.stdout.write('Password: ');
process.stdin.on('data', function(ch) {
ch = ch + '';
var _ = require('underscore');
var PassingStudentPolicy = require('./passingStudentPolicy');
var EligibleForSportsEnrollmentPolicy = function( student ) {
this.student = student;
};
EligibleForSportsEnrollmentPolicy.prototype = _.extend( EligibleForSportsEnrollmentPolicy.prototype, {
run: function() {
@ValeriiVasin
ValeriiVasin / .colordiffrc
Created August 26, 2013 08:21
colordiff configuration file
# Example colordiffrc file for light backgrounds
#
# Set banner=no to suppress authorship info at top of
# colordiff output
banner=no
# By default, when colordiff output is being redirected
# to a file, it detects this and does not colour-highlight
# To make the patch file *include* colours, change the option
# below to 'yes'
color_patches=no
@ValeriiVasin
ValeriiVasin / factorian.js
Created August 16, 2013 22:04
Factorians list determination.
function getFactorians() {
var _cache = [1],
factorial = 1,
i = 1,
list = [],
greatestFactorial;
// cache list of digits factorials
while (i < 10) {
factorial *= i;
@ValeriiVasin
ValeriiVasin / removeFolderRecursive.js
Created June 3, 2013 22:05
Remove folder with subfolders recursively.
// remove folder with all files and folders recursively
function removeFolderRecursive(path) {
if ( fs.existsSync(path) ) {
fs.readdirSync(path)
.forEach(function(file) {
var current = path + '/' + file;
if ( fs.statSync(current).isDirectory() ) {
removeFolderRecursive(current);
} else {
@ValeriiVasin
ValeriiVasin / minify-classnames.js
Created April 11, 2013 07:48
Minified classnames generator.
/**
* Generate sequential minified classnames:
* a => b => .. => z => aa => ba => .. => zz => .. => aaa ...
*/
var ClassNameEngine = (function () {
var alphabet = 'abcdefghijklmnopqrstuvwxyz',
alphabetLength = alphabet.length,
// current number combination which could be mapped to classname using alphabet
combination = null;
@ValeriiVasin
ValeriiVasin / curry.js
Created March 25, 2013 20:37
Function currying
/**
* @param {Number} count Call chain length
*/
function createAdd(count) {
return function add() {
var length = arguments.length,
args,
result,
i;
@ValeriiVasin
ValeriiVasin / color.js
Created December 11, 2012 19:25
Colorized output in nodejs
var color, i;
// Notice: octal literals are not allowed in strict mode.
function colorize(color, output) {
return ['\033[', color, 'm', output, '\033[0m'].join('');
}
for (i = 0; i < 100; i += 1) {
color = Math.random() > 0.9 ? 91 : 92; // 91 - red, 92 - green
process.stdout.write( colorize(color, '●') );
@ValeriiVasin
ValeriiVasin / linkedList.js
Last active October 12, 2015 02:07
Invert Linked List using Javascript.
function invertLinkedList(list) {
var next = list.next,
temp;
list.next = null;
while ( next ) {
temp = next;
next = temp.next;
temp.next = list;
@ValeriiVasin
ValeriiVasin / gist:3486197
Created August 27, 2012 06:21
SublimeLinter user settings
{
// http://www.jshint.com/docs/
"jshint_options": {
// prohibits the use of explicitly undeclared variables
"undef": true,
// prohibits the use of a variable before it was defined
"latedef": true,