Skip to content

Instantly share code, notes, and snippets.

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

@googya
googya / ..git-pr.md
Created February 18, 2017 08:16 — forked from gnarf/..git-pr.md
git pr - Global .gitconfig aliases for Pull Request Managment

Install

Either copy the aliases from the .gitconfig or run the commands in add-pr-alias.sh

Usage

Easily checkout local copies of pull requests from remotes:

  • git pr 4 - creates local branch pr/4 from the github upstream(if it exists) or origin remote and checks it out
  • git pr 4 someremote - creates local branch pr/4 from someremote remote and checks it out
@googya
googya / test-children.rb
Created February 22, 2017 08:31 — forked from mfazekas/test-children.rb
awesome-nested-set-children
# test-children.rb
# This is a stand-alone test case.
# Run it in your console with: `rubytest-children.rb`
# If you change the gem dependencies, run it with:
# `rm gemfile* && ruby test-children.rb`
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
# Rails master
@googya
googya / RxJS 5 Operators By Example.md
Created April 6, 2017 14:08 — forked from lyyourc/RxJS 5 Operators By Example.md
「译」RxJS 5 Operators By Example
@googya
googya / RxJS 5 Operators By Example.md
Created April 6, 2017 14:08 — forked from lyyourc/RxJS 5 Operators By Example.md
「译」RxJS 5 Operators By Example
@googya
googya / introrx.md
Created April 6, 2017 14:23 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@googya
googya / web-servers.md
Created May 16, 2017 06:32 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@googya
googya / gist:d8af34d9fd5f71e5d95b63aeed7aba7b
Created July 13, 2017 07:24 — forked from mxpv/gist:5262043
Git caret and tilde
http://paulboxley.com/blog/2011/06/git-caret-and-tilde
http://alblue.bandlem.com/2011/05/git-tip-of-week-git-revisions.html
@googya
googya / Redux-React-Counter-Example
Created July 19, 2017 06:46 — forked from rjmacarthy/Redux-React-Counter-Example
Redux and React Simple JSBIN
https://jsbin.com/debohu/1/edit?html,js,output

Redux higher order components

Sometimes we need to share props and behaviour between multiple components/containers. For that we can do a higher order component. Example:

Decorator component

Higher Order Component that will decorate other component: