Skip to content

Instantly share code, notes, and snippets.

View 3zcurdia's full-sized avatar

Luis Ezcurdia 3zcurdia

  • Mexico City
  • 11:32 (UTC -06:00)
View GitHub Profile
#!/usr/bin/env ruby
require "nokogiri"
require "json"
module Cfdi
module_function
def parse_file(xml_path)
doc = Nokogiri::XML(File.read(xml_path))
@3zcurdia
3zcurdia / main.rb
Created April 27, 2022 15:41
Rails challenge
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
gem 'rails', '~> 7.0'
gem 'sqlite3'
end
require 'active_record'
@3zcurdia
3zcurdia / Gemfile
Last active March 18, 2022 20:32
RabbitMQ Basic Implementation
# frozen_string_literal: true
source "https://rubygems.org"
gem "bunny", "~> 2.19"
@3zcurdia
3zcurdia / death_toll.rb
Created May 20, 2021 02:26
Rick And Morty death toll
# frozen_string_literal: true
require 'json'
require 'net/http'
require 'concurrent'
class RickAndMorty
def character(id)
response = get_response("https://rickandmortyapi.com/api/character/#{id}")
return {} unless response.is_a?(Net::HTTPSuccess)
@3zcurdia
3zcurdia / config.ru
Created April 17, 2021 04:39
Rails App under 10 lines
require 'bundler/inline'; gemfile(true) { gem 'rails', '~> 6.1.3'; gem 'puma' }
require 'rails'; require 'action_controller/railtie';
Codes = Struct.new(:id) { def to_json(args = {}) = { id: id, hex: SecureRandom.hex, iat: Time.now.utc.to_i }.to_json(args) }
class CodesApp < Rails::Application
config.secret_key_base = '4bdd3baa5f573f06c71cfb0504273e7ed1cf95858d7be6268bd1c7f800bbd03e1169e89106a9cf99541ac1b75ad4685d731723a30660c2cc66912609fd008090'
Rails.logger = Logger.new($stdout)
end
Rails.application.routes.draw { get '/:id', to: lambda { |env| [200, { 'Content-Type' => 'application/json' }, [Codes.new(env['action_dispatch.request.path_parameters'][:id]).to_json]] } }
run CodesApp
@3zcurdia
3zcurdia / bomb.rb
Created September 7, 2020 22:43
Ruby memory bomb
class Bomb
def method_missing(meth, *args, &blk)
self.class.send(:define_method, "is_#{meth}?") { true }
send("is_#{meth}?")
end
end
if __FILE__ == $0
require 'SecureRandom'
loop { Bomb.new.send(SecureRandom.hex) }
@3zcurdia
3zcurdia / haml2erb.rb
Last active September 22, 2020 09:48
Haml to erb converter with herbalizer
#!/usr/bin/env ruby
require "httparty"
class Converter
def initialize(filename)
@content = File.open(filename).read
end
attr_reader :content
@3zcurdia
3zcurdia / auditor.rb
Last active April 16, 2020 18:03
Gemfile.lock auditor
#!/usr/bin/env ruby
require 'HTTparty'
require 'nokogiri'
require 'colorize'
require 'action_view'
class Analyzer
def initialize(gem)
@gem = gem
@3zcurdia
3zcurdia / Gemfile
Last active November 28, 2018 20:46
Ruby Serializers benchmark
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
ruby '2.3.8'
# Specify your gem's dependencies in ams_vs_jbuilder.gemspec
gemspec
gem 'benchmark-ips'
gem 'active_model_serializers', '0.9.4'
require 'digest'
NUM_ZEROES = 6
class Block
def find_nonce(message)
nonce = "HELP I'M TRAPPED IN A NONCE FACTORY"
count = 0
until valid_nonce?(nonce, message)
print '.' if count % 10_000 == 0