Skip to content

Instantly share code, notes, and snippets.

View phillipoertel's full-sized avatar

Phillip Oertel phillipoertel

View GitHub Profile
@phillipoertel
phillipoertel / replacements.rb
Last active October 9, 2024 16:43
Fixing city names
#
# 1. define replacements
#
replacements = {
'germany' => {
# this has the following structure:
# 'correct city name' => ['variant to fix 1', 'variant to fix 2', ...]
# the variants DO NOT repeat the correct city name, neither downcased nor capitalized.
'Berlin' => ['Берлин', 'Berlin, Stadt', 'Berlin / Biesdorf', 'Berlin-Prenzlauer Berg', 'Berlin-Wedding'],
# add a db schema migration to add geocoded_at to listings
add_column :listings, :geocoded_at, :timestamp, default: nil
# add a geocoded? method to the model
class Listing < ApplicationRecord
def geocoded?
read_attribute(:geocoded) || geocoded_at.present?
end
end
@phillipoertel
phillipoertel / run.rb
Last active June 14, 2024 15:09
redis counts
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'redis'
gem "hiredis-client"
# gem 'rspec'
end
require "hiredis-client" # speed optimized redis client
require 'open-uri'
`mkdir files`
URL = 'https://www.cia.gov/library/abbottabad-compound/index_video.html'
html = URI.open(URL).read
files = html.scan(/"\.(.*Jerry.*\.rm(vb)?)">/i)
urls = files.map { |a| URL.gsub('/index_video.html', a.first) }
module Cs
module Hanami
class PathResolver
def self.call(env)
new.call(env)
end
def call(env)
path = env['REQUEST_URI'].split('?').first # path without query string
return 'root' if path == '/'
@phillipoertel
phillipoertel / omegametrix.pl
Last active November 29, 2019 11:09
Perl script to submit Omegametrix' test results to Cerascreen
sub sendFTPs($) {
my $lftpfile = shift;
# apt install liblwp-protocol-https-perl libfile-slurp-perl
use HTTP::Request qw();
use HTTP::Headers qw();
use LWP::UserAgent ();
use File::Slurp qw(read_file);
# Cerascreen hostnames:
created_organizations = {}
MedlineOrganization.find_each do |organization|
# ...
key = new_organization[:organization][:external_id]
if created_organizations[key]
print "x"
else
created_organizations[key] = zendesk_account.organizations.create(new_organization[:organization])
print "."
module Cm
module Shared
# Calculates a percentage of the amount passed in and returns it rounded to 2 decimals (i.e. cents),
# as a BigDecimal object.
#
# Some takeaways from "Invoices: How to properly round and calculate totals" (https://goo.gl/cHvuPa)
# - it is very easy to create invoices where numbers don't add up and a few cents are missing.
# - don't pass around unrounded values. Once you round, use the rounded value for all further totals.
# - the rounding of money amounts is *not* a matter of presentation, and should never happen in a view.
# - don't ever use the float data type in Ruby or MySQL for money
# Right now these checks add more noise than value; may change as the team grows.
CommitMsg:
ALL:
enabled: false
# Right now these checks add more noise than value; may change as the team grows.
PreCommit:
ALL:
enabled: false
PrePush:
RakeTarget: