Skip to content

Instantly share code, notes, and snippets.

Avatar

Caius Durling caius

View GitHub Profile
View partial_http_get.rb
require "net/http"
A_CHUNK_TOO_FAR = Class.new(StandardError)
# @param url [URI] uri to fetch title of
def url_title(url)
title = nil
Net::HTTP.start(url.host, url.port, use_ssl: (url.scheme == "https"), open_timeout: 5, read_timeout: 5) do |http|
request = Net::HTTP::Get.new(url)
@caius
caius / spss_macos.md
Last active Nov 13, 2020
IBM SPSS Version 26 on macOS Big Sur
View spss_macos.md
  1. install homebrew - https://brew.sh
brew install openjdk
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
(check `brew info openjdk` if that's still the correct command)
  1. Check java runs
View thing_spec.rb
require "net/http"
require "json"
require "rspec/autorun"
module Thing
def self.thing(response)
case response
when Net::HTTPSuccess
:ok
when Net::HTTPNotFound
View callback_promise.js
// Callback hell approach
function main() {
console.log("hello from main")
var name = "caius"
sendHello(decorateName(name)) // <- smelly
}
function decorateName(name) {
View number_search.rb
# five digit number
# two of the digits are the same
# four of the digits are odd
# number is higher than 40010
# number is higher than 45000
# digit sum is 16
# five digit, upper/lower bounds
candidates = (40011..44999).select { |i|
# two digits are the same
View shovelling to nowhere.rb
@data = {}
def default_src(*args)
if args.first
@data[:default_src] = args.map(&:to_s)
else
@data.delete(:default_src)
end
end
View safelist_2020_06_30.txt
*@*.aaa
*@*.aarp
*@*.abarth
*@*.abb
*@*.abbott
*@*.abbvie
*@*.abc
*@*.able
*@*.abogado
*@*.abudhabi
@caius
caius / file.rb
Created Jun 17, 2020
Run this in your terminal. No really, it's safe.
View file.rb
p = Enumerator.new { |y| o = (31..36).to_a-[34]; loop { y << o.first; o.shuffle! } }
c = ->(l) { "\e[1;5;#{p.next}m#{l}\e[0m" }
r = ->(s) { s.gsub(/\S/) { |l| c[l] } }
puts nil, "\t\e[34m<#{19479728.to_s(36)}>\e[0m#{r["#{[16712,8265].pack("s*")}#{ENV["USER"].upcase}"]}\e[34m</#{19479728.to_s(36)}>\e[0m", nil
View standard_assign_begin_bug.rb
# What I expect it to be corrected to:
#
# something = begin
# raise "thing"
# rescue => e
# p e
# end
# What it's actually corrected to (standard gem v0.4.7)
something = begin
View given_when_then.rb
module GivenWhenThen
module ClassMethods
def def_Given(name, *args, &block)
_gwt_define(:Given, name, *args, &block)
end
def def_When(name, *args, &block)
_gwt_define(:When, name, *args, &block)
end