Skip to content

Instantly share code, notes, and snippets.

View adz's full-sized avatar

Adam Davies adz

  • Veridapt
  • Adelaide, Australia
  • 13:26 (UTC +09:30)
  • X @adzdavies28
View GitHub Profile
@adz
adz / encoding_repairer.rb
Created September 5, 2024 05:12 — forked from xijo/encoding_repairer.rb
Repair utf-8 strings that contain iso-8599 encoded utf-8 characters
class EncodingRepairer
REPLACEMENTS = {
"€" => "€", "‚" => "‚", "„" => "„", "…" => "…", "ˆ" => "ˆ",
"‹" => "‹", "‘" => "‘", "’" => "’", "“" => "“", "â€" => "”",
"•" => "•", "–" => "–", "—" => "—", "Ëœ" => "˜", "â„¢" => "™",
"›" => "›", "Å“" => "œ", "Å’" => "Œ", "ž" => "ž", "Ÿ" => "Ÿ",
"Å¡" => "š", "Ž" => "Ž", "¡" => "¡", "¢" => "¢", "£" => "£",
"¤" => "¤", "Â¥" => "¥", "¦" => "¦", "§" => "§", "¨" => "¨",
"©" => "©", "ª" => "ª", "«" => "«", "¬" => "¬", "®" => "®",
@adz
adz / capybara cheat sheet
Created March 2, 2023 00:06 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@adz
adz / 0_reuse_code.js
Created September 19, 2016 02:05
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@adz
adz / anima_vs_virtus_vs_contracts_vs_noop.rb
Last active September 24, 2015 14:04 — forked from solnic/anima_vs_virtus.rb
Anima + Transproc vs Virtus
require 'anima'
require 'transproc'
require 'contracts'
require 'virtus'
require 'benchmark/ips'
USERS = 1000.times.map { |i| { id: "#{i+1}", name: "User #{i+1}", age: "#{(i+1)*2}" } }
@adz
adz / example.rb
Last active January 1, 2016 23:19 — forked from joakimk/example.rb
class Filter
include FormObject
# Proc because Date.yesterday changes every day :)
attribute :from, Date, default: Proc.new { Date.yesterday }
attribute :to, Date, default: Proc.new { 1.month.from_now - 1.day }
end
# in controller
@filter = Filter.new(params[:filter])
@adz
adz / library.rb
Created June 3, 2011 03:21 — forked from captainpete/library.rb
Tom's coding challenge. MiniTest suite
module Library
def self.leaf_paths_of(paths)
paths.select{|path|
!paths.any?{|other|
other.start_with?(path + '/')
}
end
end
#!/usr/bin/env ruby
command = '/usr/bin/passenger-memory-stats'
memory_limit = 200 # megabytes
def running?(pid)
begin
return Process.getpgid(pid) != -1
rescue Errno::ESRCH
return false