Skip to content

Instantly share code, notes, and snippets.

View damirm's full-sized avatar

Damir Makhmutov damirm

  • Yandex
  • Russia, Moscow
View GitHub Profile
@damirm
damirm / 1_ruby_quicksort.rb
Last active December 27, 2015 08:19
Here are some things you can do with Gists in GistBox.
# Use Gists to store entire functions
class QuickSort
def self.sort!(keys)
quick(keys,0,keys.size-1)
end
private
def self.quick(keys, left, right)
@damirm
damirm / shift_array_elements.js
Last active June 12, 2024 08:50
Javascript shift array elements left/right by N positions
/**
* Fast method
*/
function shift(arr, direction, n) {
var times = n > arr.length ? n % arr.length : n;
return arr.concat(arr.splice(0, (direction > 0 ? arr.length - times : times)));
}
/**
* Slow method
@damirm
damirm / convert_currencies.sql
Last active August 29, 2015 14:07
Convert currencies
CREATE FUNCTION `convert_currency`(cur_from INT, cur_to INT, amount DOUBLE, rate_rub DOUBLE, rate_dollar DOUBLE, rate_euro DOUBLE)
RETURNS double DETERMINISTIC
BEGIN
DECLARE result DOUBLE DEFAULT amount;
DECLARE delta DOUBLE;
DECLARE TYPE_DOLLAR INT;
DECLARE TYPE_EURO INT;
DECLARE TYPE_RUBLES INT;
@damirm
damirm / sum.js
Last active August 29, 2015 14:11
Sum function with carring
function sum(n) {
var self = sum;
if (typeof n === 'undefined') {
var result = self.numbers.reduce(function (prev, next) { return prev + next; }, 0);
self.numbers = [];
return result;
}
if ( ! self.numbers ) { self.numbers = [] };
@damirm
damirm / parse_links_tmp
Last active August 29, 2015 14:13
php parse links test
@damirm
damirm / wait_for_seconds.js
Created March 27, 2015 22:23
Wait for seconds
var waitSeconds = function (seconds) {
if (waitSeconds.promise) {
return waitSeconds.promise;
}
var defer = $.Deferred();
setTimeout(function () {
defer.resolve();
}, 1000 * seconds);
var $_GET = (function () {
var getParams;
return function (param) {
if ( ! getParams ) {
getParams = decodeURIComponent(window.location.search.slice(1))
.split('&')
.reduce(function _reduce (a, b) {
b = b.split('=');
a[b[0]] = b[1];
@damirm
damirm / kolor.moro.es Clicker
Created May 14, 2015 11:51
kolor.moro.es Clicker
function find() {
var bg = document.getElementById('kolor-kolor').style.backgroundColor;
var options = document.querySelectorAll('#kolor-options a');
[].slice.call(options, 0).forEach(function (el) {
var clickEvent = new Event('click'),
dest = el;
if (el.style.backgroundColor == bg) {
el.style.border = "10px solid red";
el.dispatchEvent(clickEvent);

Keybase proof

I hereby claim:

  • I am damirm on github.
  • I am damirm (https://keybase.io/damirm) on keybase.
  • I have a public key whose fingerprint is A3DF 90E6 8DE3 2B24 0BEC 3E54 C846 4F13 7B90 5E9B

To claim this, I am signing this object: