Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'aws-sdk'
# initialize S3 client
s3_client = Aws::S3::Client.new(region: 'us-east-1')
# initialize KMS client
kms_client = Aws::KMS::Client.new(region: 'us-east-1')
@boy-jer
boy-jer / contact.rb
Created March 21, 2021 23:03 — forked from endymion/contact.rb
Example of integrating a Ruby on Rails app with Zapier using the REST hooks pattern. With support for triggering the REST hooks from Resque background jobs.
class Contact < ActiveRecord::Base
...
def after_create
if Hook.hooks_exist?('new_contact', self)
Resque.enqueue(Hook, self.class.name, self.id)
# To trigger directly without Resque: Hook.trigger('new_contact', self)
end
end
@boy-jer
boy-jer / Rails Console Actionmailer test.rb
Created November 20, 2016 00:57 — forked from benoror/Rails Console Actionmailer test.rb
Rails Console Actionmailer test
# Copy and paste this to the rails console to test your email settings
class MyMailer < ActionMailer::Base
def test_email
set_tracking_headers 'test_campaign'
@recipients = "benoror@gmail.com"
@from = "Equipo Nimbo X <hola@" + Rails.application.secrets.sparkpost_domain + ">"
@subject = "sparkpost email test with open & click tracking"
@body = "This is a test email. With a <a href=\"http://blog.nimbo-x.com/nimbo-x-gold/\">test link</a>."
@boy-jer
boy-jer / credit_card_spec.md
Last active August 12, 2016 10:53
How I learned to love testing by Gregg Polack. https://www.youtube.com/watch?v=guSUuMMDl2E
@boy-jer
boy-jer / tic
Last active April 21, 2016 04:13
http://codereview.stackexchange.com/questions/88429/tic-tac-toe-implementation-in-ruby
**https://codequizzes.wordpress.com/2013/10/25/creating-a-tic-tac-toe-game-with-ruby/
ruby ~/dev-gt/test/ttt/lib/ttt.rb
For example, a Tic Tac Toe program requires data structures for storing
the board and conditional logic for knowing whose turn it is or if someone has won.
http://stackoverflow.com/questions/3233278/how-do-i-test-if-all-items-in-an-array-are-identical?rq=1
You can use Enumerable#all? which returns true if the given block returns true for all the elements in the collection.
require 'minitest/autorun'
require_relative 'checkout'
class TestCheckoutTest < Minitest::Test
def setup
@checkout = Checkout.new('strawberry')
end
@boy-jer
boy-jer / tac.rb
Last active April 20, 2016 21:47
class Board
attr_reader :grid
def initialize(input_array_hash = {})
@grid = input_array_hash.fetch(:grid, board_default_grid)
end
def fetch_cell(x, y)
@boy-jer
boy-jer / multi-parameter_attributes_spec.rb
Created December 4, 2013 10:59 — forked from k-rudy/multi-parameter_attributes_spec.rb
Multiparameter Attributes support in Mongoid 4 (Rails 4.0.1) Code is taken from https://github.com/mongoid/mongoid/issues/2954 with minor amendments to work with Rails 4.0.1
# This class is needed since Mongoid doesn't support Multi-parameter
# attributes in version 4.0 before it's moved to active model in rails 4
#
# https://github.com/mongoid/mongoid/issues/2954
#
require "spec_helper"
require 'mongoid/multi_parameter_attributes'
describe Mongoid::MultiParameterAttributes do
module Mongoid
module ActiveRecord
module EagerLoadable
module Criteria
extend ActiveSupport::Concern
def includes_active_record(*relations)
relations.each do |relation|
metadata = RelationMetadata.new(relation)
@boy-jer
boy-jer / S3Upload.js
Created July 18, 2013 09:37 — forked from raytiley/S3Upload.js
This class uploads to an S3 bucket. And was adapted from this blog post: http://www.ioncannon.net/programming/1539/direct-browser-uploading-amazon-s3-cors-fileapi-xhr2-and-signed-puts/ You need to have an endpoint on your server that will sign your S3 request for you ('covered in the plog post'). To use: App.S3Upload.create({ file: file-from-fil…
App.S3Upload = Ember.Object.extend({
progress: 0,
state: "pending",
bucket: 'your-bucket'
complete: false,
s3url: null,
xhr: null,
file: null,
fileName: function() {
var file = this.get('file');