Skip to content

Instantly share code, notes, and snippets.

View delbetu's full-sized avatar
🏠
Working from home

M. Bellucci delbetu

🏠
Working from home
View GitHub Profile
@delbetu
delbetu / flatten_array.rb
Last active June 24, 2019 23:02
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
require 'minitest/autorun'
# This is not a production ready solution. Code doesn't explains itself it takes some time for the
# reader to reason about its execution under different cases.
# For a production ready solution I would think of using a stack and switch to an iterative solution
# rather than recursive.'
def flatten_array(arry)
return arry if arry.empty?
head, *tail = arry
if head.is_a?(Array)
class BarService
def foo(input_data)
...
if input_data.page
num = 45
output_data.notified_at_offset = notification_data_access.notified_at(input_data.page)
else
num = 10
end
output_data.notifications =
@delbetu
delbetu / initial_solution_controller.rb
Created February 15, 2019 18:49
These gists show a refactor which objective is isolate code that is part of a controller.
class IsolatedCode
def initialize(release_being_sent = { state: 'published' },
release)
@release_being_sent = release_being_sent
@release = release
end
def foo
ActiveRecord::Base.transaction do
if publishing?
@delbetu
delbetu / uniqueness_validator_spec.rb
Created November 6, 2017 18:55
Ruby Rspec - Class example
class UniquenessValidator
def initialize(sources: [])
@sources = sources
end
def run
# 'admin_intro_crm_basics', 'lex_migration_introduction', 'admin_intro_crm_basics'
top_level_ids = sources.map(&:find_all_top_level_ids).flatten
calculate_repeated!(top_level_ids)
self
context 'Test all instance methods' do
let(:test_user) { create(:th_user) }
let(:superbadge) do
create(
:th_superbadge,
api_name: 'test_super_badge',
first_ascent_points: 1000,
completion_points: 1000
)

Comments

every time you write a comment you failed. commented out code is an abomination that must be destroy before it spreads.

Formatting

white space discipline is important Be consistent horizontal scrolls will not be tolerated(between 40 and 120 columns) keep file sizes under control average between 100 lines and never exceed 500

@delbetu
delbetu / 01paradigms.rb
Last active October 11, 2022 08:02
Notes from - Gary Bernhardt boundaries talk.
# Procedural (Mutation and data separated from code)
# OO (Mutation and data combined with code)
# Functional Version (Imutability and data separated from code)
# FauxO Version (Immutability and data combined with code)
#Procedural-we have knowledge of the internals
def feeding_time
walruses.each do |walrus|
walrus.stomach << Cheese.new
end
@delbetu
delbetu / xss-injection.md
Created December 14, 2016 17:51
Cros Site Scripting

Cross-Site Scripting (XSS)

User injects client side executable code. User can add js-malicious code within user input boxes, parameters or cookies

HTML/JS injection

this
<script>alert('Hello');</script>
is the same as this
@delbetu
delbetu / angular_controller.md
Last active December 13, 2016 15:35
Angular Controller Test Example

Example Controller

    angular.module('sportAdmin')
      .controller('TournamentListController', function ($scope, Tournament, Sports, Alerts) {

        this.getTournaments = function(){
          this.tournaments = Tournament.all()
          this.sports = Sports.all()
          this.organization = $scope.organization
        }
@delbetu
delbetu / angular_factory.md
Created December 13, 2016 15:12
Angular Factory Test Example

##Example Service

  angular.module('sportAdmin')
    .factory('Tournament', function($resource, $q) {

      var baseUrl = '/api/tournaments/:tournamentId'

      var service = $resource(baseUrl, {tournamentId: '@id'})