Skip to content

Instantly share code, notes, and snippets.

View CarlosLeonCode's full-sized avatar
🦁
Music and code!

CarlosLeonCode CarlosLeonCode

🦁
Music and code!
View GitHub Profile
@CarlosLeonCode
CarlosLeonCode / transactions.rb
Created October 5, 2022 17:07
Dry transactions
# frozen_string_literal: true
require 'ruby_jard'
require "dry/transaction"
class AskError < StandardError; end
class MakeLunch
include Dry::Transaction
@CarlosLeonCode
CarlosLeonCode / colas.py
Last active May 26, 2022 02:36
Pilas y Colas en python.
from collections import deque
zoologico = deque()
zoologico.append('Mono')
zoologico.append('Elefante')
zoologico.append('Cocodrillo')
zoologico.append('Gato')
# print(f'Los animales de zoologico son {zoologico}')
@CarlosLeonCode
CarlosLeonCode / Variables_in_ruby.rb
Created March 20, 2021 21:12
Variables in Ruby!
# Variables in ruby 🦁
# Types
# 👉 Global -> $
# 👉 Instance -> @
# 👉 Class -> @@
# 👉 Local myvar
# 👉 Constants MYCONSTANT
# --- 🔥 Global variable
@CarlosLeonCode
CarlosLeonCode / aliases.zshrc
Last active January 21, 2025 15:13
bash aliases
# ==================================================
# Aliases
# ==================================================
# Ruby
alias rb='ruby'
alias irb='irb --simple-prompt'
alias gemi='gem install'
alias gemu='gem update'
alias geml='gem list'
@CarlosLeonCode
CarlosLeonCode / Dig in Ruby.rb
Created March 9, 2021 17:26
Dig method in Ruby
characters = [
{ name: 'Naruto', powers: ['rasengan', 'modo sabio'], age: 12 , friends: [ { name: 'sakura' } ]}
]
# --- Normal way
puts " -- Normal way"
puts characters[0][:name] # rta => Naruto
puts characters[0][:powers][0] # rta => rasengan
puts characters[0][:age] # rta => 12
puts characters[0][:friends][0][:name] # rta => sakura
@CarlosLeonCode
CarlosLeonCode / Hashes on ruby.rb
Last active March 9, 2021 17:27
Hashes_on_ruby
# Creating a Hash
data = Hash.new
data = Hash[]
data = {}
# Either way has the same result
# Creating has with values
user = { name: 'carlos', lastname: 'leon', nickname: 'CarlosLeonCode', OS: 'windows' }
# retrieving hash value
p user[:name] # out => "carlos"
@CarlosLeonCode
CarlosLeonCode / arrays_on_ruby_part_3.rb
Last active March 9, 2021 17:28
Arrays on Ruby - part 3
# -> | Array Methods on Ruby
# Points
rate = [1, 2, 2]
# -> | Sum
p rate.sum
# out -> 5
# -> | Create an array from a string
p numbers = %w"1 2 3 4 5 6 7 8 9 " # ! Literals
@CarlosLeonCode
CarlosLeonCode / arrays_on_ruby_part_2.rb
Last active March 9, 2021 17:29
Arrays on Ruby - part 2
# -> Creating Array
books = [
'Harry Potter and Philosopher\'s Stone',
'Maze Runner',
'La Ciudade de los umbrales'
]
# -> Adding Elements
books << 'Game Of Thrones'
p books.push('Fantastic Beasts')
@CarlosLeonCode
CarlosLeonCode / arrays_on_ruby_part_1.rb
Last active March 9, 2021 17:29
Arrays on Ruby - part 1
# -> Creating Array
# First option
books = [
'Harry Potter and Philosopher\'s Stone',
'Maze Runner',
'La Ciudade de los umbrales'
]
# Second option
p songs_lst_one = Array.new
# out => []