سوال نرمش ذهن :)
میخواهیم یک دنباله از اعداد را به دو دسته تقسیم کنیم:
فرض کنید ورودی به شما nعدد میدهد، نام این لیست از اعداد را aبگذاریم.
میخواهیم aرا به دو لیست bو cتقسیم کنیم که اولا اعضای bو cبا یکدیگر اشتراک نداشته باشند،
ثانیا هر عضو از aدر یکی از لیست های bیا cباشد. مقدار مجموع اعداد لیست bرا Bو مقدار مجموع
اعضای لیست cرا Cنامگذاری میکنیم. میخواهیم این بخش بندی طوری صورت گرفته باشد که مقدار
B-Cبیشینه باشد.
ورودی:
ابتدا یک عدد nبه عنوان تعداد اعداد لیست aبه شما داده میشود، سپس در nخط بعدی اعضای
لیست aبه عنوان ورودی داده میشود: a1, a2, …, an
1 ≤ n ≤ 100
-100 ≤ a1, a2,…, an ≤ 100
خروجی:
مقدار B-Cرا چاپ کنید.
مثال:
Input
4 1 2 -3 0
Output
10
توضیح: بخش بندی بهینه به این صورت میشود:
b = {4, 1, 2, 0} وc = (-3}
در صورت رسیدن به جواب، پاسخ رو به @Pickle_Ali ارسال کنید.
میخواهیم یک دنباله از اعداد را به دو دسته تقسیم کنیم:
فرض کنید ورودی به شما nعدد میدهد، نام این لیست از اعداد را aبگذاریم.
میخواهیم aرا به دو لیست bو cتقسیم کنیم که اولا اعضای bو cبا یکدیگر اشتراک نداشته باشند،
ثانیا هر عضو از aدر یکی از لیست های bیا cباشد. مقدار مجموع اعداد لیست bرا Bو مقدار مجموع
اعضای لیست cرا Cنامگذاری میکنیم. میخواهیم این بخش بندی طوری صورت گرفته باشد که مقدار
B-Cبیشینه باشد.
ورودی:
ابتدا یک عدد nبه عنوان تعداد اعداد لیست aبه شما داده میشود، سپس در nخط بعدی اعضای
لیست aبه عنوان ورودی داده میشود: a1, a2, …, an
1 ≤ n ≤ 100
-100 ≤ a1, a2,…, an ≤ 100
خروجی:
مقدار B-Cرا چاپ کنید.
مثال:
Input
4 1 2 -3 0
Output
10
توضیح: بخش بندی بهینه به این صورت میشود:
b = {4, 1, 2, 0} وc = (-3}
در صورت رسیدن به جواب، پاسخ رو به @Pickle_Ali ارسال کنید.
سلام و خداقوت به همراهان عزیز کانال،
🔴 بزودی در کنار پادکستهای بسیار زیبای Masters of Scale دوره های آموزشی MongoDB مقدماتی قرار داده می شود (زبان اصلی)
با ما همراه باشید :)
🔴 بزودی در کنار پادکستهای بسیار زیبای Masters of Scale دوره های آموزشی MongoDB مقدماتی قرار داده می شود (زبان اصلی)
با ما همراه باشید :)
If you use
You can do more and sort json keys! To do that pass
#python #json #dumps #indent #sort #sort_keys
json.dumps()
in order to write a json into a file, it will be wriiten all in one line. You can do more with dumps()
. You can pretty print into the file with indentation using indent
parameter:dumped_json = json.dumps(json.loads(content), indent=4)
You can do more and sort json keys! To do that pass
sort_keys
to dumps
function like below:dumped_json = json.dumps(json.loads(content), indent=4, sort_keys=True)
#python #json #dumps #indent #sort #sort_keys
Few days ago we talk about
1- Initiate git object in python by providing path:
2- If you want to
3- Let's say you want to set username and email for git author:
4- Now to add a specific file to staged:
5- Commit the staged file with a message:
6- The final step is to push to a remote repo:
#python #git #gitPython #pull #push #author
gitPython
to work with git inside of python. The code below is a sample that would do all routine tasks like pulling and pushing or commit.1- Initiate git object in python by providing path:
from git import Repo
repo = Repo(repo_path)
2- If you want to
pull
results from git repo:repo.git.pull('origin', 'refs/heads/dev')
3- Let's say you want to set username and email for git author:
config = repo.config_writer()
config.set_value("user", "email", author_email)
config.set_value("user", "name", author_name)
4- Now to add a specific file to staged:
index = repo.index
index.add([file_path])
5- Commit the staged file with a message:
index.commit(commit_message)
6- The final step is to push to a remote repo:
repo.git.push('origin', 'refs/heads/dev')
#python #git #gitPython #pull #push #author
In case you want to serve static files in your website in nginX, you can add a new
This is it, whether it is a uwsgi proxy, fpm, etc.
#web_server #nginx #static #location #serve
location
directive to your server block that corresponds to your website:server {
# your rest of codes in server block...
location / {
location ~ \.(css|ico|jpg|png) {
root /etc/nginx/www/your_site/statics;
}
# your rest of codes...
}
}
This is it, whether it is a uwsgi proxy, fpm, etc.
#web_server #nginx #static #location #serve
Netflix has open sourced his container management system called
- https://netflix.github.io/titus/
Source code and Docs:
- https://github.com/Netflix/titus
#container_orchestration #docker #container #golang #go #netflix #titus #aws
Titus
written in Go Lang
. You can see documentation of it here:- https://netflix.github.io/titus/
Source code and Docs:
- https://github.com/Netflix/titus
#container_orchestration #docker #container #golang #go #netflix #titus #aws
GitHub
GitHub - Netflix/titus
Contribute to Netflix/titus development by creating an account on GitHub.
If you have installed mysql server and want to install
The solution is to install
If you have installed
#mysql #mysql_config #MYSQLpython
MYSQL-python
package, you may encounter the below error like me:EnvironmentError: mysql_config not found
The solution is to install
libmysqlclient-dev
:sudo apt-get install libmysqlclient-dev
If you have installed
MariaDB
then:sudo apt-get install libmariadbclient-dev
#mysql #mysql_config #MYSQLpython
If you have installed
You need to install
You can also do:
#python #google_api_python_client
google-api-python-client
and got below error on authentication:No crypto library available
You need to install
PyCrypto
using pip or PyOpenSSL
.You can also do:
sudo pip install PyOpenSSL --upgrade
#python #google_api_python_client
If you have
Read the below article to set SSL on server side:
- https://docs.mongodb.com/manual/tutorial/configure-ssl/
Now in order to set
- http://api.mongodb.com/python/current/examples/tls.html
#mongodb #ssl #tls #pymongo
mongoDB
as your database and you query on DB from an external network, make sure you have SSL in place. By not using SSL everyone can evesdrop on the network data which is transmitted in between.Read the below article to set SSL on server side:
- https://docs.mongodb.com/manual/tutorial/configure-ssl/
Now in order to set
SSL=True
in mongo python driver head over to link below to read more on:- http://api.mongodb.com/python/current/examples/tls.html
#mongodb #ssl #tls #pymongo
Mongodb
Configure mongod and mongos for TLS/SSL - Database Manual v8.0 - MongoDB Docs
Configure MongoDB instances for TLS or SSL encryption using native OS libraries. Ensure strong ciphers with a minimum 128-bit key length for secure connections.
If you want to make an exact copy of a table from another database into a target database in
The above command will create a table named
#mysql #database #create_table #table #copy_table
mySQL
you could do like below:create table new_table like target_database.target_table
The above command will create a table named
new_table
like target_table
from target_database
database.#mysql #database #create_table #table #copy_table
If you want to disable mouse in
It just kills me when I want to work with vim with mouse enabled!
#linux #debian #vim #mouse_enabled
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
If you have list of numbers like below:
Now let's say you want to check a partial number like
would you do?
It's clear that you cannot do something like:
So to check all the list element and also check the partial number we can do as below:
We have explained
#python #any #for
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. Whatwould 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
http://phoenixframework.org/blog/the-road-to-2-million-websocket-connections
The Road to 2 Million Websocket Connections in Phoenix
The Road to 2 Million Websocket Connections in Phoenix
www.phoenixframework.org
The Road to 2 Million Websocket Connections in Phoenix - Phoenix Blog
If you have been paying attention on Twitter recently, you have likely seen some increasing numbers regarding the number of simultaneous connections the Phoenix web framework can handle. This post documents some of the techniques used to perform the benchmarks.