Skip to content

Instantly share code, notes, and snippets.

@shivai
shivai / jalaliToEpoch.py
Last active August 4, 2018 06:49
Convert jalali date to epoch
import jdatetime
import datetime
import csv
input_file = "/home/shiva/Desktop/input.csv"
output_file = "/home/shiva/Desktop/output.csv"
dlm = "," # delimiter
with open(input_file, 'r') as csv_file:
reader = csv.DictReader(csv_file, delimiter=dlm)
output = open(output_file, 'w')
@shivai
shivai / screen-commands.md
Last active June 27, 2021 13:55
Screen- Linux commands

Screen Commands:

Exit the detached screen:

screen -X -S [session # you want to kill] quit

How to go to a screen:

screen -r [session]

Apache enable SSL

To enable ssl following these steps:

  1. Run the llowing commands:
 root@root#a2enmod ssl
 root@root#a2ensite default-ssl.cnf
  1. Make a directory in /etc/apache2/ and cd to it:
root@root#mkir /etc/apache2/ssl

Apache HTTP redirect to HTTPS

To forced redirect from http to https following these steps:

  1. create or open htaccess file:
root@root#nano /var/www/html/.htaccess
  1. add these lines:
RewriteEngine On
RewriteCond %{HTTPS} off
@shivai
shivai / psql.md
Last active April 24, 2024 14:44

PSQL sample commands

Copy command:

copy (select * from user_attrs) to '/tmp/bkp_user_attrs_2018_dec_19.csv' delimiter ',' CSV header quote'""'

Inser command:

insert into user_attrs(user_id, attr_name, attr_value) select user_id, attr_name, attr_value from tmp_real_login

Alter:

Install RabbitMQ Server

# apt install rabbitmq-server
# systemctl enable rabbitmq-server
# systemctl restart rabbitmq-server

Note: If the debian's version is less than 9 you don't have systemctl and you should use /etc/init.d/rabbitmq-server .. Note: RabbitMQ default port is 5672

To change RabbitMQ listening address, you should copy following

Some Usefull commands for RabbitMQ

Full documentation: https://www.rabbitmq.com/rabbitmqctl.8.html

    # rabbitmqctl add_user <username> <password>
    # rabbitmqctl set_user_tags <username> administrator
    # rabbitmqctl set_permissions -p / <username> ".*" ".*" ".*"
    # rabbitmqctl list_users
    
 # rabbitmqctl authenticate_user  
import socket
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 1234 # Port to listen on (non-privileged ports are > 1023)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:

awk and sed sample commands:

Delete trailing commas in line

sed 's/,*\r*$//'

like this:

@shivai
shivai / Set_timezone.md
Last active February 4, 2019 08:26
Set timezone

Set timezone

dpkg-reconfigure tzdata