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 / 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 / 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 / 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')
@y2k-shubham
y2k-shubham / clean_windows_text_file.sh
Created March 31, 2020 12:53
clean text-files generated in windows for programmatic consumption in linux
# Removes invisible characters (like formfeed)
# also coerces UTF-8 encoding
iconv -c -f utf-8 -t ascii source_filename.csv > destination_filename.csv
import hashlib
import os
import sys
# /////////////////////////
# file-read / write methods
# /////////////////////////
def get_utf8_file_descriptor(file_path, mode):
@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 / 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 / airflow_webserver_stacktrace.log
Last active December 24, 2019 09:51
Stacktrace generated on Airflow's Webserver when I try to manually trigger DAG via WebUI
____/ ( ( ) ) \___
/( ( ( ) _ )) ) )\
(( ( )( ) ) ( ) )
((/ ( _( ) ( _) ) ( () ) )
( ( ( (_) (( ( ) .((_ ) . )_
( ( ) ( ( ) ) ) . ) ( )
( ( ( ( ) ( _ ( _) ). ) . ) ) ( )
( ( ( ) ( ) ( )) ) _)( ) ) )
( ( ( \ ) ( (_ ( ) ( ) ) ) ) )) ( )