Create an excel file using pandas in python:
#pandas #python #excel #dataframe
users = [{
'user_id': 1
}, {
'user_id': 2
}]
df = pandas.DataFrame(users, columns=['user_id'])
filename = 'users_info_%s.xlsx' % random.randint(0, 100)
writer = pandas.ExcelWriter(filename, engine='xlsxwriter')
df.to_excel(writer, sheet_name='user information')
#pandas #python #excel #dataframe
If you want to implement Oauth2.0 read RFC below thoroughly:
https://tools.ietf.org/html/rfc6749
#oauth #rfc #rfc6749
https://tools.ietf.org/html/rfc6749
#oauth #rfc #rfc6749
tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.
after installation you can list your sessions by:
Output would be something like this:
You can attach a session by:
Now let's say you want to detach a session you need to press ^b+d (CONTROL+b and then press d).
If you want to split your window to multiple panes press ^b+" (split horizontally) and/or ^b+% (split vertically).
^b+n : next window
^b+(up/down/left/right) : to move between panes
^b+? : help and shortcuts
^b+x : kill a pane
THE GREAT THING about
I know you will get tired if I say more about tmux, so go and explore more yourself and see the real power of multiplexers.
#tmux #linux #sysadmin #terminal #multiplexer
after installation you can list your sessions by:
tmux ls
Output would be something like this:
0: 1 windows (created Mon Aug 7 10:34:00 2017) [135x52] (attached)
2: 1 windows (created Mon Aug 7 13:56:10 2017) [126x25]
(attached)
at the end of session 0 tells us that the session has been attached by a user.You can attach a session by:
tmux attach -t 0
-t
tells tmux which session should be attached.Now let's say you want to detach a session you need to press ^b+d (CONTROL+b and then press d).
If you want to split your window to multiple panes press ^b+" (split horizontally) and/or ^b+% (split vertically).
^b+n : next window
^b+(up/down/left/right) : to move between panes
^b+? : help and shortcuts
^b+x : kill a pane
THE GREAT THING about
tmux
is that multiple users can attach the same session and work simultaneously!I know you will get tired if I say more about tmux, so go and explore more yourself and see the real power of multiplexers.
#tmux #linux #sysadmin #terminal #multiplexer
You can add title to iOS push notification as of iOS 8.2:
#push #notification #ios
A short string describing the purpose of the notification. Apple Watch displays this string as part of the notification interface. This string is displayed only briefly and should be crafted so that it can be understood quickly. This key was added in iOS 8.2.
#push #notification #ios
Emails need to have call to actions. It encourages users to pay more, to charge his account or to buy a product.
Display CTAs the right time to target users to increase ROI (return of investment)
#call_to_action #email #end_user #ROI
Display CTAs the right time to target users to increase ROI (return of investment)
#call_to_action #email #end_user #ROI
Tech C**P
You can add title to iOS push notification as of iOS 8.2: A short string describing the purpose of the notification. Apple Watch displays this string as part of the notification interface. This string is displayed only briefly and should be crafted so that…
{
"aps":{
"alert":{
"body":"The status of flight KL123 scheduled 20:30 to London Heathrow has changed to 'boarding'. Boarding at 20:05.",
"title":"Boarding at 20:05"
},
"category":"openFlightCategory"
},
}
"aps":{
"alert":{
"body":"The status of flight KL123 scheduled 20:30 to London Heathrow has changed to 'boarding'. Boarding at 20:05.",
"title":"Boarding at 20:05"
},
"category":"openFlightCategory"
},
}
As you all may know pip is a python package manager and everyone has worked with it to install python libs.
Some of the commands with pip that you may not know about it:
- freeze: output installed packages in requirements format. (you can grep and search for a specific package):
- list: list installed packages:
- show: Show information about installed packages:
Important note for devops: pip by default install a stable version of the package. If you need to install an unstable version of the package (latest version) use
If you want to manage your custom python repository package versions (RC, Alpha, Beta, Stable, etc) add
The important part is
To see list of
https://pypi.python.org/pypi?%3Aaction=list_classifiers
Now you can give versioning like
To see different classifiers see the link
https://pypi.python.org/pypi/Django
#django #pip #pre_release #freeze #package #python #devops
Some of the commands with pip that you may not know about it:
- freeze: output installed packages in requirements format. (you can grep and search for a specific package):
rply==0.7.4
rsa==3.2.3
sasl==0.2.1
scipy==0.13.0b1
- list: list installed packages:
tcpwatch (1.3.1)
telebot (0.0.3)
thrift (0.9.3)
- show: Show information about installed packages:
$ pip show pandas
Name: pandas
Version: 0.17.0
Summary: Powerful data structures for data analysis, time series,and statistics
Home-page: http://pandas.pydata.org
Author: The PyData Development Team
Author-email: pydata@googlegroups.com
License: BSD
Location: /Library/Python/2.7/site-packages
Requires: numpy, python-dateutil, pytz
Important note for devops: pip by default install a stable version of the package. If you need to install an unstable version of the package (latest version) use
--pre
flag to install pre-release package.If you want to manage your custom python repository package versions (RC, Alpha, Beta, Stable, etc) add
classifiers
to your setup.py script like below:setup(...,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Environment :: Web Environment',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Python Software Foundation License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python',
'Topic :: Communications :: Email',
'Topic :: Office/Business',
'Topic :: Software Development :: Bug Tracking',
],
)
The important part is
Development Status :: 4 - Beta
, which for stable release you would use Development Status :: 5 - Production/Stable
.To see list of
pypi
Development Status values read from the below link:https://pypi.python.org/pypi?%3Aaction=list_classifiers
Now you can give versioning like
Django 2.0b1
(for pre release) and Django 1.11.6
for stable release.To see different classifiers see the link
Django
link below to learn more:https://pypi.python.org/pypi/Django
#django #pip #pre_release #freeze #package #python #devops
put a key in dictionary into another key and remove it from dictionary:
Idiots way:
Tech C**P way:
#pop #python #dictionary #code_improvement
Idiots way:
data = {
'username': 'alireza@gmail.com'
}
data['email'] = data['username']
del data['username']
Tech C**P way:
data = {
'username': 'alireza@gmail.com'
}
data['email'] = data.pop('username')
pop
access the data and remove it from data payload. In case username
is not in data, an error will be raised. To prevent such an error give it default value:data['email'] = data.pop('username', 'NO_USERNAME')
#pop #python #dictionary #code_improvement
A Fantastic completely FREE course to implement ONLINE ESHOP using
https://scotch.io/courses/build-an-online-shop-with-vue
vue.js
:https://scotch.io/courses/build-an-online-shop-with-vue
Digitalocean
Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
There is a mgic method in python called contains which should return true if item is in self, false otherwise.
The method signature of contains:
Samples:
BUT DONT USE this magic methods this way, as it should be used in internal class operations.
Membership test operator for this is
Side note: methods which are started by _ (underscore) should not be called directly outside of class scope. They meant for internal class operations.
#python #membership #in #contain #exist
The method signature of contains:
object.__contains__(self, item)
Samples:
>>> 'sample_output'.__contains__('sample')
True
>>> 'sample_output'.__contains__('ASL')
False
BUT DONT USE this magic methods this way, as it should be used in internal class operations.
Membership test operator for this is
in
. In case you want to test membership:>>> 'sample' in 'sample_output'
True
>>> 'ASL' in 'sample_output'
False
Side note: methods which are started by _ (underscore) should not be called directly outside of class scope. They meant for internal class operations.
#python #membership #in #contain #exist
OneSignal - free multiplatform push notification service
Send 100% FREE push notifications to Android, iOS, Web by their completely free SDKs on
OneSignal
. #OneSignal is multiplatform push notification service that you just interact with it using API calls in JSON format. It has a thorough documentation for SDKs and Server API.* BE AWARE THAT use
OneSignal
in case your user's privacy does not matter to you! They have mentioned in their privacy policy that they sell this information!!! All device locations, user email addresses and all the other sensetive data will be collected by OneSignal
.#push_notification #push #ios #android #web #notification #one_signal
It is sometimes tempting to log less in order to let's say improve performance or save disk space, and blah blah blah!
Loggers in python are the last thing to think about when you think about performance. You can place log ratote to use less disk space. From my own experience log as much as you can. Log as every step necessary to make log level verbose. At last in case you think you application is very stable you change log level to info, and all debug logs are ignored.
It took sometimes hours to debug a few modules (in microservice structure) to find the culprit, something that could have been solved by putting more logs.
Log, log and log more...
#python #log #logger #performance
Loggers in python are the last thing to think about when you think about performance. You can place log ratote to use less disk space. From my own experience log as much as you can. Log as every step necessary to make log level verbose. At last in case you think you application is very stable you change log level to info, and all debug logs are ignored.
It took sometimes hours to debug a few modules (in microservice structure) to find the culprit, something that could have been solved by putting more logs.
Log, log and log more...
#python #log #logger #performance
UWSGI - Web server Gateway Interface
-----
uwsgi is a big C application which is used to deploy python applications on server. There is a full documentation of UWSGI in
Reference: http://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
#python #uwsgi #reference #flask #readthedocs
-----
uwsgi is a big C application which is used to deploy python applications on server. There is a full documentation of UWSGI in
readthedocs
, follow it and master it to handle loads of requests concurrently and use graceful reloading of the app. It is usually put behind a full web server like nginX by proxying.Reference: http://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
#python #uwsgi #reference #flask #readthedocs