Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔
Wondering if Github is going to become a fully fledged social network

Iain Barnett yb66

🤔
Wondering if Github is going to become a fully fledged social network
View GitHub Profile
View yb66.plugin.zsh
# Because I don't like being tracked by Facebook around the web
# This function, which I load via my ~/.zshrc,
# - takes the url on the clipboard (when run)
# - decodes the querystring to find the original link
# - removes the FB id from the resulting query string
# - pops it back onto the clipboard
fb-uri(){
str=${1:-`pbpaste`}
ruby -W0 -ruri -r'rack/utils' -e "print URI(Rack::Utils.parse_query(URI('$str').query)['u']).then{|uri| %Q(#{uri.scheme}://#{uri.host}#{uri.path}#{ (hs = Rack::Utils.parse_query(uri.query).reject{|k,_| k == 'fbclid'}).empty? ? '' : %Q(?#{Rack::Utils.build_query hs}) }) }" | pbcopy
}
@yb66
yb66 / cacert-refresh.plist
Created May 24, 2020
Refresh/check cacert once every week to keep curl updated
View cacert-refresh.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Run the cacert refresh once a week -->
<!-- ~/Library/LaunchAgents/cacert-refresh.plist -->
<plist version="1.0">
<dict>
<key>Label</key>
<string>cacert-refresh</string>
<key>EnableGlobbing</key>
@yb66
yb66 / bench_str_building.rb
Last active Mar 20, 2019 — forked from alno/bench_str_building.rb
Benchmark: interpolation vs concatenation in Ruby
View bench_str_building.rb
require 'benchmark'
count = 1_000_000
Benchmark.bmbm do |bm|
bm.report("to_s + ") { count.times { 11.to_s + '/' + 12.to_s } }
bm.report("+ ") { count.times { "11" + '/' + "12" } }
bm.report('#{} to_s ') { count.times { "#{11}/#{12}" } }
bm.report('#{} ') { count.times { %Q!#{"11"}/#{"12"}! } }
bm.report("to_s << ") { count.times { 11.to_s << "/" << 12.to_s } }
bm.report("<< ") { count.times { "11" << "/" << "12" } }
@yb66
yb66 / yb66.pem
Created Jan 15, 2019
yb66's Ruby gem signing certificate
View yb66.pem
-----BEGIN CERTIFICATE-----
MIIEbjCCAtagAwIBAgIBATANBgkqhkiG9w0BAQsFADAwMS4wLAYDVQQDDCVoZWxw
ZnVsLWlhaW4vREM9dGhlcHJpbnRlZGJpcmQvREM9Y29tMB4XDTE5MDExNTA3MjAw
OVoXDTIwMDExNTA3MjAwOVowMDEuMCwGA1UEAwwlaGVscGZ1bC1pYWluL0RDPXRo
ZXByaW50ZWRiaXJkL0RDPWNvbTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoC
ggGBALhp1KlrdriWAuhXhM3I0oZblbOUAgk8UZSyI6vLQ4oK8uHWmdBkrzUublq4
7cU1T0IIFeKOzjN2aXS660q2Ev7Bpwt1oBjMVqLMZYJM4gixwzXW9labQhnjefEy
CTWRa/i4gL8NbwOg/UeX5rHiCy/xaqyxj//24E7m5e72JrpK11ZZ5/4TUvxDfOJr
w+16BAxH3ELBRjXoOXnlb7SzA2ohNnwuoom5gi9Ju6z0ooSa9cegqauHBbme8wgO
5bPwGi+MbiLKoMDcnakuUoKqWL6qA+/QofNnrmtgBmMe08dd9/ermztT/dBdNQiE
View Keybase.md

Keybase proof

I hereby claim:

  • I am yb66 on github.
  • I am iainb (https://keybase.io/iainb) on keybase.
  • I have a public key ASBMPFBvFnJ5Uzq_5zUgktL0pK8uomtYcnFoVATS5iC6xgo

To claim this, I am signing this object:

@yb66
yb66 / luhn.rb
Last active Apr 23, 2018
Luhn algorithm with the broken Syncthing implementation
View luhn.rb
# Implemented because Syncthing (kind of) uses it
# @example
# @luhn = Luhn.new Base32.table
# @luhn.check_character "P56IOI7MZJNU2"
# # => "S"
class Luhn
def initialize alphabet
@alphabet = alphabet
@table_alpha = Hash[ @alphabet.split(//).zip(0 .. @alphabet.length - 1) ]
@table_code = Hash[ (0 .. @alphabet.length - 1).zip(@alphabet.split(//))]
View check_gems.rb
#!/usr/bin/env ruby
require 'optparse'
require 'pathname'
require 'psych'
options = {}
optparse = OptionParser.new do |opts|
@yb66
yb66 / app.rb
Created Apr 15, 2013
Shared *and* individual configuration in Sinatra.
View app.rb
require 'sinatra'
configure :development do
set :one, 1
end
configure :production do
set :one, 11
end
View app.rb
require 'sinatra'
require 'haml'
class Something
def self.all( h= {} )
[]
end
def self.get( id=1 )
obj = Object.new
class << obj