Skip to content

Instantly share code, notes, and snippets.

@rob-murray
rob-murray / add_intellij_launcer
Last active April 10, 2024 15:42
Add Intellij launcher shortcut and icon for ubuntu
// create file:
sudo vim /usr/share/applications/intellij.desktop
// add the following
[Desktop Entry]
Version=13.0
Type=Application
Terminal=false
Icon[en_US]=/home/rob/.intellij-13/bin/idea.png
Name[en_US]=IntelliJ
@rob-murray
rob-murray / siege_examples.sh
Last active April 1, 2024 03:48
Siege examples
# Basic example
siege -t60s -c20 -d10 'http://robertomurray.co.uk/'
# Basic auth;
auth=$(echo -n 'username:password' | openssl base64)
siege -t60s -c20 -d10 --header="Authorization:Basic $auth" 'https://staging.a-hostname.co.uk/'
@rob-murray
rob-murray / UK Company Number regex
Last active February 4, 2024 02:12
A regex to check UK Company numbers - ie the reference assigned to companies in the UK via Companies House
/^((AC|ZC|FC|GE|LP|OC|SE|SA|SZ|SF|GS|SL|SO|SC|ES|NA|NZ|NF|GN|NL|NC|R0|NI|EN|\d{2}|SG|FE)\d{5}(\d|C|R))|((RS|SO)\d{3}(\d{3}|\d{2}[WSRCZF]|\d(FI|RS|SA|IP|US|EN|AS)|CUS))|((NI|SL)\d{5}[\dA])|(OC(([\dP]{5}[CWERTB])|([\dP]{4}(OC|CU))))$/
@rob-murray
rob-murray / find_dups.rb
Created October 27, 2015 09:59
Rails find duplicate records
columns_that_make_record_distinct = [:some_id, :another_name]
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id)
duplicate_records = Model.where.not(id: distinct_ids)
@rob-murray
rob-murray / select-next-ip.sql
Created January 8, 2013 17:31
Select the next available IP address using Postgres inet and cidr types
SELECT sub.ip FROM
(SELECT set_masklen(((generate_series(1,
(2 ^ (32 - masklen('10.10.100.0/24'::cidr)))::integer - 2) +
'10.10.100.0/24'::cidr)::inet), 32) as ip) AS sub
WHERE sub.ip NOT IN
(SELECT ip_address from ip_table)
AND sub.ip > set_masklen('10.10.100.0/24', 32)+10
AND sub.ip < set_masklen(broadcast('10.10.100.0/24')::inet, 32)-5;
require 'net/http'
require 'benchmark'
def make_request(sleep_mins, read_timeout = 1)
puts "sleep_mins=#{sleep_mins} mins read_timeout=#{read_timeout} mins"
uri = URI.parse 'http://localhost:4040'
request = Net::HTTP::Get.new("/sleep?m=#{sleep_mins}")
Net::HTTP.start(uri.host, uri.port, read_timeout: (read_timeout * 60)) do |http|
@rob-murray
rob-murray / asdf_install_ruby_ssl.sh
Created April 14, 2020 20:14
ASDF - Install Ruby with SSL
RUBY_CONFIGURE_OPTS="--with-openssl-dir=/usr/local/opt/openssl" asdf install ruby 2.6.5
begin
require 'awesome_print'
AwesomePrint.irb!
rescue LoadError
Gem.install('awesome_print')
retry
end
ap '👋🌎'
namespace :export do
desc <<-DESC.strip_heredoc
Export tables listed as YAML
Usage: `rails export:tables TABLES=users,posts,comments`
DESC
task tables: :environment do
models = ENV["TABLES"].split(",").map do |name|
name.to_s.classify.constantize
rescue NameError
nil

Error

rbenv install 2.7.1
Downloading ruby-2.7.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.1.tar.bz2
Installing ruby-2.7.1...
ruby-build: using readline from homebrew

BUILD FAILED (macOS 12.4 using ruby-build 20220713)