Skip to content

Instantly share code, notes, and snippets.

@miligraf
miligraf / README.md
Last active May 28, 2020 13:43
CodePipeline + CodeBuild + Lambda
@miligraf
miligraf / presigned_url.rb
Last active October 24, 2023 21:33
Rails - Upload an Object Using a Pre-Signed URL (AWS SDK for Ruby)
Aws.config.update({
region: 'us-east-1',
credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
})
S3_BUCKET = Aws::S3::Resource.new.bucket(ENV['S3_BUCKET'])
@post = S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read')
post = Aws::S3::Resource.new.bucket("fake").presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read')
class User < ActiveRecord::Base
class_attribute :columns
def self.columns
@columns ||= [];
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(
name.to_s,
default,
class User < ActiveRecord::Base
def self.columns
@columns ||= [];
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(
name.to_s,
default,
class RenameReadColumToState < ActiveRecord::Migration
def change
add_column :messages, :state, :integer, default: 0
execute "UPDATE messages SET state = CAST(read AS INTEGER);"
remove_column :messages, :read
end
end
@miligraf
miligraf / index_name_convention
Last active January 22, 2016 16:41
Ruby on Rails database table index naming convention
Rails, or Active Record in this case, only identifies indexes with the following name pattern:
index_<table_name>_on_<column_name>
If name is different than that, it will completely ignore the index and won't use it.
@miligraf
miligraf / mongoid_like_or
Created February 26, 2012 01:28
Mongoid version of SQL "SELECT * FROM Objects WHERE field1 LIKE '%search%' OR field2 LIKE '%search%'
search = params[:search][:text]
results = Object.any_of({ field1: /#{search}/ } , { field2: /#{search}/ })