Skip to content

Instantly share code, notes, and snippets.

View pharzan's full-sized avatar

Farzan pharzan

View GitHub Profile
@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
@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 / 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 / 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 / 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 / keybase.md
Last active April 22, 2019 18:00
keybase

Keybase proof

I hereby claim:

  • I am pharzan on github.
  • I am pharzan (https://keybase.io/pharzan) on keybase.
  • I have a public key ASD7kHx7hIepix8J9Oyrh6QAK0VIXiksugOW_TuQgdIv2wo

To claim this, I am signing this object:

@pharzan
pharzan / server.py
Last active March 6, 2024 10:03
esp8266 post json data using usocket
#listens to the above run to
#FLASK_APP=server.py FLASK_DEBUG=1 python3.5 -m flask run -h 192.168.1.124 -p 8999:
#run this on the local server to listen to socket communication
from flask import Flask, render_template, jsonify
from flask import request as query
app = Flask(__name__)
@pharzan
pharzan / format.py
Last active November 30, 2017 07:52
Format ESP8266 01 File system
#to format:
from flashbdev import bdev
uos.VfsFat.mkfs(bdev)
vfs = uos.VfsFat(bdev, "")
# to create a boot.py file:
with open("/boot.py", "w") as f:
f.write("""\
# This file is executed on every boot (including wake-boot from deepsleep)
import esp