Skip to content

Instantly share code, notes, and snippets.

Anatoli Makarevich makaroni4

Block or report user

Report or block makaroni4

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@makaroni4
makaroni4 / incremental_counter_config.json
Last active Dec 20, 2018
Config incremental counter via Firebase Realtime Database
View incremental_counter_config.json
{
"rules": {
".read": false,
".write": false,
"incremental_counter": {
".validate": "newData.isNumber() && newData.val() === data.val() + 1",
".read": true,
".write": true
}
}
@makaroni4
makaroni4 / auto_benchmark_with_ips.rb
Created Dec 2, 2016
Code for blog post "Benchmarking with Ruby"
View auto_benchmark_with_ips.rb
require 'benchmark'
require 'benchmark/ips'
Benchmark.ips do |r|
r.report("+ ") do
42 + 42
end
r.report("* ") do
42 * 42
@makaroni4
makaroni4 / code.c
Last active Oct 12, 2016
Sample C program for VG
View code.c
#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;
View add serial primary key to existing table.sql
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);
View Monitor PG processes.sql
SELECT
age(now(), query_start) AS duration,
state,
pid,
query,
datname,
application_name,
waiting
FROM pg_stat_activity
ORDER BY duration DESC NULLS LAST;
View count_words.rb
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}
@makaroni4
makaroni4 / trim_column.sql
Created Dec 11, 2015
Remove all non digit symbols from column in PostgreSQL
View trim_column.sql
update fb_audiences
set facebook_id = replace(facebook_id, '[^0-9]+$', '');
SELECT id, facebook_id
FROM fb_audiences
WHERE facebook_id ~ '[^0-9]+$'
View filter_9gag.js
(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;
View unfair_coin.rb
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
@makaroni4
makaroni4 / duolingo.js
Created Sep 27, 2015
Grace Monkey script to show the remain lessons count
View duolingo.js
$(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();
You can’t perform that action at this time.