Skip to content

Instantly share code, notes, and snippets.

View svenyurgensson's full-sized avatar

Yury Batenko svenyurgensson

View GitHub Profile
@svenyurgensson
svenyurgensson / ruby_meta.md
Created May 7, 2021 11:52 — forked from jamesyang124/ruby_meta.md
Ruby meta programming

#!/bin/ruby --verion => 2.0.0-p353

Self

In Ruby, self is a special variable that always references the current object.

  • Inside class or module definition, self refer to the Class or Module object.
  • Inside instance method, self refer to future instance object.
  • Inside class method, self refer to the class.i
@svenyurgensson
svenyurgensson / clean.el
Created May 10, 2020 07:05 — forked from rougier/clean.el
A very minimal but elegant emacs configuration file
(require 'org)
(setq-default indent-tabs-mode nil)
(setq org-display-inline-images t)
(setq org-redisplay-inline-images t)
(setq org-startup-with-inline-images "inlineimages")
(setq default-frame-alist
(append (list '(width . 72) '(height . 40))))

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

$('form .input.array').each(function() {
var $wrapper = $('.array-inputs', this);
var $insertArea = $(".array-input button[data-action=add]").closest(".array-input");
$(".array-input button[data-action=add]", $(this)).click(function(e) {
$('.array-input:first-child', $wrapper).clone(true).insertBefore($insertArea).find('input').val('').focus();
});
$('.array-input button[data-action=remove]', $wrapper).click(function() {
if ($('.array-input', $wrapper).length > 2) {
$(this).parent('.array-input').remove();
}
@svenyurgensson
svenyurgensson / privacy.md
Created December 30, 2017 17:38 — forked from veekaybee/privacy.md
A work-in-progress post on how to protect your data and privacy online

Work-in-progress

How to protect your data and privacy online for the average user

Table of Contents

  1. Introduction and Motivation 1a. About me
  2. Ad profiling: What can be tracked
  3. Government tracking: What can be tracked
  4. Low-effort
  5. Medium-effort
@svenyurgensson
svenyurgensson / github-to-bitbucket
Created December 19, 2017 05:23 — forked from sangeeths/github-to-bitbucket
Forking a Github repo to Bitbucket
Go to Bitbucket and create a new repository (its better to have an empty repo)
git clone git@bitbucket.org:abc/myforkedrepo.git
cd myforkedrepo
Now add Github repo as a new remote in Bitbucket called "sync"
git remote add sync git@github.com:def/originalrepo.git
Verify what are the remotes currently being setup for "myforkedrepo". This following command should show "fetch" and "push" for two remotes i.e. "origin" and "sync"
git remote -v
@svenyurgensson
svenyurgensson / rails http status codes
Created October 13, 2017 04:10 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@svenyurgensson
svenyurgensson / XORCipher.js
Created March 28, 2017 06:33 — forked from sukima/XORCipher.js
A Super simple encryption cipher using XOR and Base64 in JavaScript
// XORCipher - Super simple encryption using XOR and Base64
//
// Depends on [Underscore](http://underscorejs.org/).
//
// As a warning, this is **not** a secure encryption algorythm. It uses a very
// simplistic keystore and will be easy to crack.
//
// The Base64 algorythm is a modification of the one used in phpjs.org
// * http://phpjs.org/functions/base64_encode/
// * http://phpjs.org/functions/base64_decode/