Skip to content

Instantly share code, notes, and snippets.

@the-spectator
the-spectator / requirements.txt
Last active March 29, 2024 10:50 — forked from nikhilweee/statement-to-excel.py
Convert HDFC Bank Credit Card statements from PDF to Excel
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
@the-spectator
the-spectator / unroutable_routes.rake
Created May 31, 2022 19:41 — forked from natematykiewicz/unroutable_routes.rake
Find routes that will raise a routing error when requested
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 }.
@the-spectator
the-spectator / 0. nginx_setup.sh
Created November 17, 2020 20:34 — forked from mikhailov/0. nginx_setup.sh
Nginx + secure pseudo-streaming
# 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
class LRUCache
attr_reader :lookup, :size
def initialize(size)
@lookup = {}
@size = size
end
def get(key)
return unless lookup[key]
# 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
class User
STATUSES = [:active, :pending]
attr_accessor :status
def initialize(status = :pending)
@status = status
end
STATUSES.each do |value|
# 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
@the-spectator
the-spectator / ruby_config_usage.rb
Created August 22, 2020 17:02
Ruby config object usage
# Configuring using configuration object
ApplicationConfig.configure do |config|
config.logger = Logger.new(STDOUT)
config.async_enabled = true
end
@the-spectator
the-spectator / ruby_config.rb
Created August 22, 2020 16:59
ActiveSupport Configurable example
require 'active_support/configurable'
# Defination of config Object
class ApplicationConfig
include ActiveSupport::Configurable
config_accessor :logger
config_accessor :log_level do
:debug
@the-spectator
the-spectator / SomeRubyCode.rb
Created February 7, 2020 15:25
Closure memeonization in ruby, It's magical
# 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}"