Skip to content

Instantly share code, notes, and snippets.

def lambda_function(event:, context:)
puts "Lambda function was called"
end
@muneebaahmad
muneebaahmad / ruby_yield_example.rb
Created April 30, 2020 23:21
An example to understand the yield keyword in ruby.
def greeting
puts '2'
yield
end
puts '1'
greeting { puts '3'}
=> 1
=> 2
resource "aws_elasticsearch_domain" "demo" {
domain_name = "demo"
elasticsearch_version = "6.2"
ebs_options {
ebs_enabled = true
volume_type = "gp2"
volume_size = 10
}
@muneebaahmad
muneebaahmad / convert_to_env.rb
Created February 20, 2019 21:28
Converts Heroku configs to a format accepted by .env files
# Converts Heroku configs to a format accepted by .env files
class ConvertToEnv
File.open('sample_env.txt').each do |line|
line = line.sub(':', '=').delete(" \t\r\n")
print "#{line}\n"
end
end
ConvertToEnv.new
@muneebaahmad
muneebaahmad / check_difference.rb
Created January 31, 2019 21:00
Checks the difference between two files
# To run, cd to this folder and put the following command in the command line
# ruby check_difference.rb
require 'set'
# Returns the user ids for emails that already exist
class Difference
FILE_ONE = 'all_emails.txt'.freeze
FILE_TWO = 'matched_emails.txt'.freeze
@muneebaahmad
muneebaahmad / parse_csv_check_sql.rb
Last active January 25, 2019 01:21
Parses a csv to look for email addresses. Then checks the sql table to see which emails exist and then returns those users ids.
require 'mysql2'
require 'csv'
# Returns the user ids for emails that already exist
class Users
CSV_FILENAME = 'emails.csv'.freeze
EMAIL_COLUMN_NUMBER = 0
def user_ids
ids = []
# INSERT RECORDS INTO A DB
# Use case: To insert millions of records into a local db to test scripts.
# Testing scripts that affect millions of records on a remote db is very time consuming.
require('mysql2')
class Table
# @params cur_index [The id to start the insertion at]
# @params num_records [Number of records to insert starting at the id above]
def insert_records(cur_index, num_records)
end_index = cur_index + num_records
@muneebaahmad
muneebaahmad / launch.json
Last active March 9, 2018 06:23
VS Code Launch Configuration
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/node_modules/.bin/lambda-local",
"args": [
"-l",