Skip to content

Instantly share code, notes, and snippets.

@ktimothy
ktimothy / hierarchy.rb
Created December 6, 2021 09:19
This describes how to make hierarchy SQL-requests with Arel and Common Table Expressions (CTE)
def ancestors
# Please read descedants comments for the entire method
return Supplier.none unless persisted?
# The raw SQL query for getting ancestors could be like this.
# Please note the differences.
# sql = <<~SQL
# WITH recursive ancestors AS (
# SELECT * FROM suppliers_parent_suppliers s
class LogRequestAndResponse
def initialize(app); @app = app; end
def call(env)
req = Rack::Request.new(env)
headers = Hash[*env.select {|k,v| k.start_with? 'HTTP_'}
.collect {|k,v| [k.sub(/^HTTP_/, ''), v]}
.collect {|k,v| [k.split('_').collect(&:capitalize).join('-'), v]}
.sort
.flatten]
@ktimothy
ktimothy / README.md
Last active October 18, 2020 12:13
locust test suite
  1. устанавливаем locust.io (для него нужен python >=2.7):
python3 -m pip install locust
  1. запускаем командой
locust 
@ktimothy
ktimothy / restrict.rb
Created March 11, 2020 12:21
call `using` dynamically in ruby
module Restrict
def ololo
module Restrictions
def allow(method_name, *classes)
# puts self.instance_methods(false)
# puts Model.instance_methods(false)
# puts Model.singleton_class.instance_methods(false)
puts self
@ktimothy
ktimothy / README.md
Last active March 19, 2019 20:11
Almost dynamic refinement in ruby.

This allows to restrict some method calls and allow to only specific classes.

# frozen_string_literal: true
Sequel.migration do
up do
run 'CREATE EXTENSION IF NOT EXISTS "cube";'
run 'CREATE EXTENSION IF NOT EXISTS "earthdistance";'
end
down do
run 'DROP EXTENSION IF EXISTS "earthdistance";'
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@ktimothy
ktimothy / 0_reuse_code.js
Created April 12, 2016 08:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ktimothy
ktimothy / log_server_name.rb
Created November 7, 2015 11:38
An extension, that allows to log server name in sequel sharded environment. Useful for debugging, when you need to know where exactly your query is executed.
# This extension is useful for sharded environment.
# It logs server name, for which connection is picked from pool.
# Logging happens using Database::log_info method, so be sure to set logger to database.
# The extension simply overrides original pick_server method and logs server name argument.
module Sequel
module LogServerName
def self.extended(db)
pool = db.pool
# check if pool is sharded

Интеграция нового баннера

Новый баннер работает на html5, благодаря чему он работает в Chrome. Находится html5-версия внутри iframe, который теперь нужно вставлять на страницу вместо флешки. Адреса iframe для разных игр перечислены ниже.

Есть два баннера - верхний (тулбар) и нижний (ротатор). Они находятся на разных html-страницах. Сами iframe отличаются высотой.

Загадки Атлантиды

ok.ru