Skip to content

Instantly share code, notes, and snippets.

View pharzan's full-sized avatar

Farzan pharzan

View GitHub Profile
@pharzan
pharzan / Django run script with arguments
Created October 11, 2017 10:57
how to run a Django script with arguments
# inside the script we should have something like below:
def run(*script_args):
print (script_args)
# from the shell when calling the script to run use the --script-args to pass in arguments and they will be recieved as tuples inside the script
#-> example: python manage.py runscript myscript --script-args Testing 123
will return ('Testing','123')
@pharzan
pharzan / NoneType check.txt
Created September 28, 2017 10:17
Django snippets
So how can I question a variable that is a NoneType?
Use is operator, like this
''
if variable is None:
''
Why this works?
Since None is the sole singleton object of NoneType in Python, we can use is operator to check if a variable has None in it or not.
Quoting from is docs,
@pharzan
pharzan / NoneType check.txt
Created September 28, 2017 10:17
Django snippets
So how can I question a variable that is a NoneType?
Use is operator, like this
''
if variable is None:
''
Why this works?
Since None is the sole singleton object of NoneType in Python, we can use is operator to check if a variable has None in it or not.
Quoting from is docs,
@pharzan
pharzan / NoneType check.txt
Created September 28, 2017 10:17
Django snippets
So how can I question a variable that is a NoneType?
Use is operator, like this
''
if variable is None:
''
Why this works?
Since None is the sole singleton object of NoneType in Python, we can use is operator to check if a variable has None in it or not.
Quoting from is docs,
@pharzan
pharzan / hack.txt
Created September 28, 2017 07:43
PostgreSQL won't start on Mint /var/run/postgresql/.s.PGSQL.5432
After installing postgreSQL and rebooting Mint when recieved I would recieve the following error saying can't start postgres
while trying to run Django
could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain
socket “/var/run/postgresql/.s.PGSQL.5432”?
sudo mkdir /var/log/postgresql
sudo chown postgres.postgres /var/log/postgresql
sudo su postgres
touch /var/log/postgresql/postgresql-9.1-main.log
@pharzan
pharzan / create.txt
Last active September 28, 2017 07:36
Backup PostgreSQL database to a local file and retrieve it
# create a bakup:
sudo su - postgres
pg_dump postgres > postgres_db.bak
# options:
pg_dump -U user_name -h remote_host -p remote_port name_of_database > name_of_backup_file