Skip to content

Instantly share code, notes, and snippets.

View yoones's full-sized avatar
🔥
Con sentimiento y manana

Younes Serraj yoones

🔥
Con sentimiento y manana
View GitHub Profile
#!/usr/bin/env ruby
# https://twitter.com/smlpth/status/1693574834179961234
# "I have an array of amounts on one hand and a target amount on the other. I need to find a combination of amounts in the array that sums to the target. If multiple combinations work, take the one containing the most recent amounts."
require 'logger'
logger = Logger.new(STDOUT)
logger.level = :debug # set it to info to only see matches
# logger.level = :info
@yoones
yoones / initialize.rb
Created May 19, 2019 20:21
initialize!
# Initialize the application passing the given group. By default, the
# group is :default
def initialize!(group = :default) #:nodoc:
raise "Application has been already initialized." if @initialized
run_initializers(group, self)
@initialized = true
self
end
def run_initializers(group = :default, *args)
return if instance_variable_defined?(:@ran)
# Load the Rails application.
require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
@yoones
yoones / config.ru
Created May 19, 2019 20:20
config.ru
# This file is used by Rack-based servers to start the application.
require_relative 'config/environment'
run Rails.application
@yoones
yoones / server_options.rb
Created May 19, 2019 20:20
server options
class_option :config, aliases: "-c", type: :string, default: "config.ru",
desc: "Uses a custom rackup configuration.", banner: :file
# [...]
def server_options
{
user_supplied_options: user_supplied_options,
server: using,
log_stdout: log_to_stdout?,
@yoones
yoones / application_class.rb
Created May 19, 2019 20:19
application class
module Iluvrails
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
end
end
@yoones
yoones / all.rb
Created May 19, 2019 20:18
rails/all.rb
# frozen_string_literal: true
# rubocop:disable Style/RedundantBegin
require "rails"
%w(
active_record/railtie
active_storage/engine
action_controller/railtie
action_view/railtie
action_mailer/railtie
active_job/railtie
@yoones
yoones / application.rb
Created May 19, 2019 20:17
./config/application.rb
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Iluvrails
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
@yoones
yoones / perform.rb
Created May 19, 2019 20:17
perform method
def perform
extract_environment_option_from_argument
set_application_directory!
prepare_restart
Rails::Server.new(server_options).tap do |server|
# Require application after server sets environment to propagate
# the --environment option.
require APP_PATH
Dir.chdir(Rails.application.root)
if server.serveable?
@yoones
yoones / commands.rb
Created May 19, 2019 20:16
rails/commands
# frozen_string_literal: true
require "rails/command"
aliases = {
"g" => "generate",
"d" => "destroy",
"c" => "console",
"s" => "server",
"db" => "dbconsole",
"r" => "runner",
"t" => "test"