Skip to content

Instantly share code, notes, and snippets.

@mikem
mikem / yubikey-verify.pl
Created February 22, 2020 13:40
A small Perl script to verify a Yubikey OTP
#!/usr/bin/env perl
# A small script to verify a Yubikey OTP with Yubico.
# Inspired by https://www.crc.id.au/openvpn-otp-with-a-yubikey/
# Usage: curl $(./yubikey-verify.pl)
use MIME::Base64 qw( encode_base64 decode_base64 );
use Digest::HMAC_SHA1 qw( hmac_sha1 );
use URI::Escape qw( uri_escape );
@mikem
mikem / yubikey-verify.rb
Created February 22, 2020 09:39
A small Ruby script to verify a Yubikey OTP
#!/usr/bin/env ruby
# A small script to verify a Yubikey OTP with Yubico.
# Usage: curl $(./yubikey-verify.rb)
require 'openssl'
require 'base64'
require 'cgi'
require 'securerandom'
@mikem
mikem / decrypt_jwe.rb
Last active August 8, 2017 14:36
A short program to decrypt a JWE Compact Serialization encrypted with a symmetric key
#!/usr/bin/env ruby
require 'optparse'
require 'jwe'
require 'jwt'
require 'pp'
options = {}
OptionParser.new do |opts|
opts.banner = <<-TXT
@mikem
mikem / time.scala
Created September 6, 2016 01:50
Timing code in Scala
// see http://stackoverflow.com/a/9160068/2576
def time[R](block: => R): R = {
val t0 = System.nanoTime()
val result = block // call-by-name
val t1 = System.nanoTime()
println("Elapsed time: " + (t1 - t0) + "ns")
result
}
@mikem
mikem / ruby_timezone.rb
Created August 10, 2014 23:31
Create a Time in a specific timezone in Ruby
require 'time'
def format_time time_str
old_tz = ENV['TZ']
return if time_str.nil?
ENV['TZ'] = 'America/New_York'
Time.parse time_str
ensure

Keybase proof

I hereby claim:

  • I am mikem on github.
  • I am mmazur (https://keybase.io/mmazur) on keybase.
  • I have a public key whose fingerprint is 6E05 E2BA 3559 12BB 05FE 878E F182 C523 6779 2760

To claim this, I am signing this object:

#!/usr/bin/env ruby
def parse_app app_text
app = {}
current_property = nil
lines = app_text.split("\n")
lines.each do |line|
next if line.start_with? '=== '
@mikem
mikem / pre_commit_hook-jammit
Created March 9, 2011 12:18
git pre-commit hook for Jammit
#!/usr/bin/env ruby
require 'jammit'
print "Jammit check... "
status_before = %x[git status --porcelain --untracked-files=no]
Jammit.package!
status_after = %x[git status --porcelain --untracked-files=no]
jammit_files = (status_after.split("\n") - status_before.split("\n")).map { |f| f.split[1] }
unless jammit_files.empty?