Skip to content

Instantly share code, notes, and snippets.

@RajatGoyal
RajatGoyal / capsense
Last active January 3, 2016 18:59
Capacitive sensing arduino without a sensor.
// readCapacitivePin
// Input: Arduino pin number
// Output: A number, from 0 to 17 expressing
// how much capacitance is on the pin
// When you touch the pin, or whatever you have
// attached to it, the number will get higher
#include "pins_arduino.h" // Arduino pre-1.0 needs this
int pintoread1=10;
int pintoread2=5;
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time, sys
username = 'gyl.rajat@gmail.com'
password = 'xxxxx'
driver = webdriver.Chrome()
==> amazon-ebs: Launching a source AWS instance...
2017/01/05 17:01:38 ui: amazon-ebs: Instance ID: i-07359bd734cf85429
2017/01/05 17:01:38 ui: ==> amazon-ebs: Waiting for instance (i-07359bd734cf85429) to become ready...
amazon-ebs: Instance ID: i-07359bd734cf85429
2017/01/05 17:01:38 packer: 2017/01/05 17:01:38 Waiting for state to become: running
2017/01/05 17:01:38 packer: 2017/01/05 17:01:38 Using 2s as polling delay (change with AWS_POLL_DELAY_SECONDS)
2017/01/05 17:01:38 packer: 2017/01/05 17:01:38 Allowing 300s to complete (change with AWS_TIMEOUT_SECONDS)
==> amazon-ebs: Waiting for instance (i-07359bd734cf85429) to become ready...
2017/01/05 17:01:57 ui: amazon-ebs: Public DNS: ec2-54-91-125-146.compute-1.amazonaws.com
2017/01/05 17:01:57 ui: amazon-ebs: Public IP: 54.91.125.146
import argparse
import os
import sys
SPARK_HOME = '/usr/share/dse/spark'
import findspark
findspark.init(spark_home=SPARK_HOME)
import pyspark
@RajatGoyal
RajatGoyal / copy_data.sql
Last active May 23, 2017 06:46
copy data in batches from one table another, so that transfer does not happen in a single transactions
DECLARE @BatchSize INT = 20000
declare @StartId = 0;
declare @MaxId;
select @MaxId = max(Id) from [dbo].[SOURCE] .
WHILE 1 = 1
BEGIN
INSERT INTO [dbo].[Destination]
SELECT *
@RajatGoyal
RajatGoyal / estimated_bill.sh
Last active September 7, 2018 18:21
total estimated bill aws
#!/bin/sh
from_email="from@synaptic.com"
to_email="to@synaptic.com"
max_estimated_charge_12_hour=$(aws --region us-east-1 cloudwatch get-metric-statistics \
--namespace "AWS/Billing" \
--metric-name "EstimatedCharges" \
--dimension "Name=Currency,Value=USD" \
--start-time $(date +"%Y-%m-%dT%H:%M:00" --date="-12 hours") --end-time $(date +"%Y-%m-%dT%H:%M:00") \
@RajatGoyal
RajatGoyal / abstract_mysql_adapter.rb
Created May 5, 2019 10:32
Monkey patch AbstractMysqlAdapter to set mysql 8 resource group while making a new connection
require 'active_record/connection_adapters/abstract_mysql_adapter'
module ActiveRecord
module ConnectionAdapters
class AbstractMysqlAdapter
alias :old_configure_connection :configure_connection
def configure_connection
begin
execute 'SET RESOURCE GROUP etl'
@RajatGoyal
RajatGoyal / debezium_cdc.py
Created April 2, 2020 20:27
debezium cdc memsql
#!/usr/bin/python
import struct
import sys
import json
binary_stdin = sys.stdin if sys.version_info < (3, 0) else sys.stdin.buffer
binary_stderr = sys.stderr if sys.version_info < (3, 0) else sys.stderr.buffer
binary_stdout = sys.stdout if sys.version_info < (3, 0) else sys.stdout.buffer
@RajatGoyal
RajatGoyal / debezium_cdc.py
Last active April 2, 2020 21:12
debezium cdc memsql
#!/usr/bin/python
import struct
import sys
import json
binary_stdin = sys.stdin if sys.version_info < (3, 0) else sys.stdin.buffer
binary_stderr = sys.stderr if sys.version_info < (3, 0) else sys.stderr.buffer
binary_stdout = sys.stdout if sys.version_info < (3, 0) else sys.stdout.buffer
@RajatGoyal
RajatGoyal / request_logging_server.py
Created June 3, 2020 19:28
http server to dump request ip, headers and check if javascript is executing.
# To start: python3 request_logging_server.py
# returns a html page with
# 1) is javascript working
# 2) request headers
# 3) request ip address
# scraping this page can help you, when you are debugging if the request is using proxy, cookies, and correct headers
# when accessing from the same machine the address would be 0.0.0.0:8004
import http.server
import socketserver