Skip to content

Instantly share code, notes, and snippets.

@samokoder
samokoder / active_record_extension.rb
Created February 15, 2019 11:55 — forked from ozydingo/active_record_extension.rb
ActiveRecord left join
module ActiveRecordExtension
extend ActiveSupport::Concern
module ClassMethods
# Simple left join taking advantage of existing Rails & Arel code
def left_joins(*args)
inner_joins = self.joins(*args).arel.join_sources
left_joins = inner_joins.map do |join|
Arel::Nodes::OuterJoin.new(join.left, join.right)
end
@samokoder
samokoder / left_join_arel_example.rb
Created February 15, 2019 11:15 — forked from mildmojo/left_join_arel_example.rb
LEFT JOIN in ARel for ActiveRecord in Ruby on Rails
# Here's a contrived example of a LEFT JOIN using ARel. This is an example of
# the mechanics, not a real-world use case.
# NOTE: In the gist comments, @ozydingo linked their general-purpose ActiveRecord
# extension that works for any named association. That's what I really wanted!
# Go use that! Go: https://gist.github.com/ozydingo/70de96ad57ab69003446
# == DEFINITIONS
# - A Taxi is a car for hire. A taxi has_many :passengers.
# - A Passenger records one person riding in one taxi one time. It belongs_to :taxi.
@samokoder
samokoder / mysql-docker.sh
Created February 10, 2019 17:55 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@samokoder
samokoder / mongoDump.md
Created February 4, 2019 17:01 — forked from JaniAnttonen/mongoDump.md
Export Docker MongoDB collection as a JSON file

First, find the container that runs your MongoDB and ssh into it.

Then, find the collection you want to export:

mongo
show dbs
use <database>
show collections
exit
@samokoder
samokoder / my.cnf.old
Created April 19, 2018 09:53 — forked from wood-goblin/my.cnf.old
Percona mysql sample config: /etc/mysql/my.cnf
# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
[mysql]
# CLIENT #
port = 3306
socket = /var/lib/mysql/data/mysql.sock
[mysqld]
@samokoder
samokoder / Ruby_finance_testcase.md
Created July 9, 2017 14:48 — forked from beshkenadze/Ruby_finance_testcase.md
Тестовое задание для Ruby-разработчика

Задание

Реализовать на Ruby с использованием Rails приложение со следующим функционалом:

  1. Регистрация / авторизация пользователей.
  2. Создание портфеля акций (5-6 акций достаточно) для пользователя: стандартный CRUD.
  3. Данные должны скачиваться с Yahoo Finance.
  4. Сделать вывод графика "стоимость портфеля от времени" за 2 последних года по выбранным в п.2 акциям.

Требования