Skip to content

Instantly share code, notes, and snippets.

View HCLarsen's full-sized avatar

Chris Larsen HCLarsen

View GitHub Profile
class Array(T)
# Returns true if the two arrays share no common elements.
def disjointed?(other : Array(U)) forall U
(self & other).size == 0
end
end
arr1 = [1 ,2 ,3, 4]
arr2 = [3, 4, 5, 6]
arr3 = [5, 6, 7, 8]
require 'jose'
message = "Jodie Whittaker is the greatest Doctor ever!"
# A128GCM Symmetric Key Encryption/Decryption
puts "-----Symmetric Key Encryption/Decryption-----"
secret = 'some128bitsecret'
jwk = JOSE::JWK.from_oct(secret)
encrypted_a128gcmkw = JOSE::JWE.block_encrypt(jwk, message, { "alg" => "A128GCMKW", "enc" => "A128GCM" }).compact
puts "encrypted JWE: #{encrypted_a128gcmkw}"
require 'jose'
# HS256 Symmetric Signature
secret = 'some128bitsecret'
jwk = JOSE::JWK.from_oct(secret)
header = { "alg" => "HS256" }
payload = { "iss" => "Chris Larsen",
"sub" => "JWTs",
"aud" => "Silicon Halton Software P2P",
"iat" => 1540121863 }
@HCLarsen
HCLarsen / crystal_generics.cr
Last active June 9, 2018 17:45
Basic demonstration of what can be done with Crystal Generic classes
class Gen(T)
getter value : T
def initialize(@value : T)
end
def self.build(value : K) : Gen(K) forall K
Gen(K).new(value)
end
@HCLarsen
HCLarsen / cgrep.cr
Last active January 9, 2018 21:34
A simple grep tool written in Crystal to display use of a RegExp and use of Command Line.
abort "Need a regex pattern" unless ARGV.size > 0
regex = ARGV.shift
STDIN.each_line do |i|
puts i if i =~ %r(#{regex})
end
usage = <<-STRING
Usage: cl-tutorial [option]
Command:
time, --time, -t show the current time
help, --help, -h show this help
version, --version, -v show version
STRING
if ARGV.size == 0
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install software-properties-common
sudo apt-add-repository -y ppa:rael-gc/rvm
sudo add-apt-repository ppa:webupd8team/atom
sudo apt-get update
sudo apt-get install rvm