Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
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
How to query on Google Big Query?

Big Query or for short BQ is a data warehousing solution that puts your data on a serverless platform with no limit on data size and processing power. It is design for this specific purpose and returns aggregated results in a fraction of a second most of the time.


In python you can use its library by installing google-cloud-bigquery:

pip install --upgrade google-cloud-bigquery

Now create a service account as stated in link below:

https://cloud.google.com/bigquery/docs/reference/libraries

We assume that you have done the installation and configuration process for now. To query on BQ:

from google.cloud import bigquery
bigquery_client = bigquery.Client()
dataset_id = 'MY_PROJECT'
query = ("SELECT user_id FROM MY_PROJECT.users LIMIT 100")

# API CALL
query_job = bigquery_client.query(query)

for row in query_job:
print row.user_id, row['user_id']


You can send update commands like the above query too.

#google #BI #bigdata #bigquery #warehouse #data_warehouse
How to implement email tracking solution?

nginX has a module called empty_gif that generates a 1*1 pixel image. It is usually put at the end of campaign emails in order to track how many users have opened the email. The code for nginX is:

location = /empty.gif {
empty_gif;
expires -1;
post_action @track;
}

location @track {
internal;
proxy_pass http://tracking-backend/track$is_args$args;
proxy_set_header x-ip $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}


The above code check if /empty.gif URL is requested, if answer is yes then serve the image and makes expires to -1 to not cache the image and finally using post_action which calls a sub request after the current request has been fininshed. The parameters you need to pass is put after the image link in email like:

https://www.example.com/empty.gif?token=SOMETHING_TO_TRACK
#nginx #email #empty_gif #email_tracking #pixel
Vue.js 2.epub
13.1 MB
How to convert the below line of string:

data = '15 0 42 50 "some text" "" 4 4 "text"'

into:

[15, 0, 42, 50, 'some text', '', 4, 4, 'text']

As you may have noted you cannot use split as there are texts with spaces in between. For that we can use the below code:

import csv
import io

file = io.StringIO(data) # use io.BytesIO in python 2
reader = csv.reader(file, delimiter=' ')
split_data = next(reader)
parsed_data = [int(x) if x.isdigit() else x for x in split_data]

NOTE: use io.BytesIO instead of io.StringIO in case you are using python 2.

#python #csv #reader #split #stringIO #byteIO
How to disable visual block in VIM?

There is a feature in vim that as you select a text inside of vim, it turns the mode into VISUAL BLOCK. This is annoying for me in case you want to disable it put the below code in ~/.vimrc:

set mouse-=a

#vim #visual_block #mouse #set #vimrc