Skip to content

Instantly share code, notes, and snippets.

View fespinoza's full-sized avatar

Felipe Espinoza fespinoza

View GitHub Profile
@fespinoza
fespinoza / example.swift
Created January 9, 2022 20:36
Shimmer Animation Over Content
import SwiftUI
/*
## Animated highlight over redacted code
To actually try to get a loading shimmer animation on redacted content
Interesting concepts:
- overlay + `.blendMode`
@fespinoza
fespinoza / presentation.md
Created February 27, 2018 09:59
Priorities and micro habits

build-lists: true

Priorities & Micro-Habits


^ share my personal process

^ take inspiration and apply to your life

@fespinoza
fespinoza / README.md
Last active June 23, 2017 08:29
Holding model migration scripts

Instructions 12/06/2017

this code is supposed to be run in the rails console.

TODO:

  • run fix_varner_organizations.rb
  • for each organization identifier: (cubus, dressmann, urban... except carlings) do:
    • set env variable MYCHAIN_SYNCED_ORGANIZATIONS to the organization_identifier in production.
  • run a clean mychain import: make sure there is no MyChainSync record with organization_identifier = 'varner', also modify the MYCHAIN_SYNCED_ORGANIZATIONS to have one organization at a time, for not having problems with memory on production.
@fespinoza
fespinoza / groups.md
Last active January 12, 2017 14:33
Webhook proposal

Update/Create/Delete Group

  • which group associations do we include? parents, children, both? how many?
  • what if the associated groups are not yet created: order of request matter

Request

Url

POST https://cubus.motimateapp.com/api/webhooks/mychain
@fespinoza
fespinoza / example.rb
Created September 22, 2016 06:49
Ruby 2.3 heredocs
# frozen_string_literal: true
module Organization
class Group
# belongs_to :parent, class_name: 'Organization::Group'
# has_many :children, class_name: 'Organization::Group',
# foreign_key: :parent_id
# has_many :group_memberships, dependent: :destroy
# has_many :users, through: :group_memberships
RECURSIVE_UP = <<SQL.freeze
@fespinoza
fespinoza / README.md
Created June 2, 2016 13:40
Bug Reproduction: ActiveRecord::StatementInvalid: PG::DuplicatePstatement: ERROR: prepared statement "XXX" already exists

Bug Reproduction: ActiveRecord::StatementInvalid: PG::DuplicatePstatement: ERROR: prepared statement "XXX" already exists

so basically here in postgres_adapter.rb I am manually raising a raise Rack::Timeout::RequestTimeoutError and if that exception is captured, the code continues to execute, then the next time the code wants to access the DB the PG::DuplicatePstatement: ERROR will occurr.

the way to solve this is to add a begin/ensure block to the affected area to make sure prepared statements are generated correctly

NOTE: i raise the error when the counter gets to 130 since this method is excecuted many times

@fespinoza
fespinoza / error_normalization.rb
Created November 30, 2015 20:46
Error Normalization Concern
module ErrorNormalization
extend ActiveSupport::Concern
included do
rescue_from CanCan::AccessDenied, with: :render_forbidden
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
rescue_from ActionController::ParameterMissing, with: :render_bad_request
end
def render_forbidden
Nov 03 17:56:52 rema-mine-ansatte app/web.4: source=rack-timeout id=5cbf5e4f-1011-4b45-8205-8ce70df979dd wait=94ms timeout=29000ms state=ready
Nov 03 17:56:52 rema-mine-ansatte app/web.4: Processing by API::V1::EmployeesController#create as JSON
Nov 03 17:56:52 rema-mine-ansatte app/web.4: Started POST "/api/v1/stores/1111/employees.json" for 62.92.0.125 at 2015-11-03 16:56:51 +0000
Nov 03 17:56:52 rema-mine-ansatte app/web.4: Parameters: {"employee"=>{"address"=>"Ratvikveien 435", "age_group"=>"", "bank_account_number"=>"[FILTERED]", "birthdate"=>"1974-06-30", "city"=>"Åfjord", "collective_agreement"=>"1", "complete"=>"", "country_code"=>"NO", "display_name"=>"Anita Helen By", "draft_id"=>"5638e319633532000d000000", "email_address"=>"anitaby@hotmail.com", "employment_percent"=>"13.33333333333333", "employment_type"=>"1", "end_date"=>"", "first_name"=>"Anita Helen", "hourly_pay_entry_date"=>"2015-11-03 00:00:00 +0000", "hourly_pay_level"=>"9", "hourly_pay_premium_currency"=>"", "hourly_pay_premium_pe

Practical Web APIs, rails' style

Me

  • I am about to say many stupid stuff, mostly based on experience

What is an API

Definition

Create New CatVideo

Rationale

because cats are awesome, i want to save all videos i can find about them

Request

Url