Skip to content

Instantly share code, notes, and snippets.

@zloyrusskiy
zloyrusskiy / gist:b709dcb4601a8823f20f
Created June 16, 2014 13:33
bufferedDelay JS function
bufferedDelay = (function () {
var delays = {};
return function (alias, delay, callback) {
if (delays[alias]) {
clearTimeout(delays[alias]);
}
delays[alias] = setTimeout(function () { delete delays[alias]; callback(); }, delay);
}
})();
#include <iostream>
using namespace std;
int main() {
char * str { "Hello" };
int * int_hz = (int *) str;
cout << str << endl;
@zloyrusskiy
zloyrusskiy / gist:314c5b231d54dbe8ba13
Created April 6, 2015 10:02
Move location from one to another
SET @from_loc := 'ChIJ2aunYmllQTQRntXu6lNDlCU';
SET @to_loc := 'ChIJ-yRniZpWPEURE_YRZvj9CRQ';
START TRANSACTION;
# получение начальных данных
SELECT id, path, `level` INTO @from_id, @from_path, @from_level FROM locations WHERE place_id = @from_loc;
SELECT id, path, `level` INTO @to_id, @to_path, @to_level FROM locations WHERE place_id = @to_loc;
SET @new_path := CONCAT(@to_path, @to_id, ',');
require 'nokogumbo'
require 'uri'
def print_parents visited, path
parent = path
while parent = visited[parent]
puts "parent: %s" % URI.unescape(parent)
end
end
@zloyrusskiy
zloyrusskiy / gist:4d1287ebf637ecf65e16
Last active August 29, 2015 14:25
Mini stopwatch
=begin
использовать:
stopwatch 'parsing' do
# код, производительность которого надо замерять
end
=end
def stopwatch message, &block
@zloyrusskiy
zloyrusskiy / detect_language.rb
Last active August 29, 2015 14:25
Denu detect words
def detect_language words
if Array(words).any? { |w| w =~ /\p{Cyrillic}/ }
364
elsif Array(words).any? { |w| w =~ /\p{Hangul}/ }
0 # тут корейский код, неебу какой
else
124
end
end
def more_than_medium string
words = string.split /\W+/
return [] if words.empty?
avg = words.inject(0) { |res, w| res += w.size; res } / words.size
words.select { |w| w.size > avg }
end
@zloyrusskiy
zloyrusskiy / bashrc-part.sh
Created April 28, 2016 11:03
my bash promt
PS1='\[\e[1;37m\]⌞ \[\e[1;32m\]\u\[\e[0;39m\]@\[\e[1;36m\]\h\[\e[0;39m\]:\[\e[1;33m\]\w\[\e[0;39m\]\[\e[1;35m\]$(__git_ps1 " (%s)")\[\e[0;39m\] \[\e[1;37m\]⌝\[\e[0;39m\]\n$ '
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
// add tests
suite.add('lowercase', function() {
let input = 'ai';
let dictionary = ['airplane','airport','apple','ball'];
var clean_str = input.replace(/[^a-z]+/gi,'').toLowerCase();
var OUTPUT_DIR = 'pics';
var fs = require('fs');
if (!fs.exists(OUTPUT_DIR)) {
fs.makeDirectory(OUTPUT_DIR);
}
var casper = require('casper').create({
verbose: true,