This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "ostruct" | |
class User | |
def initialize(basic_params) | |
@json_params = OpenStruct.new(basic_params) | |
end | |
def full_name | |
[ | |
@json_params.first_name, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rules": { | |
".read": false, | |
".write": false, | |
"incremental_counter": { | |
".validate": "newData.isNumber() && newData.val() === data.val() + 1", | |
".read": true, | |
".write": true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'benchmark/ips' | |
Benchmark.ips do |r| | |
r.report("+ ") do | |
42 + 42 | |
end | |
r.report("* ") do | |
42 * 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
age(now(), query_start) AS duration, | |
state, | |
pid, | |
query, | |
datname, | |
application_name, | |
waiting | |
FROM pg_stat_activity | |
ORDER BY duration DESC NULLS LAST; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'parser' | |
require 'parser/current' | |
module OneLetterVariableDetector | |
class NodeAnalyzer < Struct.new(:node, :path) | |
def analyze | |
return unless node && node.respond_to?(:type) | |
if node.type == :lvasgn || node.type == :lvar | |
if lvar_name.size == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_path.each do |obj| | |
result << obj.obj_id | |
end if train_path.any? | |
# | |
# 1. Если ты вызываешь метод .each, то как минимум переменная | |
# должна иметь множественное число, это ведь коллекция (массив), | |
# т.е. это train_paths | |
# | |
# 2. Если массив пуст, то метод .each сразу вернет пустой массив |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
require 'csv' | |
ActiveRecord::Base.establish_connection( | |
adapter: "mysql2", | |
host: "localhost", | |
database: "36on_development", | |
user: "username", | |
password: "password", | |
pool: 5, |
NewerOlder