Skip to content

Instantly share code, notes, and snippets.

@AlxGolubev
AlxGolubev / libv8
Last active August 29, 2015 14:19
Installing libv8 gem on OS X 10.9+
`bundle config build.libv8 --with-system-v8`
then run
`bundle install`
@AlxGolubev
AlxGolubev / user_recent_media
Created May 6, 2015 16:24
User Recent Media result (methods)
Enumerable#methods:
all? detect each_slice entries find_all group_by lazy max_by min_by none? reduce slice_when to_set
chunk each_cons each_with_index exclude? flat_map index_by many? member? minmax one? slice_after sort_by
collect_concat each_entry each_with_object find grep inject max min minmax_by partition slice_before sum
JSON::Ext::Generator::GeneratorMethods::Array#methods: to_json_without_active_support_encoder
V8::Conversion::Array#methods: to_v8
Columnize#methods: columnize columnize_opts columnize_opts=
Array#methods:
& as_json concat empty? fourth keep_if product rindex size to_a to_xml
* assoc count eql? from last push rotate slice to_ary transpose
@AlxGolubev
AlxGolubev / association.md
Last active April 7, 2017 17:25
Способ загрузки ассоциаций при использовании find_by_sql

При выполнении сложных запросов, часто бывает необходимо выполнить предзагрузку данных об ассоциациях какой либо модели. Обычно сложные запросы выполняються через find_by_sql, например

Post.find_by_sql "SELECT p.name, c.author FROM posts p, comments c WHERE p.id = c.post_id"
> [#<Post:0x36bff9c @attributes={"title"=>"Ruby Meetup", "first_name"=>"Quentin"}>, ...]

Чтобы при вывзове ассоциаций объектов избежать проблемы с select(n+1) запросами в Rails существует eager-loading, например:

@AlxGolubev
AlxGolubev / rubymine.vmoptions
Last active February 23, 2017 09:43
Rubymine Config for Memory Optimization
-Xms128m
-Xmx1024m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=128m
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
-agentlib:yjpagent=probe_disable=*,disablealloc,disabletracing,onlylocal,disableexceptiontelemetry,delay=10000,sessionname=RubyMine80
{
"_index":"agreement_versions_development",
"_type":"agreement_version",
"_id":"294",
"_score":1.7475108,
"_source":{
"agreement":{
"template":{
"name":"Software Licensing Agreement",
"uuid":"23fbd237-2923-48dc-898e-bd13d8f3c392"
@AlxGolubev
AlxGolubev / jobs_mover.rb
Last active June 5, 2017 14:09
Class for case when queue for worker was changed but there are a lot of scheduled jobs in queue previously used
class JobsMover
BATCH_SIZE = 100
def initialize(original_queue, klass)
@original_queue = Sidekiq::Queue.new(original_queue)
@klass = klass
end
def move
jobs = @original_queue.select { |job| job.item['class'] == @klass }
@AlxGolubev
AlxGolubev / update-json-in-postgres.sql
Created June 26, 2017 16:41
How to create a new key in existing record with JSONB field in Postgres
UPDATE users SET preferences = jsonb_set(to_jsonb(preferences), '{some_preference}'::text[], 'true'::jsonb, true);
const R = require('ramda')
const kind = 'desc'
let collection = {
nodes: [
{
name: 'Items',
children: [
{
import {
FILTER_CATEGORIES_CONSTANTS,
generateInitialObjForAdvSearchFilters
} from 'routes/AdvanceSearch/helpers/Utils'
export const ADVANCE_SEARCH_FILTER_FORM_INITIAL = generateInitialObjForAdvSearchFilters(
FILTER_CATEGORIES_CONSTANTS
)
module Resource
def connection(routes)
if routes.nil?
puts "No route matches for #{self}"
return
end
loop do
print 'Choose verb to interact with resources (GET/POST/PUT/DELETE) / q to exit: '
verb = gets.chomp