I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api
Rails.application.routes.draw do
constraints subdomain: "api" do
scope module: "api" do
CURRENT_DATE=`date -Ru | sed 's/+0000/GMT/'` | |
CHECKSUM=$(echo -n "application/json,,/transactions,$CURRENT_DATE" \ | |
| openssl dgst -sha1 -binary -hmac "your-secret-key" \ | |
| base64) | |
curl "https://apix.casiregalii.com/transactions" \ | |
-X POST \ | |
-d '{ | |
"account_number": "12345678998", | |
"amount": "2000.0", |
I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api
Rails.application.routes.draw do
constraints subdomain: "api" do
scope module: "api" do
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 |
#!/usr/bin/env ruby | |
require "openssl" | |
require 'digest/sha2' | |
require 'base64' | |
# We use the AES 256 bit cipher-block chaining symetric encryption | |
alg = "AES-256-CBC" | |
# We want a 256 bit key symetric key based on some passphrase | |
digest = Digest::SHA256.new |
#SOLID Principles with ruby examples
##SRP - Single responsibility principle A class should have only a single responsibility.
Every class should have a single responsibility, and that responsibility should be entirely encapsulated. All its services should be narrowly aligned with that responsibility, this embrace the high cohesion.
##OCP - Open/closed principle Software entities should be open for extension, but closed for modification.
require 'spec_helper' | |
# comment out `config.order = "random"` in spec_helper or run rspec with `--order default` configuration (just for illustration) | |
# I have Database Cleaner set up in spec_helper too | |
$count1 = 0 | |
$count2 = 0 | |
describe "let and let!" do | |
describe "let!" do |
I hereby claim:
To claim this, I am signing this object:
PASSWORD_FORMAT = /\A | |
(?=.{8,}) # Must contain 8 or more characters | |
(?=.*\d) # Must contain a digit | |
(?=.*[a-z]) # Must contain a lower case character | |
(?=.*[A-Z]) # Must contain an upper case character | |
(?=.*[[:^alnum:]]) # Must contain a symbol | |
/x | |
# validates_format_of :password, | |
# with: /\A(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*\z/ |
# fibonacci | |
# https://stackoverflow.com/questions/44837662/named-anonymous-functions-in-elixir/44837880#44837880 | |
defmodule Fibonacci do | |
def get(n) when n <= 1, do: 1 | |
def get(n), do: get(n-1) + get(n-2) | |
end | |
# Elixir how to iterate over two lists at once to produce a new list? | |
# https://stackoverflow.com/questions/44938494/elixir-how-to-iterate-over-two-lists-at-once-to-produce-a-new-list/44940454#44940454 |