Skip to content

Instantly share code, notes, and snippets.

View makaroni4's full-sized avatar

Anatoli Makarevich makaroni4

View GitHub Profile
require "ostruct"
class User
def initialize(basic_params)
@json_params = OpenStruct.new(basic_params)
end
def full_name
[
@json_params.first_name,
@makaroni4
makaroni4 / incremental_counter_config.json
Last active December 20, 2018 21:02
Config incremental counter via Firebase Realtime Database
{
"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 December 2, 2016 00:15
Code for blog post "Benchmarking with Ruby"
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 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;
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);
SELECT
age(now(), query_start) AS duration,
state,
pid,
query,
datname,
application_name,
waiting
FROM pg_stat_activity
ORDER BY duration DESC NULLS LAST;
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 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]+$'
(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;
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