Skip to content

Instantly share code, notes, and snippets.

View makaroni4's full-sized avatar

Anatoli Makarevich makaroni4

View GitHub Profile
@makaroni4
makaroni4 / dup_finder.rb
Created May 6, 2015 19:55
Duplicates finder
require 'digest/md5'
hash = {}
dirname = "files"
Dir.glob("#{dirname}/**/*", File::FNM_DOTMATCH).each do |filename|
next if File.directory?(filename)
# puts 'Checking ' + filename
key = Digest::MD5.hexdigest(IO.read(filename)).to_sym
RSpec::Matchers.define :terminate do |code|
actual = nil
def supports_block_expectations?
true
end
match do |block|
begin
block.call
@makaroni4
makaroni4 / duolingo.js
Created September 27, 2015 21:12
Grace Monkey script to show the remain lessons count
$(function(){
function drawLessonsCount(count) {
$(".topbar-nav-main").append("<li style='display: block; color: #fff; padding: 8px 15px;'>Осталось уроков: " + count + "</li>");
}
function countLessons() {
var count = 0;
$(".lessons-left").each(function(index, element) {
var text = $(element).text();
def toss
(rand * 100) > 60 ? 1 : 2
end
# Both players bet on 1
def game
toss_1 = toss()
toss_2 = toss()
if toss_1 == 1 && toss_2 != 1
(function() {
function hideBoringArticles(nodes) {
nodes.filter("article.badge-entry-container.badge-entry-entity").each(function(i, el) {
if($(el).data("entryVotes") < 20000) {
$(el).hide();
}
})
}
var MutationObserver = window.MutationObserver;
@makaroni4
makaroni4 / trim_column.sql
Created December 11, 2015 15:57
Remove all non digit symbols from column in PostgreSQL
update fb_audiences
set facebook_id = replace(facebook_id, '[^0-9]+$', '');
SELECT id, facebook_id
FROM fb_audiences
WHERE facebook_id ~ '[^0-9]+$'
input = ["red", "green", "blue", "red", "blue"]
output = input.each_with_object(Hash.new(0)) do |word, o|
o[word] += 1
end
p output
# {"red"=>2, "green"=>1, "blue"=>2}
SELECT
age(now(), query_start) AS duration,
state,
pid,
query,
datname,
application_name,
waiting
FROM pg_stat_activity
ORDER BY duration DESC NULLS LAST;
ALTER TABLE mc_subscribers ADD COLUMN id BIGSERIAL;
UPDATE mc_subscribers SET id = nextval(pg_get_serial_sequence('mc_subscribers', 'id'));
ALTER TABLE mc_subscribers ADD PRIMARY KEY (id);
@makaroni4
makaroni4 / code.c
Last active October 12, 2016 12:40
Sample C program for VG
#include <stdio.h>
long long int myfunc (long long int i, long long int cache[])
{
if(cache[i]) {
return cache[i];
}
if (i <= 2) {
return i;