Skip to content

Instantly share code, notes, and snippets.

View Hazem-Ben-Khalfallah's full-sized avatar

Hazem Ben Khalfallah Hazem-Ben-Khalfallah

View GitHub Profile
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / jdk-version-compilation.java
Last active May 28, 2021 22:21
[JDK compilation version] Determine Which JDK Version a JAR/Class File Was Compiled With #java
javap -v [path to your class file] | grep 'major version'
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / duplicate_rows.sql
Created December 30, 2019 13:51
[Detect duplicate rows] #sql #mysql
# display duplicate rows
SELECT
*
FROM (
SELECT
person_id,
@rank := IF( @email = email and @firstname = firstname, @rank + 1, 1) AS row_number,
@email := email as email,
@firstname := firstname as firstname
FROM
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / show_constraints.sql
Last active December 30, 2019 11:49
[Show all table constraints] #sql
SELECT TABLE_NAME,
COLUMN_NAME,
CONSTRAINT_NAME,
REFERENCED_TABLE_NAME,
REFERENCED_COLUMN_NAME
FROM information_schema.KEY_COLUMN_USAGE
WHERE TABLE_NAME = "<TABLE_NAME>";
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / ssmparameters.sh
Last active July 11, 2019 15:01
[Get ssm parameter] get all parameters from aws ssm and extract their names and descriptions #aws #ssm
aws ssm describe-parameters --query "Parameters[].{Name:Name,Description:Description}" --output text
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / schema.sql
Last active July 8, 2019 11:08
[DB schema and privileges] #sql #mysql
#connect to mysql
mysql -u root -p
#list privileges
select user,host from mysql.user;
# create new schema
CREATE SCHEMA `[SCHEMA_NAME]` DEFAULT CHARACTER SET utf8;
# grant acess on schema to user
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / uuid_mysql.sql
Last active November 7, 2019 08:50
[UUID to string in Mysql] #sql #mysql
#MySQL 8
#convert uuid binary(16) to String
SELECT BIN_TO_UUID(uuid) FROM foo
#convert uuid string to binary(16)
SELECT UUID_TO_BIN(UUID())
#MySQL 5,6,7
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / disable-foreign_key_constraint.sql
Last active June 14, 2019 16:19
[Disable a foreign key constraint in MySQL] #sql #mysql
#disable
SET FOREIGN_KEY_CHECKS=0;
#reenable
SET FOREIGN_KEY_CHECKS=1;
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / git-credentials.sh
Created May 17, 2019 10:17
[Save git credentials] I want to use a push and pull automatically without entering my user and password in a prompt, every time. #git
# run
git config credential.helper store
#then
git pull
# user credentials will be saved in ~/.git-credentials in PLAIN text
# if user credentials are changed in the future, simply execute
git pull
# and provide a new password and it will work like before.
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / arguments.sh
Last active January 2, 2019 15:32
[Bash args] Bash positional arguments and command line options usage #linux #bash
#see link: http://linuxcommand.org/lc3_wss0120.php
# Positional args
# $#: number of items on the command line in addition to the name of the command
# $0: name of the command
> some_program word1 word2 word3
# $# would be 3
# $0 would contain "some_program"
@Hazem-Ben-Khalfallah
Hazem-Ben-Khalfallah / connect-ssh.sh
Created December 26, 2018 10:50
[Connect via ssh using pem key] Connect to a remote server via #ssh using a pem key #linux
ssh -i ~/.ssh/[KEY_NAME].pem [REMOTE_USER]@[SERVER_IP_or_DNS]