Skip to content

Instantly share code, notes, and snippets.

View kanmaniselvan's full-sized avatar

Kanmani kanmaniselvan

  • Senior Software Engineer @pcln
  • Berlin, Germany
View GitHub Profile
@kanmaniselvan
kanmaniselvan / group_by_common_chars.rb
Last active September 8, 2017 16:54
Group array of strings by first common characters
def group_by_common_chars(strings_array)
max_length = strings_array.max_by(&:length).length
char_grouped_hash = (0..max_length).each_with_object({}) do |index, hash|
hash.merge!(strings_array.group_by { |string| string[0..index] }.select{|k, v| k.length == index + 1})
end
index = 0
result_hash = {}
char_grouped_hash.each do |key, values_array|
index += 1
@kanmaniselvan
kanmaniselvan / sample_sendgrid_json.rb
Last active September 30, 2016 09:31
SendGrid Mail event Sample JSON structure
{
"_json": [
{
"email": "[email protected]",
"timestamp": 1475218536,
"smtp-id": "<14c5d75ce93.dfd.64b469@ismtpd-555>",
"event": "processed",
"category": "cat facts",
"sg_event_id": "djCl3GRt94fqCWtHYHUIJQ==",
"sg_message_id": "14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0"
@kanmaniselvan
kanmaniselvan / split_date_range.rb
Last active May 5, 2017 14:00
Split date range by 'N' smaller ranges
def recursively_split_dates(start_date, end_date, dates_array, num_days_to_add)
if start_date >= end_date
last_date = dates_array.pop
dates_array << { start_date: last_date[:start_date], end_date: end_date }
else
start_date += num_days_to_add
dates_array << { start_date: dates_array.last[:end_date] + 1.day,
@kanmaniselvan
kanmaniselvan / update_random_array.sql
Created September 3, 2020 14:46
Updates random array in batches of 1000 records
do $$
declare
row_count integer := 449166;
batch_size integer := 1000;
offset_value integer := 0;
begin
while row_count > 0 loop
update
my_table
@kanmaniselvan
kanmaniselvan / afklm_response_sample.xml
Created February 15, 2022 10:44
BA & AFKLM sample responses
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<trackingMessageHeader xmlns="http://www.af-klm.com/soa/xsd/MessageHeader-V1_0">
<consumerRef>
<userID/>
<partyID>unidentified</partyID>
<consumerID>unidentified</consumerID>
<consumerLocation>unidentified</consumerLocation>
<consumerType>unidentified</consumerType>