Skip to content

Instantly share code, notes, and snippets.

View bglusman's full-sized avatar

Brian Glusman bglusman

View GitHub Profile
@bglusman
bglusman / aws_signed_request_v4.rb
Created February 26, 2016 20:50 — forked from blelump/aws_signed_request_v4.rb
Sample Ruby code to create AWS signed request version 4 (with request headers)
#Signing AWS Requests By Using Signature Version 4
#http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
require 'uri'
require 'openssl'
require 'net/http'
require 'cgi'
method = 'GET'
service = 'iam'
@bglusman
bglusman / elixir_decrypt.exs
Last active March 26, 2017 16:58
simple working ruby-encryption to elixir-decryption (DO NOT USE a zero IV for real)
defmodule Decrypt do
@iv String.duplicate("0", 16)
def unpad(data) do
to_remove = :binary.last(data)
:binary.part(data, 0, byte_size(data) - to_remove)
end
def decrypt(data, key) do
@bglusman
bglusman / date_string_or_error.ex
Last active January 5, 2017 16:24
date_string_or_error attempt, not working
def modified_date_or_datetime(string, modifier) do
date_match = Date.from_iso8601(string)
iso_match = Timex.parse(string, "{ISO:Extended}")
isoz_match = Timex.parse(string, "{ISO:Extended:Z}")
case {:ok, x } do
^date_match -> "#{string}#{modifier}"
^iso_match -> string
^isoz_match -> string
_ -> raise "Invalid ISO8601 date/datetime format provided: #{string}"
defmodule Repo.Migrations.AddCountEstimateFunction do
use Ecto.Migration
def up do
create_function()
end
def down do
drop_function()
end