Skip to content

Instantly share code, notes, and snippets.

@havran
havran / pluck_to_hash_example.rb
Created April 8, 2016 09:00
GEM pluck to hash example
if @records
posts = @records.map{|p| p.post_id}
posts_extra_data = Message::Post
.joins(
'LEFT JOIN "message_webs" ON "message_webs"."post_id" = "message_posts"."id"',
'LEFT JOIN "source_sources" ON "source_sources"."id" = "message_posts"."source_source_id"',
'LEFT JOIN "source_sections" ON "source_sections"."id" = "message_posts"."source_section_id"'
)
.where(id: posts)
{
"head": [
{
"CoType": "CoType",
"objects": "objects",
"objects_avg_quality": "objects_avg_quality"
}
],
"rows": [
{
#!/bin/bash
# CentOS rbenv system wide installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv system wide on CentOS 5/6, also allows single user installs.
# Install pre-requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel \
make bzip2 autoconf automake libtool bison iconv-devel git-core
# Store CBRFilter objects
#
class CBRFilters
include Enumerable
extend Forwardable
attr_accessor :filters
def_delegators :@filters, :each, :size, :<<, :push
@havran
havran / Crb.rb
Last active August 29, 2015 14:17
Simple Ruby on Rails 4 model with ElasticSearch query.
require 'elasticsearch/model'
class Cbr
include ActiveModel::Model
include Elasticsearch::Model
index_name 'cbr'
document_type 'UC_CBR_003'
# Digital Objects per day
/**
* Implements callback_redirect_form().
*/
function commerce_monogram_redirect_form($form, &$form_state, $order, $payment_method) {
$wrapper = entity_metadata_wrapper('commerce_order', $order);
switch ($payment_method['method_id']) {
case 'monogram_tatrapay_tb':
break;
case 'monogram_eplatby_vub':