Skip to content

Instantly share code, notes, and snippets.

@oeN
oeN / weighted.rb
Last active April 29, 2020 19:34
Shuffle a Weighted array in Ruby
def weighted
a = []
(1..60).each do |i|
a << { value: "HIGH_#{i}", weight: 5 }
end
(1..30).each do |i|
a << { value: "MID_#{i}", weight: 3 }
end
(1..15).each do |i|
a << { value: "LOW_#{i}", weight: 2 }
@mrrooijen
mrrooijen / database.sslmode.require.yml
Last active February 6, 2024 21:33
SSL configurations for Rails + Postgres in either require or verify-full mode to ensure secure connections. Useful for Amazon RDS, Compose.io, etc.
production:
adapter: postgresql
encoding: unicode
sslmode: require
url: postgres://user:password@host:port/db
@davidderus
davidderus / application_policy.rb
Last active October 26, 2016 11:47
Non-Standard ApplicationPolicy for Pundit
# Handling Application rights thanks to roles
#
# A direct adaptation of http://through-voidness.blogspot.fr/2013/10/advanced-rails-4-authorization-with.html
# but much more performance-wise
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
raise Pundit::NotAuthorizedError, 'Must be signed in.' unless user
@user = user
@acundari
acundari / traefik-auth.conf
Last active December 6, 2022 09:41
Traefik fail2ban
# /etc/fail2ban/filter.d/traefik-auth.conf
[Definition]
failregex = ^<HOST> \- \S+ \[\] \"(GET|POST|HEAD) .+\" 401 .+$
@guich-wo
guich-wo / highlight-ruby.applescript
Created February 14, 2018 13:06
Applescript to highlight ruby code in Pages
# Applescript to highlight ruby code in Pages
# Requirements : Pygments (http://pygments.org/languages/) : pip install Pygments
# Tutorial: https://shomeya.com/articles/screencast-how-to-add-syntax-highlighting-to-pages-and-keynote
try
set old to the clipboard as record
end try
tell application "System Events" to keystroke "c" using command down
do shell script "export LC_CTYPE=UTF-8; pbpaste | /usr/local/bin/pygmentize -l ruby -f rtf -O style=default | pbcopy -Prefer rtf"
tell application "System Events" to keystroke "v" using command down
delay 0.05
@mtancoigne
mtancoigne / git-bs
Last active February 28, 2023 10:16
Display statuses of local git branches
#!/usr/bin/env ruby
# frozen_string_literal: true
# Display branch statuses
#
# @author Manuel Tancoigne <[email protected]>
# @license MIT
# @version 0.2.3
#
# Requirements
@mtancoigne
mtancoigne / airsec.rb
Created February 27, 2023 09:52
Find outdated gems in sub-directories
#!/usr/bin/env ruby
# frozen_string_literal: true
# Find projects with outdated dependencies
#
# Usage:
# airsec <gem>
# airsec <gem> [[min version] max version]
#