Skip to content

Instantly share code, notes, and snippets.

View bglusman's full-sized avatar

Brian Glusman bglusman

View GitHub Profile
defmodule Repo.Migrations.AddCountEstimateFunction do
use Ecto.Migration
def up do
create_function()
end
def down do
drop_function()
end
@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}"
@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 / cap deploy terminal session
Created April 23, 2012 00:25
git remote changed for cap deploy git branch issue
✈ > cap deploy
triggering load callbacks
* executing `qa'
triggering start callbacks for `deploy'
* executing `multistage:ensure'
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote rails@qa.xyz.org:/git/xyz.git qa"
@bglusman
bglusman / hashinit.rb
Created January 11, 2012 14:23
HashInit
module HashInit
#example usage:
# instead of this -
#
# class Message
# attr_reader :content, :sender, :subject
# attr_accessor :event
# def initialize(message)
@bglusman
bglusman / lbjk.py
Created March 10, 2011 03:15
labjack project
#simple loop to toggle LED on and off forever
import time
import math
import ConfigParser
import logging
LEVELS = {'debug' : logging.DEBUG,
'info' : logging.INFO,
'warning' : logging.WARNING,
## config/boot.rb
# Place this snippet right above the "Rails.boot!" command at the bottom of the file.
class Rails::Boot
def run
load_initializer
extend_environment
Rails::Initializer.run(:set_load_path)
end
def extend_environment
@bglusman
bglusman / README.rdoc
Created December 15, 2010 03:34 — forked from woodie/README.rdoc

Rails 3.0.pre on App Engine

You can Rails 3 on App Engine, but it won’t be especially useful until bundler 10. You should try these instead:

Install the Development Environment

The gems for the development environment include a pre-release appengine-tools gem that provides a pre-release version of jruby-rack.

Rails 2.3.5 on App Engine (DataMapper)

Do not use rvm (or install and run from JRuby). The google-appengine gem must install into your system MRI. The appengine-sdk gem includes a complete Java app server. We bootstrap Java from MRI, then your app runs inside a servlet container (with access to all the APIs) using the version of JRuby installed into each app.

We assumed Rails 2 would never work without rubygems, and we committed to gem bunlder for JRuby on App Engine, so we were waiting for Rails 3. Fortunately, Takeru Sasaki was able to patch the Rails 2.3.x calls to rubygems, and now we have it working. Rails 2.3.x currently spins up several seconds faster than Rails 3, and just a few seconds behind Sinatra.

See the TInyDS version also: gist.github.com/gists/269075

Install the Development Environment