Skip to content

Instantly share code, notes, and snippets.

@kadru
kadru / lvh_ssl.md
Created September 6, 2019 15:43 — forked from dagjaneiro/lvh_ssl.md
lvh.me ssl

Install nginx

$ brew install nginx

Edit nginx.conf

$ vim /usr/local/etc/nginx/nginx.conf
@kadru
kadru / order-rails-controller-callbacks.md
Created April 6, 2019 01:52 — forked from WaKeMaTTa/order-rails-controller-callbacks.md
Order of Rails Controller Callbacks

Order of Rails Controller Callbacks

Rails 4.x

Started GET "/" for 127.0.0.1 at 2017-05-19 14:17:18 +0200
  Processing by WelcomeController#index as HTML
    prepend_around_action
    prepend_before_action
 before_action
@kadru
kadru / transactions.markdown
Created December 16, 2018 04:32 — 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

@kadru
kadru / rails http status codes
Created November 22, 2018 03:34 — 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
@kadru
kadru / webpacker_rails.md
Created October 15, 2018 04:41 — forked from maxivak/webpacker_rails.md
Webpack, Yarn, Npm in Rails
@kadru
kadru / stored_procedure_service.rb
Last active September 14, 2018 18:22 — forked from ys/stored_procedure_service.rb
Execute stored procedure
class DatabaseHelper
def self.select name, *args, &blk
execute "select", name, *args, &blk
end
def self.call name, *args, &blk
execute "call", name, *args, &blk
end
def self.execute via, name, *args, &blk
@kadru
kadru / singleton.rb
Created September 6, 2018 14:59 — forked from mssola/singleton.rb
Different ways to create the Singleton pattern in Ruby.
##
# This files shows some possible implementations of the Singleton pattern
# in Ruby. I'm not a huge fan of the Singleton pattern, but it's nice
# in some cases. In this file I'm going to implement a simple logger.
#
##
# The first implementation that can come to our minds is to create a class
# that holds an instance as a class variable that can be accessed through
@kadru
kadru / expressjs_with_godaddy_certs.md
Created July 6, 2018 23:21 — forked from nanusdad/expressjs_with_godaddy_certs.md
Express JS with GoDaddy SSL Certificates

How to use GoDaddy SSL certs with Express JS

  • Node requires each certificate in the CA chain to be passed separately in an array.
  • GoDaddy provides a cerficate file (gd_bundle.crt) probably looks like this:
-----BEGIN CERTIFICATE-----
MIIE3jCCA...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
@kadru
kadru / media-query.css
Created July 3, 2018 00:44 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS