This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
camelot-py==0.11.0 | |
cffi==1.16.0 | |
chardet==5.2.0 | |
charset-normalizer==3.3.2 | |
click==8.1.7 | |
cryptography==42.0.5 | |
et-xmlfile==1.1.0 | |
ghostscript==0.7 | |
numpy==1.26.4 | |
opencv-python==4.9.0.80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Find routes that will raise a routing error when requested' | |
task unroutable_routes: :environment do | |
# A lot of this code was taken from how `rake routes` works | |
# https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/railties/lib/rails/commands/routes/routes_command.rb | |
require 'action_dispatch/routing/inspector' | |
unroutables = Rails.application.routes.routes. | |
map { |r| ActionDispatch::Routing::RouteWrapper.new(r) }. | |
reject { |r| r.internal? || r.engine? || r.path.starts_with?('/rails/') || !r.controller }. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nginx can serve FLV/MP4 files by pseudo-streaming way without any specific media-server software. | |
# To do the custom build we use 2 modules: --with-http_secure_link_module --with-http_flv_module | |
# This module "secure-link" helps you to protect links from stealing away. | |
# | |
# NOTE: see more details at coderwall: http://coderwall.com/p/3hksyg | |
cd /usr/src | |
wget http://nginx.org/download/nginx-1.5.13.tar.gz | |
tar xzvf ./nginx-1.5.13.tar.gz && rm -f ./nginx-1.5.13.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LRUCache | |
attr_reader :lookup, :size | |
def initialize(size) | |
@lookup = {} | |
@size = size | |
end | |
def get(key) | |
return unless lookup[key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Input service to return array of array [ ["Team A", "Team B", "win"] ] | |
class DummyData | |
def initialize | |
@data = <<~INPUT | |
Team B;Team C;win | |
Team A;Team D;draw | |
Team A;Team B;win | |
Team D;Team C;loss | |
Team C;Team A;loss | |
Team B;Team D;win |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
STATUSES = [:active, :pending] | |
attr_accessor :status | |
def initialize(status = :pending) | |
@status = status | |
end | |
STATUSES.each do |value| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example 1: Solution | |
# Assuming Address is polymorphic, filtering results by addressable_type = 'User' will only | |
# give result for user addresses. #present? returns false for nil & "" (empty string) hence | |
# filtering with not condition. | |
def get_addresses | |
Address.where(addressable_type: 'User'). | |
where.not(city: [nil, ""]). | |
to_a | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configuring using configuration object | |
ApplicationConfig.configure do |config| | |
config.logger = Logger.new(STDOUT) | |
config.async_enabled = true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/configurable' | |
# Defination of config Object | |
class ApplicationConfig | |
include ActiveSupport::Configurable | |
config_accessor :logger | |
config_accessor :log_level do | |
:debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Closure memeonization in ruby | |
# It's magical | |
Role::TYPES.each do |key, name| | |
puts "before nil assignment #{ivar.object_id}" rescue "------" | |
ivar = nil | |
puts ivar.object_id, ivar | |
define_method(:"#{key}_role") do | |
puts "Inside Role: #{ivar.object_id}" |
NewerOlder