Skip to content

Instantly share code, notes, and snippets.

@IvikGH
IvikGH / transactions.markdown
Created September 24, 2018 13:13 — forked from jcasimir/transactions.markdown
Transactions

Transactions

As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.

Basics

All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.

Example

@IvikGH
IvikGH / heroku-remote.sh
Created November 22, 2017 16:25 — forked from randallreedjr/heroku-remote.md
Add a Heroku remote to an existing git repo
$ git remote add staging https://git.heroku.com/staging-app.git
$ git remote add heroku https://git.heroku.com/app.git
@IvikGH
IvikGH / nil_vs_empty_vs_blank_ror.md
Created September 27, 2017 07:13 — forked from Jellyfishboy/nil_vs_empty_vs_blank_ror.md
nil vs empty vs blank in Ruby on Rails

.nil? can be used on any object and is true if the object is nil.

.empty? can be used on strings, arrays and hashes and returns true if:

  • String length == 0
  • Array length == 0
  • Hash length == 0

Running .empty? on something that is nil will throw a NoMethodError.

@IvikGH
IvikGH / gist:56a2e2c7304f570b2df98f7982d52681
Created April 13, 2017 11:31 — forked from aereal/gist:2802359
Guardfile for Rails with Factory Girl
guard 'rspec', version: 2, cli: File.read('.rspec').each_line.map(&:strip).join(' '), all_after_pass: false, all_on_start: false do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
@IvikGH
IvikGH / \lib\systemd\system\sidekiq-static.service
Created February 19, 2017 10:17 — forked from dsadaka/\lib\systemd\system\sidekiq-static.service
systemd unit files for sidekiq service. note backslashes in filenames are really front slashes.
# This file actually fires up multiple sidekiq services.
# to start: systemctl start sidekiq.target
#
[Unit]
Description=Fire up up to 6 sidekiqs
# If you want more than 6 processes, append sidekiq@7.service, sidekiq@8.service, etc. to the ExecStart line below
# Note that only as many as have been enabled will actually start.
# Note also that the Unit data for each sidekiq process is in /lib/systemd/system/sidekiq@.service
[Service]
@IvikGH
IvikGH / release_ru.md
Created December 29, 2016 09:53 — forked from davydovanton/release_ru.md
OSSBoard release

Вы давно хотите заняться OpenSource разработкой, но никак не доходят руки?
У вас есть свой проект, но не хватает сил и времени на его поддержку?

На [OSS Board] (http://www.ossboard.org) мы собираем задачи, которые ждут своих героев.

How?

На создание OSS Board меня вдохновили два проекта.

@IvikGH
IvikGH / Links.txt
Created November 15, 2016 11:49 — forked from iBublik/Links.txt
Useful links
@IvikGH
IvikGH / Ruby_Rails_Naming_Conventions.md
Created October 18, 2016 09:49 — forked from alexpchin/Ruby_Rails_Naming_Conventions.md
Ruby & Rails Naming Conventions

Alex's Rails Cheat Sheet

I think the most confusing thing that I have found about Ruby on Rails so far has been the transition from (trying to) write code myself to the use of the fabled "Rails Magic". So, to help my own understanding of a few core Ruby on Rails concepts, I have decided to write something on what I think is a CRITICAL topic... the idea of Convention over Configuration and why (in my mind) it is the most important thing that helps Rails become magic!

(This may be a topic that we cover in more detail in class but as I said, I'm writing this for my own understanding... I hope it helps someone else understand things too... Perhaps you can give me a hand when I'm crying next week!)

##Convention over configuration ###What does this "actually" mean...

@IvikGH
IvikGH / index.html
Created August 28, 2016 13:28 — forked from d3noob/index.html
OSMGeocoder plugin for Leaflet.
<!DOCTYPE html>
<html>
<head>
<title>osmGeocoder Search Plugin for Leaflet Map</title>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css"
/>
<link
@IvikGH
IvikGH / fiddle.html
Created July 8, 2016 18:43 — forked from WarFox/fiddle.html
Change html content with vanilla javascript
<div id="myelement">Old Text</div>