Tech C**P
14 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
If you want to disable mouse in vim 8 in new Debian, put the below line in your ~/.vimrc:

set mouse=c

It just kills me when I want to work with vim with mouse enabled!

#linux #debian #vim #mouse_enabled
An interesting scenario in Python

If you have list of numbers like below:

numbers= ["+98121434", "+9821322", "+986241234"]


Now let's say you want to check a partial number like 121434, or 98121434 or +98121434 to see if it is inside of the list. What
would you do?

It's clear that you cannot do something like:

# YOU CANNOT DO THIS!
if number in numbers:
pass


So to check all the list element and also check the partial number we can do as below:

if any(partial_number in s for s in numbers):
pass


We have explained any before enough. Check previous posts for any and all.


#python #any #for
Tech C**P
http://phoenixframework.org/blog/the-road-to-2-million-websocket-connections The Road to 2 Million Websocket Connections in Phoenix
از اونجا که تب پیام رسان های داخلی داغ هست بد نیست مطلب بالا رو مرورکنید برای اینکه بدونید چطور کرنل لینوکس رو بهبود میدن تا کانکشن های زیاد رو هندل کنند.
♨️ با توجه به اخبار منتشر شده مبنی بر فیلتر تلگرام، لطفا در صورت تمایل آدرس ما در ایتا را دنبال کنید:

یادداشت های فنی یک برنامه نویس در طول کار.
https://eitaa.com/technical_notes
A couple days ago we talked about MongoDB that uses TLS/SSL to encrypt the communication with clients connecting to it (like pyMongo). Now if you want to test MongoDB with self-signed certificate you can generate one with the command below:

cd /etc/ssl/
openssl req -newkey rsa:2048 -new -x509 -days 365 -nodes -out mongodb-cert.crt -keyout mongodb-cert.key


This operation generates a new, self-signed certificate with no passphrase that is valid for 365 days. Once you have the certificate, concatenate the certificate and private key to a .pem file, as in the following example:

cat mongodb-cert.key mongodb-cert.crt > mongodb.pem


If using the YAML configuration file format, include the following configuration in the file:

net:
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb.pem

NOTE: instead of requireSSL you can use preferSSL to not force the requirement. It depends on the requirements and network topolgy.


#mongodb #ssl #tls #pem #openssl
Now to make you MongoDB client connection secure just pass ssl=True:

# test_mongodb_ssl.py
client = pymongo.MongoClient('example.com', ssl=True)


When you run this script check your mongoDB logs (usually in /var/log/mongodb/mongod.log`). The thing you should take into account is that when you pass `ssl=True parameter to MongoClient you just should see the below log (ip addresses wil vary):

I NETWORK  [listener] connection accepted from 172.15.141.162:50761 #49 (39 connections now open)
I NETWORK [conn49] end connection 172.15.141.162:50761 (38 connections now open)


Now remove ssl=True from MongoClient or pass ssl=False. If you now run your test script, you would see something like below in mongod.log:

I NETWORK  [listener] connection accepted from 172.15.141.162:50762 #50 (39 connections now open)
I NETWORK [conn50] SSL mode is set to 'preferred' and connection 50 to 172.15.141.162:50762 is not using SSL.

It says that SSL mode in mongo config is set to preferSSL and your new connection to mongo is not using it.

YOU NEED TO BE CAUTIOUS that we have created our SSL ourselves and it is vulnerable to man in the middle attack. For production usage purchase you SSL/TLS certifcate.

#mongodb #mongo #ssl #pymongo
https://dank.sh/

Coding font for developers :)

#font #dank #mono #dank_mono
To run grafana in Docker:

docker run -d -p 3000:3000 grafana/grafana


Now if you want to install specific plugins you need to provide the name as an environment variable GF_INSTALL_PLUGINS:

docker run \
-d \
-p 3000:3000 \
--name=grafana \
-e "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource" \
grafana/grafana


#grafana #docker #plugins
When I paste something in vim all lines get indentation:

line
line
line

To solve this issue just go to command mode by pressing ESC on your keyboard now type:

:set paste

Then paste your code. Note that the text in the tooltip now says -- INSERT (paste) --.


NOTE: After you pasted your code, turn off the paste-mode, so that auto-indenting when you type works correctly again.

:set nopaste


You can set a keyboard shortcut for it (here F5):

set pastetoggle=<F5>


#editor #vim #nopaste #paste #pastetoggle
Metabase by default uses H2 Database for its internal usage and storing questions and dashboards that you are created. When you want to move from one host to another it can be tricky and it may crash! Here you will lose your dashbaords and your containers. This matter
gets important when you have loads of data there (let's say hundreds of questions and tens of dashboards).

The safest way for production is to migrate this data to MySQL. It makes Metabase to use MySQL as its backend not H2 Database. To migrate your data from current working H2 DB of Metabase you need to set following variables first:

export MB_DB_TYPE=mysql
export MB_DB_DBNAME=metabase
export MB_DB_PORT=3306
export MB_DB_USER=<username>
export MB_DB_PASS=<password>
export MB_DB_HOST=localhost
java -jar metabase.jar load-from-h2

The last command will run metabase and forces it to migrate data to MySQL. In case needed create metabase database in mySQL with sufficient privileges. It should come up safely with no much headache. After moving data remove you *.db metabase h2 DB file.

#metabase #migration #H2 #mysql
Running Metabase on another port

By default Metabase will launch on port 3000, but if you prefer to run the application on another port you can do so by setting the following environment variable:

export MB_JETTY_PORT=3500
java -jar metabase.jar

In this example once the application starts up you will access it on port 3500 instead of the default port of 3000.


#metabase #port #jetty_port