Skip to content

Instantly share code, notes, and snippets.

Aws.config.update({
region: 'eu-west-1',
access_key_id: ENV['ACCESS_KEY_ID'],
secret_access_key: ENV['SECRET_ACCESS_KEY']
})
s3 = Aws::S3::Resource.new
bucket = s3.bucket("files")
@the-spectator
the-spectator / JEMALLOC.md
Created June 20, 2025 17:45 — forked from jjb/file.md
Using Jemalloc 5 with Ruby.md

For years, people have been using jemalloc with ruby. There were various benchmarks and discussions. Legend had it that Jemalloc 5 didn't work as well as Jemalloc 3.

Then, one day, hope appeared on the horizon. @wjordan offered a config for Jemalloc 5.

Ubuntu/Debian

FROM ruby:3.1.2-bullseye
RUN apt-get update ; \
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails", "~> 7.2"
gem "pg"
end
require "active_record"
require "logger"
@the-spectator
the-spectator / requirements.txt
Last active February 15, 2025 10:48 — 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