Skip to content

Instantly share code, notes, and snippets.

View arefaslani's full-sized avatar

Aref Aslani arefaslani

View GitHub Profile
@arefaslani
arefaslani / Gemfile
Created July 12, 2021 17:41 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@arefaslani
arefaslani / medium-702687394e3d-calling-the-service.rb
Created September 13, 2020 17:35
Medium 702687394e3d-calling-the-service
class PostsController < ApplicationController
# ...
def create
Posts::Create.call(post_params.to_h) do |result|
result.success do |post|
render json: post, status: :ok
end
result.failure do |errors|
render json: errors, status: :unprocessable_entity
@arefaslani
arefaslani / medium-702687394e3d-cleaning-it-up.rb
Created September 12, 2020 15:54
Medium 702687394e3d-cleaning-it-up
module Posts
class Create
include ApplicationService
ValidationSchema = Dry::Schema.Params do
required(:title).filled(:str?)
optional(:body).maybe(:str?)
end
def execute(params)
@arefaslani
arefaslani / medium-702687394e3d-application-service.rb
Created September 12, 2020 15:53
Medium 702687394e3d-application-service
require 'dry/matcher/result_matcher'
module ApplicationService
module ClassMethods
def call(params, &block)
service_outcome = self.new.execute(params)
if block_given?
Dry::Matcher::ResultMatcher.call(service_outcome, &block)
else
service_outcome
@arefaslani
arefaslani / medium-702687394e3d-add-result-matcher.rb
Last active September 13, 2020 17:41
Medium 702687394e3d-add-result-matcher
require 'dry/matcher/result_matcher'
module Posts
class Create
include Dry::Monads[:result, :do]
ValidationSchema = Dry::Schema.Params do
required(:title).filled(:str?)
optional(:body).maybe(:str?)
end
@arefaslani
arefaslani / medium-702687394e3d-railway-oriented-programming.rb
Created September 12, 2020 11:48
Medium 702687394e3d-railway-oriented-programming
module Posts
class Create
include Dry::Monads[:result, :do]
ValidationSchema = Dry::Schema.Params do
required(:title).filled(:str?)
optional(:body).maybe(:str?)
end
def self.call(params)
@arefaslani
arefaslani / medium-702687394e3d-basic-api.rb
Last active September 11, 2020 14:54
Medium 702687394e3d-basic-api
module Posts
class Create
def self.call(params)
# Method body
end
end
end
const file = document.querySelector("input[type=file]").files[0];
const reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = () => {
const key = require("../arweave-keyfile.json");
const arweave = Arweave.init({
host: "arweave.net",
port: 443,
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./EIP712Base.sol";
contract EIP712MetaTransaction is EIP712Base {
using SafeMath for uint256;
bytes32 private constant META_TRANSACTION_TYPEHASH = keccak256(
bytes(
pragma solidity ^0.6.0;
contract EIP712Base {
struct EIP712Domain {
string name;
string version;
uint256 chainId;
address verifyingContract;
}