Skip to content

Instantly share code, notes, and snippets.

View gouravtiwari's full-sized avatar

Gourav Tiwari gouravtiwari

View GitHub Profile
@gouravtiwari
gouravtiwari / custom_origin_request.js
Last active May 10, 2019 16:40
Lambda@Edge custom origin
function updateOriginRequest(request) {
request.origin = {
custom: {
domainName: 'some-domain.example.com', // this is the origin where you want to route the request
port: 80, // or 443
protocol: 'http', // http or https
path: '/some-path', // path of the reqest
sslProtocols: ['TLSv1', 'TLSv1.1'], // and any other protocols supported by cloudfront
readTimeout: 10, //readTimeout in seconds,
keepaliveTimeout: 60, // in seconds
@gouravtiwari
gouravtiwari / string_to_cookies.js
Created March 7, 2019 22:58
Add multiple cookies from string
var str = "a=b; c=d;";
var addCookies(str) {
var multiple = res.split(";");
for(var i=0; i<multiple.length; i++) {
var key = multiple[i].split("=");
document.cookie=key[0] + "=" + key[1];
}
@gouravtiwari
gouravtiwari / introspection.gql
Created September 9, 2018 21:37
explore graphql schema with introspection
query {
__schema {
types {
name
fields {
name
}
}
}
}
@gouravtiwari
gouravtiwari / simple_queue.rb
Last active August 12, 2018 14:40
Simple Queue
class SimpleQueue
attr_accessor :queue
def initialize
@queue = []
end
def enqueue obj
queue << obj
end
@gouravtiwari
gouravtiwari / acm_cert_config_cfn.yml
Created August 3, 2018 13:49
ACM Cert configuration with Cloudformation template
Parameters:
AppLoadbalancerSslCertArn:
Description: SSL certificate for Application load balancer
Default: arn:aws:acm:<region>:<account-id>:certificate/<cert-id>
Type: String
AppCloudfrontSslCertArn:
Description: SSL certificate for Cloudfront Asset
Default: arn:aws:acm:<region>:<account-id>:certificate/<cert-id>
Type: String
AppName:
@gouravtiwari
gouravtiwari / cors_config_for_assets_for_https.xml
Created August 3, 2018 13:29
Cors Config for assets for https
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
 <AllowedOrigin>https://*</AllowedOrigin>
 <AllowedOrigin>http://*</AllowedOrigin>
</CORSRule>
</CORSConfiguration>
@gouravtiwari
gouravtiwari / task_definition.sh
Created May 1, 2018 05:05
Get task definition via Ruby thread in shell of Jenkins job
SERVICES=`aws ecs list-services --cluster ABCD`
CLUSTER="ABCD"
ruby <<EOM
require "open3"
ecs_service_name = 'abcd-ecs-service-stack-ABCDApplication-XXXXXXXXXXXXX'
puts ecs_service_name
# sleep 2
task_definition = Open3.popen3("aws ecs describe-services --cluster $CLUSTER --services #{ecs_service_name} --query services[*].taskDefinition --output text"){ |i, o| p o.read }
puts "task_definition: #{task_definition}"
@gouravtiwari
gouravtiwari / remove_invalid_rows_from_csv.rb
Created March 13, 2017 18:34
CSV file sanitizer, which will remove error-rows and create a new sanitized file
require 'csv'
valid_rows = 0
invalid_rows = 0
error_file = File.open("/path/to/invalid.csv", "w")
correct_file = File.open("path/to/valid.csv", "a+")
File.open("path/to/original.csv").each do |line|
begin
print "."
if CSV.parse_line(line)
All Indices:
| eventcount summarize=false index=* index=_* | dedup index | fields index
Groupe by source type:
| tstats values(sourcetype) where index=* group by index
@gouravtiwari
gouravtiwari / check_compression.rb
Created July 21, 2016 18:22
Check for compressed string before decompressing
# 2.2.2 :037 > gzip = 'Hi and hello'
# => "Hi and hello"
# 2.2.2 :038 > gzip.bytes[0..1]
# => [72, 105]
# 2.2.2 :039 > gzip.bytes[0..1] == [31,139]
# => false
# 2.2.2 :040 > gzip = ActiveSupport::Gzip.compress('what is this compress me!')
# => "\x1F\x8B\b\x00\x19\x11\x91W\x00\x03+\xCFH,Q\xC8,V(\xC9\x00\x12\xC9\xF9\xB9\x05E\xA9\xC5\xC5\n\xB9\xA9\x8A\x00\x14\x84\x90'\x19\x00\x00\x00"
# 2.2.2 :041 > gzip.bytes[0..1]
# => [31, 139]