Skip to content

Instantly share code, notes, and snippets.

Bogdan Gusiev bogdan

Block or report user

Report or block bogdan

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
View tables_stats_grid.rb
class TablesStatsGrid < BaseDatagrid
scope do
[]
end
dynamic do
scope do
DatabaseUtils.use_shard(shard.presence) do
ActiveRecord::Base.connection.select_all("SHOW TABLE STATUS").to_ary
end
end
View bm.rb
require "benchmark/ips"
quiet_logger
c = ActiveRecord::Base.connection
mysql = c.instance_variable_get("@connection")
sql = "select * from users where id = 1"
Benchmark.ips do |x|
x.time = 5
x.warmup = 0.1
View json.js
var a = {
success: true,
rewarded: true,
coupon_code: 'aaa',
unredeem_reason: 'aaa',
friend_person: {
"first_name": "John",
"last_name": "Smith",
"email": "advocate@example.com",
"username": "sample",
View 20180420174111_kickbox_parallel_analysis.rb
100.times.to_a.map do |i|
HTTParty.get("#{Kickbox::KICKBOX_API_URL}/verify?email=fainevb837ehadk#{i}@hotmail.com&apikey=#{Kickbox.api_key}")
end
View 20180426120831_dev_shard_1_extraction.rb
require Rails.root.join 'support/2018/20180202160337_db_extraction'
class DevShard1Extraction < ActiveRecord::Migration[5.1]
extractor = DbExtraction.new
if extractor.db_match?
raise 'Please set the shard 1 DB to be different from primary DB. You may take the config/deploy/templates/database.yml or modify your own copy.'
end
shard 1
def change
return unless Rails.env.development?
View test.log
[2018-04-20 12:37:47.513] x27[1mx27[35m (11.0ms)x27[0m x27[1mx27[35mSET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci, @@SESSION.sql_mode = 'TRADITIONAL', @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483x27[0m
[2018-04-20 12:37:47.524] x27[1mx27[35m (0.2ms)x27[0m x27[1mx27[35mBEGIN /* shard nil master */x27[0m
[2018-04-20 12:37:47.524] x27[1mx27[35m (0.1ms)x27[0m x27[1mx27[35mBEGIN /* shard 1 master */x27[0m
[2018-04-20 12:37:48.336] x27[1mx27[35m (0.2ms)x27[0m x27[1mx27[35mSAVEPOINT active_record_1 /* shard nil master */x27[0m
[2018-04-20 12:37:48.362] x27[1mx27[36mAccount Exists (6.0ms)x27[0m x27[1mx27[34mSELECT 1 AS one FROM `accounts` WHERE `accounts`.`api_key` = BINARY 'XFgLPXsZRCUKD3lx68a' LIMIT 1 /* shard nil master */x27[0m
[2018-04-20 12:37:48.364] x27[1mx27[36mAccount Exists (0.3ms)x27[0m x27[1mx27[34mSELECT 1 AS one FROM `accounts` WHERE `accounts`.`name` = 'Account 1' LIMIT 1 /* shard nil master */x27[0m
[2018-04-20 12:37:48.392] x27[1mx27[35mSQL (0.5ms)x27[0m x
View spellgood
#!/usr/bin/env ruby
new_words = ARGV
file_name = File.dirname(__FILE__) + "/../.pronto_spell.pws"
lines = File.read(file_name)
words = lines.split("\n")
header = words.shift
new_words.each do |word|
unless words.include?(word)
words << word
end
View gist:5ef38bfa60bcd47b3495b8acb0967a5d
app/grids/people_grid.rb|102| scope.with_property_value(key.id, value, :cp_1)
app/grids/people_grid.rb|110| scope.with_property_value(key.id, value, :cp_2)
app/models/activity.rb|136| joins(offer: :person).merge(Person.with_property_value(key_id, value))
app/models/concerns/customizable_properties.rb|7| scope :with_property_value, ->(key_id, value, table_alias = :custom_properties) {
app/models/customer_email.rb|141| joins(offer: :person).merge(Person.with_property_value(key_id, value))
app/models/incentive_outcome.rb|99| joins(offer: :person).merge(Person.with_property_value(key_id, value))
app/models/offer.rb|120| joins(:person).merge(Person.with_property_value(key_id, value))
app/models/offer_share.rb|82| joins(:person).merge(Person.with_property_value(key_id, value))
app/models/referral.rb|248| joins(offer: :person).merge(Person.with_property_value(key_id, value))
app/models/visitor_offer.rb|133| joins(offer: :person).merge(Person.with_property_value(key_id, value))
View md.md

Fits

WHERE (`custom_properties`.`person_id` = 197950367 OR `custom_properties`.`visitor_id` = 1052274563) AND ...

WHERE (`campaigns`.`activates_at` BETWEEN '2018-02-22 14:30:07' AND '2018-02-22 14:30:54' OR `campaigns`.`expires_at` BETWEEN '2018-02-22 14:30:07' AND '2018-02-22 14:30:54') AND ...

WHERE (role='admin' OR staff_member=1) AND

WHERE (`incentive_outcomes`.`target_type` = "Referral" OR `referrals`.`status` IN ('approved','unblocked')) AND ...
View zz.diff
where(person_id: Person.find_by(email: email, site_id: site_id), site_id: site_id)
}
+ scope :by_coupon_list, ->(coupon_list_id) {
+ sub_query = Coupon.
+ joins('INNER JOIN `checkout_coupons` ON `checkout_coupons`.`coupon_id` = `coupons`.`id`').
+ where('`origins`.`id` = `checkout_coupons`.`purchase_id`').where(coupon_list_id: coupon_list_id)
+ where("exists (#{sub_query.to_sql})")
+ }
+
You can’t perform that action at this time.