Tech C**P
14 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Is learning a new language hard?

The answer is yes and no. It's a bit like writing. Everybody can learn how to write, and you can too. But what if you wanted ro become a poet? Then writing alone is not enough. You need to learn the rythm 🎼
What are cat and zcat commands and what is their differences?

cat is used to print the content of a file (in stdout or a file, etc). It's main usage is when you want to search something in the whole file like a log file:
sudo cat /var/log/nginx/access.log | grep --color "SOMETHING TO SEARCH"

zcat command on the other is used to get the content of a .gz compressed text file like apache.log.1.gz:
sudo zcat /var/log/apache/apache.log.1.gz | grep --color "SOMETHING TO SEARCH"

NOTE: grep command is used to search in a file. the symbol | (pipeline) is used to send (pipe) first command result into the second command.

#linux #grep #cat #zcat #command
Some useful pip (python package manager) command:

show: used to know specific information about a module installed on your system:
$ pip show requests
Name: requests
Version: 2.13.0
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.com
License: Apache 2.0
Location: /Library/Python/2.7/site-packages
Requires:

search: used to search a python package on pypi.python.org:
$ pip search "suds"
suds-aop (0.6.1) - Lightweight SOAP client (aop's fork)
...
...
...
NOTE: the above list is truncated.

list: list installed packages.
pip list

NOTE: you can grep on pip list to see if a specific package is installed or check its version:
pip list | grep "requests"

freeze: this command does the the same task as list, but its output can be placed inside of the requirements.txt.

uninstall: remove a package from your system:
pip uninstall requests

#python #pip #list #freeze #show #info #search
The table provides a list of useful aggregation functions available in NumPy

#numpy #aggregation #sum #prod #mean #std #min #max #any #all
Some magic about PyCharm:

Type a.if in a .py file and press tab, the final result would be:
if a:

a.ifn:
if a is None:

a.ifnn:
if a is not None:

app.run().main
if __name__ == '__main__':
app.run()

These are called postfix completion and helps programmers to not go back and forth when coding. You can see the complete list in PyCharm setting.

#pycharm #trick #postfix #auto_completion #postfix_completion
طراحی سایت با لوگین و قابلیت پرداخت برای فروش و دانلود Object 3D
جهت تماس با کارفرما لطفا با شناسه زیر ارتباط بگیرید:
@amir3dsmax

#job #project
Some useful docker commands:

docker stack ls
List stacks or apps

docker stack deploy -c <composefile> <appname>
Run the specified Compose file

docker service ls
List running services associated with an app

docker service ps <service>
List tasks associated with an app

docker inspect <task or container>
Inspect task or container

docker container ls -q
List container IDs

docker stack rm <appname>
Tear down an application

docker swarm leave --force
Take down a single node swarm from the manager

#docker #cheatsheet #inspect #stack #swarm #service
Tech C**P
Photo
The CLI uses the Docker REST API to control or interact with the Docker daemon through scripting or direct CLI commands. Many other Docker applications use the underlying API and CLI.

#docker #docker_cli #docker_rest #architecture
To change a password on behalf of a user in Linux, first sign on or "su" to the "root" account. Then type:
passwd user

It will prompt for the password and then prompt to retype the password. The password will be change as soon as you enter retype password.

#linux #passwd #change_password
To make a user as sudoer use usermod as below:
usermod -aG sudo username

If it gives error that sudo group does not exist, use groups to see list of users, it maybe root like below:
usermod -aG root username

#linux #sysadmin #usermod #sudo #sudoer #root
ویندوز بالاخره صاحب ssh می‌شه

https://jadi.net/2017/12/windows-ssh/

یکی از چیزهای بسیار عجیب ویندوز، نداشتن ابزارهای گنو است. این ابزارها که احتمالا روی هم ۱۰۰ مگ هم نیستن بخش بزرگی از قدرت کامند لاین لینوکس رو می‌سازن. یکی از مهمترین این ابزارها ssh برای وصل شدن به سرورهای راه دور بود که نبودنش توی لینوکس و اجبار به استفاده از کلاینت های دهه ۹۰ی مثل پاتی (مشهور به پوتی) یکی از شکنجه هایی است که می شه به هر مدیر سیستم لینوکسی داد.

حالا خوشبختانه ویندوز داره قدم به قدم خودش رو اصلاح می کنه و ظاهرا در ویندوز ۱۰ قراره نه فقط کلاینت که سرور اس اس اچ رو هم داشته باشیم. دقیقا بودن این ابزارها در مک یکی از دلایلی است که مدیر سیستم ها حتی اگر دوست نداشته باشن می تونن با مک کار کنن ولی با ویندوز نه.

اگر این گزینه بتا روی سیستم شما فعال شده، می تونین به Manage Optional Features برین و با زدن Add a feature فهرست رو ببینین و اوپن اس اس اچ کلاینت و سرور و فعال کنین. البته ایده اجرا کردن یک سرویس شبکه ای بتا روی ویندوز شاید خیلی عالی نباشه اما به هرحال شروع خوبیه.

کانال @jadinet
Publish & Subscribe for dummies:

Open 2 different windows (pane) in terminal and go to redis console:
redis-cli

Now to subscribe into a specific channel:
127.0.0.1:6379> SUBSCRIBE first second
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "first"
3) (integer) 1
1) "subscribe"
2) "second"
3) (integer) 2

As you can see we have subscribed to 2 channels called first and second. In another window open redis console again by redis-cli command and try to publish to those channels:
PUBLISH second Hello

Now you should see the output below in the first window where you have subscribed to channels:
1) "message"
2) "second"
3) "Hello"

If you want to know more about pub-sub scenario:
https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern

#redis #pub_sub #publish #subscribe #redis_cli
Hanlde basic authentication (username, password in header) via requests in python:
>>> from requests.auth import HTTPBasicAuth
>>> requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))
<Response [200]>

As you can see above you just need to provide username & password in auth parameter in order to have basic authentication.

#python #requests #authentication #basic #basic_authentication
What is LPUSH in REDIS:

Insert all the specified values at the head of the list stored at key. If key does not exist, it is created as empty list before performing the push operations. When key holds a value that is not a list, an error is returned.

It is possible to push multiple elements using a single command call just specifying multiple arguments at the end of the command. Elements are inserted one after the other to the head of the list, from the leftmost element to the rightmost element. So for instance the command LPUSH mylist a b c will result into a list containing c as first element, b as second element and a as third element.

Return value:
Integer reply: the length of the list after the push operations.

For instance:
redis> LPUSH mylist "world"
(integer) 1
redis> LPUSH mylist "hello"
(integer) 2
redis> LRANGE mylist 0 -1
1) "hello"
2) "world"

NOTE1: time complexity of LPUSH command is O(1). So it is the best from performance point of view.

NOTE2: `LRANGE is used to get list members, if you use 0 to -1 it will return all list elements.

#redis #list #lpush #push