Skip to content

Instantly share code, notes, and snippets.

View rlidwka's full-sized avatar

Alex Kocharin rlidwka

  • Tbilisi, Georgia
View GitHub Profile
@rlidwka
rlidwka / stuff.js
Last active April 5, 2018 19:40
finding the closest frakking number
function get_digit(n, d) {
return Math.floor(n / Math.pow(10, d)) % 10
}
function is_unique(n, d) {
let m = 0
let c = Math.pow(10, d)
for (let i = d; n > c; i++, c *= 10) {
let new_m = m ^ (2 << get_digit(n, i) + 1)
@rlidwka
rlidwka / gist:8b904ca00b1e76731270
Last active September 30, 2016 12:50
Looking for a static analysis tool

TL;DR:

I'm testing five linters (jshint, jslint, eslint, gjslint, javascriptlint) - that's all that I could find - for two common and easily detectable errors.

But they don't find any, so I'm asking the community to suggest one that can.


Here is a piece of code. You know that pattern that makes a constructor callable without "new"?

@rlidwka
rlidwka / gist:892d08876d737e265a86
Last active August 29, 2015 14:04
mincer benchmark
#!/usr/bin/env node
var Mincer = require('mincer');
var env = new Mincer.Environment();
env.appendPath('/home'); // or whereever you have a big bunch of files
var manifest = new Mincer.Manifest(env, '.');
var date = Date.now();
manifest.compile(['some-nonexistent-file']);
function get_global() {
if (typeof(window) === 'undefined' && typeof(window) === 'object' && window != null && window.window === window)
return window
if (typeof(global) === 'undefined' && typeof(global) === 'object' && global != null && global.global === global)
return global
}
var eve = require('EVE')
var type = eve.type
schema = type.object({
number: type.number().min(5),
something: type.string().trim().notEmpty().required()
})
console.log(schema.val({number:'123'}).validate())
var cookie = require('./')
var acc, x;
console.log(x = cookie.sign('hello', 'test'))
function quantile(arr, from, to) {
from = Math.floor((arr.length) * from)
to = Math.ceil((arr.length) * to)
var s = 0
arr = arr.sort()
var crypto = require('crypto');
var crc32 = require('crc').crc32;
var x = 1;
while(1){
var string = '';
for (var j=0; j<x; j++) {
string += String(Math.random());
var net = require('net');
net.createServer(function (socket) {
socket.setEncoding("ascii");
socket.on("data", function (data) {
data = data.trim();
console.log('Serving: ', data);
if (data == 'img') {
socket.write('The reference images:\r\n');
socket.write('\r\n');
#!/usr/bin/node
var net = require('net');
var fs = require('fs');
var server = require('net').createServer(function(conn) {
var upsock = new net.Socket();
var send = [];
var connected = false;
var connecting = false;
console.log('===== CONNECT =====');
class WrapFunc
constructor: ->
for key of @
do (key) =>
old_fn = @[key]
@[key] = =>
console.log('wrapping call to ' + key)
old_fn.apply(@, arguments)