Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Okan Menevşeoğlu okanmenevseoglu

🏠
Working from home
View GitHub Profile
@okanmenevseoglu
okanmenevseoglu / lsof.sh
Last active Aug 3, 2020
Listen Ports on Mac for Applications
View lsof.sh
lsof -Pi | grep LISTEN
@okanmenevseoglu
okanmenevseoglu / generate-ssh-key.sh
Last active Mar 31, 2020 — forked from grenade/01-generate-ed25519-ssh-key.sh
Correct file permissions for ssh keys and config.
View generate-ssh-key.sh
ssh-keygen -t rsa -b 4096 -N '' -C "rthijssen@gmail.com" -f ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "rthijssen@gmail.com" -f ~/.ssh/github_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "rthijssen@gmail.com" -f ~/.ssh/mozilla_rsa
View git-commands.sh
// Clone a single branch
git clone --single-branch --branch <branch-name> <git-repo-name>
View docker-commands.sh
// Pull and image from a repository.
docker pull <repository-image-url>:<tag>
// Run an image with a bash shell.
docker run -it <image-name or image url>:<tag> /bin/bash
// Mount a volume to an image and run it
docker run -v <host-volume>:<docker-volume> <image-name or image url>:<tag>
// Connect to a running container
@okanmenevseoglu
okanmenevseoglu / user-management.sql
Created Feb 23, 2018
Creating User and Giving Granular Access to the User on PostgreSQL
View user-management.sql
-- Create new user to the DB
CREATE USER {{username}} WITH ENCRYPTED PASSWORD {{password}};
-- Give access connection to the wanted DB
GRANT CONNECT ON DATABASE {{dbname}} TO {{username}};
-- Give access to the wanted schema
GRANT USAGE ON SCHEMA {{schemaname}} TO {{userName}};
-- Give select access to the sequences for the wanted schema
@okanmenevseoglu
okanmenevseoglu / pg_stat_activity.sql
Created Feb 13, 2018
Viewing the Activity Table on PostgreSQL in detail and Terminating a pid
View pg_stat_activity.sql
-- To be able to use these in full detail, you must have the necesarry role authentication
-- Find activity list on DB
select * from pg_stat_activity
-- Find pid, user name, query, backend start date, transaction start date, query start date and the longest running sql times that are active and idle in transaction
SELECT pid, usename, query, backend_start, xact_start, query_start, (now() - query_start) AS run_time FROM pg_stat_activity WHERE state IN ('active', 'idle in transaction') ORDER BY query_start
-- Terminate the sql with the given pid
SELECT
@okanmenevseoglu
okanmenevseoglu / bootable-usb-install-drive-for-macos.sh
Last active Feb 7, 2018
How to Make a Bootable macOS USB Install Drive
View bootable-usb-install-drive-for-macos.sh
# 1) Download Mac Version to install from App Store
# 2) Put a USB stick at least 8 GB
# 3) Open Terminal and enter the following command:
sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume
@okanmenevseoglu
okanmenevseoglu / EntityQuery.java
Created Jan 29, 2018 — forked from ufuk/JpaEntityQueryBuilder.java
Easy to use query builder for JPA Criteria API (including example usages)
View EntityQuery.java
package ...;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.*;
import java.util.*;
import java.util.stream.Collectors;
@okanmenevseoglu
okanmenevseoglu / postgresql-cryptography-functions.sql
Created Jan 29, 2018 — forked from ufuk/postgresql-cryptography-functions.sql
Enable cryptography functions (pgcrypto extension) in PostgreSQL.
View postgresql-cryptography-functions.sql
CREATE EXTENSION pgcrypto;
-- Examples
SELECT ENCODE(DIGEST('password', 'md5'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha1'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha224'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha256'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha384'), 'hex');
SELECT ENCODE(DIGEST('password', 'sha512'), 'base64');
@okanmenevseoglu
okanmenevseoglu / postgres-create-drop-index-online.sql
Last active Jan 29, 2018
Create/Drop a database index online (without locking the table) on PostgreSQL
View postgres-create-drop-index-online.sql
CREATE INDEX CONCURRENTLY {indexName} ON {tableName} ({columnName});
DROP INDEX CONCURRENTLY {indexName};