Skip to content

Instantly share code, notes, and snippets.

View y2k-shubham's full-sized avatar
🏁
Chasing Checkpoints

Shubham Gupta y2k-shubham

🏁
Chasing Checkpoints
View GitHub Profile
@y2k-shubham
y2k-shubham / sql_find_and_replace_regex.txt
Created October 16, 2019 04:37
SQL-query-keyword-capitalization
Find regex: `(?<!\w)(insert|is|into|with|as|select|from|where|between|and|or|distinct|case|when|then|else|end|on|null|not|inner|outer|full|join|left|right|group|by|order|limit|in)(?!\w)`
Replace regex: `\U$1\E`
@y2k-shubham
y2k-shubham / ConnectionPoolManager.scala
Created September 6, 2018 13:59
ScalikeJdbc ConnectionPool wrapper utility
import java.sql.Connection
import com.typesafe.scalalogging.Logger
import com.company.utils.jdbc.MySQLConfig
import scalikejdbc.{ConnectionPool, ConnectionPoolSettings, DB, using}
import scala.util.control.NonFatal
object ConnectionPoolManager {
@y2k-shubham
y2k-shubham / yarn_applications_kill.sh
Created January 25, 2020 19:59
Kill all running YARN applications
`yarn application --list | awk '{print $1}' | grep application | xargs yarn application -kill`
@y2k-shubham
y2k-shubham / ImageTextRenderUtils.php
Created June 26, 2020 17:20
Utility PHP snippet to wrap text (meant to be rendered on image) using pixel width
<?php
namespace Utils;
class ImageTextRenderUtils {
/**
* Returns expected width of rendered text in pixels
@y2k-shubham
y2k-shubham / create_pool.py
Created December 17, 2018 07:10
Code snippet to create Airflow Pool
from airflow.settings import Session
from airflow.utils.db import provide_session
from airflow.models import Pool
# hive_pool is just an example, you might want to create some other types of pools such as for MySQL
@provide_session
def create_hive_pool(session: Optional[Session] = None) -> None:
pool = Pool(pool=pool_templates['hive_name'],
slots=1,
description=pool_templates['hive_description'])
@y2k-shubham
y2k-shubham / ArrayUtils.php
Last active November 12, 2020 21:31
PHP utility functions for array manipulation
class ArrayUtils {
/**
* - Groups a (non-associative) array of items into associative array of chunks (of items), where key of chunk
* is determined by $key_retriever callable
* OR
* - Groups elements of an array into subarrays, thereby converting Array into Array[group => Array]
*
* - Check unit-tests to understand further
* @param array $data
@y2k-shubham
y2k-shubham / git_remote_branch_show.sh
Last active August 8, 2020 03:39
git show all (remote) branches of particular remote
# reference: https://stackoverflow.com/a/30076212/3679900
git for-each-ref 'refs/remotes/my-origin' --sort=-committerdate refs/heads --format='%(refname:short)%09%(committerdate:relative)%09%(authorname)%09%(subject)%09'|column -ts'|'
@y2k-shubham
y2k-shubham / alias.sh
Last active March 31, 2020 12:58
rsync
rsync -avze "ssh -t -p 272 {user_name_on_entry}@entry.organization.farm ssh admin@XXX.XX.XX.XX" {home_folder_name} :/home/admin/{dest_folder_name}
@y2k-shubham
y2k-shubham / mysql_table_sizes.sql
Created March 31, 2020 12:56
get size (raw-data) of all selected mysql tables
-- reference: https://stackoverflow.com/a/9620273/3679900
SELECT TABLE_NAME AS `Table`,
round(((data_length) / 1024 / 1024 / 1024), 2) `Size-in-GB`
FROM information_schema.TABLES
WHERE table_schema = 'my_db_name'
AND TABLE_NAME IN ('my_table_1',
'my_table_2')
ORDER BY (data_length) DESC
@y2k-shubham
y2k-shubham / hive_ddl_clean_regex.txt
Created March 31, 2020 12:54
regex to clean Hive DDL statements
# this regex will clean output of Hive's SHOW CREATE TABLE .. statement
(^\| |\s+\|$| COMMENT 'from deserializer')