Skip to content

Instantly share code, notes, and snippets.

View rehmatworks's full-sized avatar
👨‍💻
python manage.py domagic

Rehmat Alam rehmatworks

👨‍💻
python manage.py domagic
View GitHub Profile
@rehmatworks
rehmatworks / drop-postgres-forcefully.sh
Created May 6, 2024 08:13
Drop a Postgres Database Forcefully
-- Set the database to reject new connections
ALTER DATABASE db_name CONNECTION LIMIT 0;
-- Terminate all existing connections to the database
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'db_name'
AND pid <> pg_backend_pid();
-- Drop the database
@rehmatworks
rehmatworks / mongodb_unique_index.md
Last active May 28, 2023 12:01
Delete Mongo Duplicates

I needed to create a unique index on a MongoDB collection and I faced the duplicate errors. To delete duplicates, here is what I found to be working. This solution was suggested by ChatGPT 3.5. Please try this at your own risk.

Apologies for the confusion. To delete duplicates while keeping one copy of each document, you can use the following steps:

  1. Connect to your MongoDB database and switch to the "profiles" database.

  2. Identify the duplicate documents based on the "details.company_id" field using the aggregation framework:

@rehmatworks
rehmatworks / world-countries.json
Created April 5, 2023 10:32
List of recognized sovereign countries in JSON format.
[
"Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Angola",
"Antigua and Barbuda",
"Argentina",
"Armenia",
"Australia",
@rehmatworks
rehmatworks / pakistani-surnames.json
Created May 31, 2022 11:03
Pakistani surnames list. I gathered this small dataset for a personal project and publishing it here thinking that it might help someone else too.
[
"Abas",
"Abbas",
"Abbasi",
"Abdul ghani",
"Abdul majid",
"Abdul satar",
"Abdullah",
"Abid",
"Adnan",
@rehmatworks
rehmatworks / pakistani-girl-names.json
Created May 31, 2022 10:46
Pakistani girl names JSON list. I curated this list for a project and publishing it here thinking that it might help someone else too.
[
"Aabha",
"Aabia",
"Aabid",
"Aabida",
"Aabidaat",
"Aabidah",
"Aabir",
"Aabira",
"Aabirah",
@rehmatworks
rehmatworks / kong-rest-client.py
Last active December 10, 2021 09:02
Kong Rest Client
import requests
API_KEY = 'admin-consumer-api-key'
API_BASE = 'https://api.amzdata.io/admin'
CONSUMER_BASE = f'{API_BASE}/consumers'
API_ACL_GROUP_NAME = 'paid-users'
class KongAdmin:
import requests
headers = {
'sec-ch-ua': '"Google Chrome";v="93", " Not;A Brand";v="99", "Chromium";v="93"',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
}
response = requests.get('https://www.dnb.com/business-directory/company-profiles.pfizer_inc.140f48fa0b37556f925afcaec7b5c566.html', headers=headers)
@rehmatworks
rehmatworks / iptables.sh
Created September 8, 2021 18:19
Disallow eth0 traffic for Docker Swarm container
iptables -I DOCKER-USER -i eth0 -j DROP
iptables -I DOCKER-USER -m state --state RELATED,ESTABLISHED -j ACCEPT
@rehmatworks
rehmatworks / nginx-php-fpm.conf
Created July 14, 2021 19:01
NGINX vhost file.
server {
listen 80;
server_name example.com;
root /home/user/sites/example;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
@rehmatworks
rehmatworks / install-nginx-ubuntu.sh
Last active June 22, 2021 08:05
Install, optimize & configure NGINX on Ubuntu 20
# Become root
sudo su
# Update apt package cache
apt update
# Install NGINX
apt install nginx
# Creae a non-sudo user