If you have Mac system and created bash scripts so far, there is a fun feature on OS X that you can type
Or let's say you have a bash script that will take a lot of time and at the end of the script your want to hear
#osx #say #command #fun
say
command. say
will say the phrase:say hello channel users
Or let's say you have a bash script that will take a lot of time and at the end of the script your want to hear
operation done successfully
from your speaker:say operation done successfully
#osx #say #command #fun
There is a command in osX called
The great thing about this command is that you can open finder when you have traversed a long path and now you want it to have inside of finder. Go to the desired directory in your terminal using
it will open you finder. :)
#osx #open #command #fun #trick
open
that will open finder for you from within of your terminal.The great thing about this command is that you can open finder when you have traversed a long path and now you want it to have inside of finder. Go to the desired directory in your terminal using
cd
then use:open .
it will open you finder. :)
#osx #open #command #fun #trick
If you get the below error for
To solve this problem, put the below line of code before any
reference: https://github.com/npm/npm/issues/13306
#npm #docker #container #cross_device
cross device link
when installing npm on container:npm WARN optional Skipping failed optional dependency /webpack/watchpack/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.12
npm ERR! Linux 3.16.0-4-amd64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v6.3.0
npm ERR! npm v3.10.3
npm ERR! path /app/node_modules/istanbul/node_modules/abbrev
npm ERR! code EXDEV
npm ERR! errno -18
npm ERR! syscall rename
npm ERR! EXDEV: cross-device link not permitted, rename '/app/node_modules/istanbul/node_modules/abbrev' -> '/app/node_modules/abbrev'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /app/npm-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 238
To solve this problem, put the below line of code before any
npm
command:RUN cd $(npm root -g)/npm && npm install fs-extra && sed -i -e s/graceful-fs/fs-extra/ -e s/fs.rename/fs.move/ ./lib/utils/rename.js
reference: https://github.com/npm/npm/issues/13306
#npm #docker #container #cross_device
GitHub
EXDEV: cross-device link not permitted, rename... in Docker · Issue #13306 · npm/npm
I'm opening this issue because: npm is crashing. npm WARN optional Skipping failed optional dependency /webpack/watchpack/chokidar/fsevents: npm WARN notsup Not compatible with your operating s...
Today in django tutorial series we define 2 models in
Our model's parent class is django
* The name of each field is the column name in the table.
* max_length can be given as an argument to put restrictions on field's length
* you can give a human readable name to each field by providing an optional first positional argument like pub_date which is set to
* you can define foreign keys by
* fields can have default value is we have set for votes by using
Until now
Now use
Finally use the below command to create the tables:
So we've done 2 steps overall:
1- used
2- applied the migration generated in step 1 by using
#python #django #migrate #models #migrate #makemigrations #django_part5
polls/models.py
. One for Question
and another for Choice
.from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
Our model's parent class is django
models.Model
and each model has its own fields. You can define string field by CharField
, integer by IntegerField
and datetime by DateTimeField
.* The name of each field is the column name in the table.
* max_length can be given as an argument to put restrictions on field's length
* you can give a human readable name to each field by providing an optional first positional argument like pub_date which is set to
date published
* you can define foreign keys by
models.ForeignKey
* fields can have default value is we have set for votes by using
default
Until now
Django
knows nothing about our polls app, we need to plug it in, in order to include it in our project. Go to saturn/settings.py
and do as follow:INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Now use
makemigrations
command to tell Django to store new model changes in migrations
folder inside of polls:$ python manage.py makemigrations polls
Migrations for 'polls':
polls/migrations/0001_initial.py
- Create model Choice
- Create model Question
- Add field question to choice
Finally use the below command to create the tables:
$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, polls, sessions
Running migrations:
Applying polls.0001_initial... OK
migrate
is smart and just applies those changes needed, if you are careful enough you can see that a file is created that is called polls.0001_initial
. This file is created by our command makemigrations
in the previous step.So we've done 2 steps overall:
1- used
makemigrations
to create migration files.2- applied the migration generated in step 1 by using
migrate
.#python #django #migrate #models #migrate #makemigrations #django_part5
Django has an admin panel that does lots of tedious works that if you had to create yourself, it wouldn't be an easy t
ask. In this part we try to build the admin panel from ground up.
First of all an admin panel needs an admin user. So create one first:
Ok after creating the admin user, run the developement server:
Now point your URL to
e administrator page of Django.
#python #django #admin #dashboard #createsuperuser #django_part6
ask. In this part we try to build the admin panel from ground up.
First of all an admin panel needs an admin user. So create one first:
$ python manage.py createsuperuser
Username (leave blank to use 'fc'): alireza
Email address: a***@***.com
Password:
Password (again):
Superuser created successfully.
Ok after creating the admin user, run the developement server:
$ python manage.py runserver
Now point your URL to
http://127.0.0.1:8000/admin/
. You should see the login page in the next post. Login and see the administrator page of Django.
#python #django #admin #dashboard #createsuperuser #django_part6
Tech C**P
Django has an admin panel that does lots of tedious works that if you had to create yourself, it wouldn't be an easy t ask. In this part we try to build the admin panel from ground up. First of all an admin panel needs an admin user. So create one first:…
Django has an admin panel that does lots of tedious works that if you had to create yourself, it wouldn't be an easy task. In this part we try to build the admin panel from ground up.
First of all an admin panel needs an admin user. So create one first:
Ok after creating the admin user, run the developement server:
Now point your URL to
#python #django #admin #dashboard #createsuperuser #django_part6
Now to see polls in admin page, you need to register you models. open
Last 2 lines are added to register the
First of all an admin panel needs an admin user. So create one first:
$ python manage.py createsuperuser
Username (leave blank to use 'fc'): alireza
Email address: a***@***.com
Password:
Password (again):
Superuser created successfully.
Ok after creating the admin user, run the developement server:
$ python manage.py runserver
Now point your URL to
http://127.0.0.1:8000/admin/
. You should see the login page in the next post. Login and see the administrator page of Django.#python #django #admin #dashboard #createsuperuser #django_part6
Now to see polls in admin page, you need to register you models. open
polls/admin.py
:# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import Question
admin.site.register(Question)
Last 2 lines are added to register the
Question
model as picture below:If you want to monitor a specific
Here in above sample we are monitoring port
#linux #monitoring #sysadmin #icinga2 #host #tcp #port
tcp port
on Icinga2
you just need to add another tcp
variable:object Host "host-web" {
import "generic-host-tpl"
address = "YOUR_SERVER_IP_ADDRESS"
vars.os = "Linux"
vars.tcp["OPTIONAL_NAME"]={
tcp_port=8181
}
Here in above sample we are monitoring port
8181
of host-web
which has the IP address of YOUR_SERVER_IP_ADDRESS
(change it to your server ip address remote or local).#linux #monitoring #sysadmin #icinga2 #host #tcp #port
In order to remove a specific document in
Use this method in preference over
#couchdb #couch #delete #remove #document #python
couchDB
, you just need to give delete
function the document itself:couch = couchdb.Server('http://SERVER_IP:PORT/')
your_db = couch['your_db_name']
# we assume you have fetched your_couch_db_doc document
your_db.delete(your_couch_db_doc)
Use this method in preference over
__del__
to ensure you're deleting the revision that you had previously retrieved. In the case the document has been updated since it was retrieved, this method will raise a ResourceConflict
exception:>>> db.delete(doc) # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
ResourceConflict: (u'conflict', u'Document update conflict.')
#couchdb #couch #delete #remove #document #python
If you want to find an element inside of a list in
Now if you want to find a document that has the value of
#mongodb #mongo #find #list #array
MongoDB
document you can use the simple find command. Let's say you have the below documents:[{
"food": "Ghorme",
"creation_date": "2017-10-12 12:00:00"
"rates": ["bad", "so_so", "not_bad", "mmmm"]
},{
"food": "Kebab",
"creation_date": "2017-10-07 22:10:00"
"rates": ["great", "not_bad", "great", "great"]
}]
Now if you want to find a document that has the value of
bad
in rates
, you just use the below find
query:db.foods.find({rates: "bad" }).pretty()
#mongodb #mongo #find #list #array
Tech C**P
Photo
Setup a proxy server by using
#proxy #switchy_omega #ssh #tunnel #socks
SwitchyOmega
chrome addon. Download and install it from chrome store and setup the credential as picture. Use ssh -D 5300 USERNAME@YOUR_SERVER_IP
to proxy your browser traffic (server should be located in Europe or America).#proxy #switchy_omega #ssh #tunnel #socks
How to use
If you want to use conditional statements like
#python #jinja2 #template_engine #template
if
in jinja2
template engine?Jinja2
is a modern and designer-friendly templating language for Python, modelled after Django’s templates. It is fast, widely used and secure.If you want to use conditional statements like
if
inside of template engine you should use a syntax like below:{% if status == 'success' %}
Some text for successful procedure
{% else %}
Some text for not successful procedure
{% endif %}
#python #jinja2 #template_engine #template