Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
jinja2 has tons of filters for strings, lists, etc that can be used to make the process of, um well, filtering simpler.

To apply a filter you can use pipe symbol (|). In order to lower case`/`upper case a string:
{{"SOMETHING"|lower}}
{{"sOmThing"|upper}}

Or let's say getting the max number from a list:
{{ [1, 2, 3]|max }}

The filters are endless, see below for more:
http://jinja.pocoo.org/docs/2.10/templates/#filters

#python #jinja2 #template #filter #uppercase #lowercase #max
Did you push a very large file into git? Does everyone yell at you about your commit and your uselessness? Are you a junky punky like me that just ruin things? Oh I'm kidding...

Because of that big file cloning the repo again would take a long long time. Removing the file locally and pushing again would not solve the problem as that big file is in Git's history.

If you want to remove the large file from your git history, so that when everyone clone the repo should not wait for that large file, just do as follow:

git filter-branch --tree-filter 'rm path/to/your/bigfile' HEAD

git push origin master --force

I should note that you should be in the root of git repo.

If you need to do this, be sure to keep a copy of your repo around in case something goes wrong.

#git #clone #rm #remove #large_file #blob #rebase #filter_branch
As you may know you can use capitalize to make the first letter of a word upper case. For example you can turn failed to Failed.

In Jinja2 you can use title to do the same job:

{{ "failed" | title }}

#python #jinja2 #filter #title #capitalize
In axigen mail server you can set a filter that if sender email address (from) has a specific text using regexp then redirect it to
another mailbox:

Security and Filtering -> Acceptance and Routing -> Advanced settings -> Add acceptance / routing rule

Phew! Now in Conditions section open combo box and select Email under Recipient. Click Add condition. A text box is appeared now which you can select Regexp from the combo box and enter your regex like:

.*SpecificSender.*

Now in actions section in name enter the mail address you want to receive emails in and in Folder text box enter INBOX.

This is it.

#mail #mail_server #axigen #filter #routing
What is filters in Python Logging and what we can do with it?

Filter is a way to tell logger not to log or to log something. Let's say you print sensitive data in a core module that can also handle passwords. Here you don't want to record user passwords in you logs! Do you?!

class NoPasswordFilter(logging.Filter):
def filter(self, record):
return not record.getMessage().startswith('password')

logger.addFilter(NoPasswordFilter())

The above method will not log lines which start with password. You can use regex to find your template in you logs and return false
to not record them or mask the password part by chaning the the log using:

record.msg

Just get your message using the above line and replace it with something you want.

#python #logging #filter