For enabling push notification on pushd server, you need to get a file with
We need to generate 2 pem files one called
To generate
And now generate the key pem file:
Restart the pushd and check for any error in
#pushd #openssl #p12 #cer #pem #push
.p12
extension and .cer
certificate file. For pushd to work you need to generate a .pem
file and give its path in push configuration(`/etc/pushd/pushd.conf`).We need to generate 2 pem files one called
apns-cert.pem
(generated from .cer
file) and the other called apns-key.pem
(generated from .p12
file).To generate
.pem
file use openssl command, with the format below:openssl pkcs12 -in YOUR_KEY.p12 -out apns-key.pem -nodes
NOTE:
it may ask you for the password, enter the given password by whom that gave you the p12
file.-in
set your input file name and -out
sets your output file name which will be generated.And now generate the key pem file:
openssl x509 -in cert.cer -inform DER -outform PEM -out apns-cert.pem
Restart the pushd and check for any error in
/var/log/pushd
.#pushd #openssl #p12 #cer #pem #push
lowercase/uppercase a function, variable or a string in
#pycharm #lowercase #uppercase
PyCharm
by using:OS X: Command+Shift U
#pycharm #lowercase #uppercase
Download a static file from a remote URL by using
#python #requests #stream #large_file #download
requests
in python:# author -> Roman Podlinov
def download_file(url):
local_filename = url.split('/')[-1]
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
return local_filename
NOTE:
stream=True parameter is used for returning large files in chunk and save it into a file#python #requests #stream #large_file #download
Django
tutorials will be published today or the day after, sorry for the delay. 🙈In order to create a debian package from your shell script do as follow:
Let's consider our package name is
You can copy the files into your package with the full paths on the destination filesystem. E.g. if you want to put a file in
In your
Now build the package using
This creates a dangling.deb file, which you can now install on any Debian installation with following command:
#debian #deb #create #package #dpkg #build
Let's consider our package name is
dangling
. We need to create 2 folders, first is called dangling and the second is DEBIAN
which is inside of the dangling folder:mkdir helloworld && mkdir helloworld/DEBIAN
You can copy the files into your package with the full paths on the destination filesystem. E.g. if you want to put a file in
/usr/local/bin/
you put it in dangling/usr/local/bin/
:mkdir -p dangling/usr/local/bin
cp /usr/local/bin/dangling.sh dangling/usr/local/bin/
In your
DEBIAN
directory (created at the begining of the post), create a control
file with the below content:<span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Package: dangling
</span><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Version: 0.1
</span><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Maintainer: Alireza Hoseini
</span><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Architecture: all
</span><span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; white-space: pre;">Description: would wipe all docker dangling volumes out
NOTE:
These are the mandatory fields in the control file.Now build the package using
dpkg-deb
:dpkg-deb --build dangling
This creates a dangling.deb file, which you can now install on any Debian installation with following command:
dpkg -i dangling.deb
#debian #deb #create #package #dpkg #build
In case you want to add a custom font to
reference: https://support.apple.com/en-us/HT201722
#apple #osx #font #fonts
OS X
, you need to go to /Library/fonts
and paste your custom fonts in this folder. No need to restart or logout.reference: https://support.apple.com/en-us/HT201722
#apple #osx #font #fonts
Apple Support
Mac OS X: Font locations and their purposes
Mac OS X has multiple Fonts folders. Where you install a font determines who can use it and when.
DJANGO
Let's do a little bit more by fetching data from database and pass them to views in
Django
.For now we make a change in
polls/views.py
in index
function to get data from Question
model and return it as an HTTP response object. At first let's import the model:from .models import Question
And now in
index
function write the below code:latest_question_list = Question.objects.order_by('-pub_date')[:5]
output = ', '.join([q.question_text for q in latest_question_list])
return HttpResponse(output)
The code above gets the last 5 questions and on the second line
question_text
fields for those questions are joined together by comma and finally returned as an HTTP response.
Now if you head over to
http://127.0.0.1:8000/polls/
you would see the result of question texts bound together by comma.
#python #django #query #django_part9
Here we aim to design templates and render them to interact with
Create a folder called
We have
Now put the below code in
OK now do as follow in index function in
Note that we have imported
As you can see above, we have rendered the template with our variables (context) and passed it to http response object. We have used
I've got the below result (next picture) what about you?
#django #loader #render #templates #django_part10
Django
the way it likes! We try to isolate the page's design.Create a folder called
templates
in polls directory (this is the default folder name where django
will look for app templates). Inside of templates create polls
directory and inside of it create index.html
file. So your templates are in path polls/templates/polls/index.html
.We have
polls
inside of templates folder to render templates in the format of loader.get_template('polls/index.html')
.NOTE:
if you don't create polls
subdirectory inside of templates and you have templates we the same name in different apps (in the same project) you would encounter bizarre problems. DON'T DO THAT! (Django will choose the first template it finds whose name matches)Now put the below code in
polls/templates/polls/index.html
:{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
OK now do as follow in index function in
polls/views.py
for template rendering:from django.http import HttpResponse
from django.template import loader
from .models import Question
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
template = loader.get_template('polls/index.html')
context = {
'latest_question_list': latest_question_list,
}
return HttpResponse(template.render(context, request))
Note that we have imported
loader
from django.template
.As you can see above, we have rendered the template with our variables (context) and passed it to http response object. We have used
django.template
module to render templates.I've got the below result (next picture) what about you?
#django #loader #render #templates #django_part10
Tech C**P
http://pyvideo.org/pydata-amsterdam-2017/a-pythonic-tour-of-neo4j-and-the-cypher-query-language.html
PyData Amsterdam 2017
This talk gives an overview of the Neo4j graph database and the Cypher query language from the point of view of a Python user. We'll look at how to run queries and visualise or extract those results into software such as Pandas. We'll also explore the property graph data model and look at how it differs from other data models.
Graph databases offer a fresh perspective on data modelling and one that is often closer to the real world than a traditional RDBMS. In this talk, we'll look at how to work with Neo4j's property graph data model from the point of view of a Python user, how this model differs from other database models and we'll also show how to integrate the Cypher query language into a Python application.
This talk will (hopefully!) contain a couple of live demonstrations. We'll explore how to integrate Cypher query results with data analysis tools such as Pandas as well as how to visualise graph data through the Neo4j browser.
#neo4js #python #pandas #pyvideo
This talk gives an overview of the Neo4j graph database and the Cypher query language from the point of view of a Python user. We'll look at how to run queries and visualise or extract those results into software such as Pandas. We'll also explore the property graph data model and look at how it differs from other data models.
Graph databases offer a fresh perspective on data modelling and one that is often closer to the real world than a traditional RDBMS. In this talk, we'll look at how to work with Neo4j's property graph data model from the point of view of a Python user, how this model differs from other database models and we'll also show how to integrate the Cypher query language into a Python application.
This talk will (hopefully!) contain a couple of live demonstrations. We'll explore how to integrate Cypher query results with data analysis tools such as Pandas as well as how to visualise graph data through the Neo4j browser.
#neo4js #python #pandas #pyvideo
How much do you know about python
This module provides a standard interface to extract, format and print stack traces of Python programs.
It acts a lot like a python interpreter when it print a stack trace.
Print exception information and up to limit stack trace entries from the traceback tb to file. This is a shorthand for
This is like
A sample
#python #traceback #exception #format_exc #print_exc
traceback
? Here we will dive deep into this concept.What is a traceback?
This module provides a standard interface to extract, format and print stack traces of Python programs.
It acts a lot like a python interpreter when it print a stack trace.
traceback
module has many functions, we will review some of them here.traceback.print_exc()
:Print exception information and up to limit stack trace entries from the traceback tb to file. This is a shorthand for
print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)
.traceback.format_exc()
:This is like
print_exc(limit)
but returns a string instead of printing to a file.A sample
traceback
usage derived from python
documentation:import sys, traceback
def run_user_code(envdir):
source = raw_input(">>> ")
try:
exec source in envdir
except:
print "Exception in user code:"
print '-'*60
traceback.print_exc(file=sys.stdout)
print '-'*60
envdir = {}
while 1:
run_user_code(envdir)
#python #traceback #exception #format_exc #print_exc