tag:blogger.com,1999:blog-11566523123745181752024-03-05T06:49:53.637-05:00b:devBoris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.comBlogger109125tag:blogger.com,1999:blog-1156652312374518175.post-82408824045754790282019-03-06T10:42:00.000-05:002019-03-06T10:42:46.560-05:00New language injection in PyCharmI love the PyCharm's ability to recognize one code type inside another. It is very convenient to use all the help to edit, say, SQL query inside a python function. However, I noticed if you have an HTML snippet inside the python code, it's not recognized as HTML, just as mere string. Time to fix it.
1. Go to Preference -> Language Injections
2. Press Add (the plus sign icon under the list Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-69152213963997988962019-02-12T18:49:00.000-05:002019-02-12T18:49:13.545-05:00Top 5 biggest tables in currently active scheme in PostgreSQLSELECT C.relname AS table_name,
pg_size_pretty(pg_total_relation_size(C.oid)) AS total_size,
S.n_live_tup AS total_rows
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
LEFT JOIN pg_stat_user_tables S ON (C.relname = S.relname)
WHERE nspname NOT IN ('pg_catalog', 'Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-33990756875098881132019-02-12T17:37:00.004-05:002019-02-12T17:37:40.971-05:00Drop all active connections to PostgreSQL serverSELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'db' -- ! replace db with the target database name
AND pid <> pg_backend_pid();Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-61309809218705623402018-12-03T10:33:00.001-05:002018-12-03T10:33:15.757-05:00Questions for a Senior Python develoeprA list of question to help you assess your Python seniority.
Questions
When will the else part of try-except-else be executed?
What are metaclasses in Python?
What is monkey patching? How to use in Python? Example?
What are the tools that help to find bugs or perform static analysis? What static code analyzers do you know/used?
Whenever Python exits, why isn’t all the memory Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-30552521230459400232017-08-10T07:32:00.000-04:002017-08-10T07:32:46.695-04:00Local docker deployment update with AWS CodeBuild#!/usr/bin/env bash
# Prerequisites
# $WORKDIR/.env - environment variables
# awscli installed virtualenv env dir in $WORKDIR
set -e
WORKDIR=
PROJECT=project name
DOCKER_REPO=codebuild docker image
REPO_TAG=latest
cd $WORKDIR
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
echo ' -s|--skip-build - skip building image'
exit 0
;;
-s|--skip-build)
SKIP_BUILD=Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-46372126654423983162016-02-25T17:12:00.005-05:002016-02-25T17:12:59.239-05:00Django query loggingRecently I had to optimise some piece of legacy code that worked slow. Among other refactoring procedures I wanted to check what queries gets invoked exactly. Having dug Django Docs and internets I came up with solution.
Using this, you'll get all executed queries in the console
For example:
2016-02-25 15:57:47 DEBUG utils.py:89 (0.055) SET SQL_AUTO_IS_NULL = 0; args=None
2016-02-25 15:57:Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-48292400669213567122016-02-24T17:26:00.001-05:002016-02-24T17:26:47.502-05:00No more commits with debugging codeMost of you have certainly found yourself in the situation when after committing and pushing you realise you've forgotten to delete some code you added for debugging purpose? I am prone to it and after yet another doing it I decided to let git itself monitor my commits and prevent me from wrongdoing. From me does it require to put a comment in the file I do not want to be committed before all theBoris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-15460918492417106592013-09-03T02:56:00.000-04:002013-09-03T02:56:37.838-04:00Install GeoIP from MaxMind on OS XI could not find a package ready to use to get running GeoIP from MaxMind on OS X so I built it from sources. To do so, I
Downloaded sources
Unpacked it tar xvfz GeoIP-latest.tar.gz
cd GeoIP-1.5.1
./configure
make
make check
make install
That is it. It's ready to go.
Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-23702238502456799302013-08-02T05:25:00.000-04:002013-08-02T05:25:44.344-04:00Parse any number string to floatfunction stringToFloat(str) {
var fractional_part, integer, fractional = "", found = false, i;
// remove leading and trailing non-digit symbols
str = str.replace(/[^\d,\.]+$/, '').replace(/^[^\d,\.]+/, '');
fractional_part = str.slice(-3);
for (i = fractional_part.length - 1; i >= 0; i--) {
if (/\d/.test(fractional_part[i])) {
fractional = Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-48327283552514311542013-07-02T10:29:00.001-04:002013-07-02T10:29:49.946-04:00Delete tagsTo delete tags in git that match some regex, both locally and remotely, I use these two commands
# remove tags on origin
git ls-remote --tags | awk '/tags\/release.*[^\}]$/ {print ":" $2}' | xargs git push origin
# remove locally
git tag -l | awk '/^release.*$/ {print $1}' | xargs git tag -d
Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-52979910852713663292013-05-14T12:02:00.001-04:002013-05-14T12:02:59.715-04:00Increase trackpad speed beyond system settingsIf you are not satisfied with your trackpad speed and you've already set it to the maximum in System Settings pane, it could help you.
Go to Terminal and
open ~/Library/Preferences/.GlobalPreferences.plist
You need com.apple.trackpad.scaling. System Preferencies's maximum is 3. From my experience, 30 is insane. I use 15, it's enough to move cursor with one movement from the left side of left Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-48995488562305821542013-04-24T18:51:00.000-04:002013-04-24T19:01:44.369-04:00Showing an image when dragging any tag in HTMLChrome and Safari support displaying a ghost image for draggable objects out of the box, Firefox does not. It's not a big deal, I'd say a matter of one event handler.
This is a sample HTML:
Drag Me!
and JavaScript code:
$(function () {
var dragImage = document.createElement("img");
dragImage.src = "/image/to/show/when/dragging.jpg";
function handleDragStart(e) {
Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-68817107507346462542013-04-15T10:08:00.000-04:002013-04-15T10:08:19.539-04:00Line numbers in Vim
pre {font-style:italic;}
I would like to cover all aspects known for me related to the line numbers in Vim.
CommandDescription
:0move cursor to the first
:4242gg42Gmove cursor to 42nd
:Gmove cursor to the last
Show line numbers in current file
:set number
Hide line numbers in current file
:set nonumberBoris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-18239505621736605682013-04-09T11:31:00.000-04:002013-04-09T11:31:38.336-04:00Computed field on TabularInline (StackedInline)Django admin doesn't provide list_display attribute on its inline admin classes. That's right, since the only supposed view for those classes is editable form. So, to display a result of custom function's call, it needs to add the name of the function (that can be declared either on the admin or model classed) to both fields and readonly_fields.
Example:
class StatsInline(admin.TabularInline):
Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-82736218237932423762012-11-22T07:14:00.000-05:002012-11-22T07:16:10.181-05:00Reduce directory nestingOnce I encountered a problem with image files that were named according to their checksum of the content chunked by 2 symbols 6 times, so it gets like 2f/d4/e1/c6/7a/2d/28fced849ee1bb76e7391b93eb12.jpg.
To have this structure with approx. 13M files, I got short in inodes. After a quick research and calculations I realized that such nesting depth is redundant and easily can be reduced. Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-85324738127567393452012-10-07T06:43:00.001-04:002012-10-07T07:17:52.168-04:00Sync your development environment with a remote oneWhile the developing process you need sometimes to sync you local development database with a remote one (i.e. production).
Below there is a script allowing to recreate the development database and fill in with data from the remote server.
MySQL
#!/bin/sh
DBUSER_REMOTE="root"
DBPASSWORD_REMOTE="root"
DBUSER_LOCAL="root"
DBPASSWORD_LOCAL="root"
DBNAME_REMOTE=""
DBNAME_LOCAL=""
TMPFILE="$(mktempBoris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-11878699298308566202012-09-28T17:14:00.001-04:002012-10-03T09:25:53.235-04:00Favicon sizesThe browser can use the favicon in different situations, like to show it on the tab, for the bookmark and so forth. There are a few sizes the favicon can be. Here I gathered the most often and broadly used.
Favicon sizes
<link rel="icon" type="image/png" sizes="16x16" href="favicon@16.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon@32.png">
<link rel="icon" Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-11429793526642153372012-08-03T10:59:00.000-04:002012-08-03T10:59:21.439-04:00PyCharm can't run a project with MySQL databaseI wanted to run my project in PyCharm IDE and got this error.
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/boris/env/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/boris/env/lib/python2.7/site-packages/_mysql.so
Reason: image not found
After googling a while I figured out there is a Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-38227366409005052442012-04-28T04:48:00.002-04:002012-04-28T04:48:32.076-04:00Fatal Python error: Couldn't create autoTLSkey mappingMy last project I started with Django 1.4 and Django Compressor. Today I decided to deploy to the production its first version. I used nginx+Apache.
Everything seemed to be good but instead of normal page I got:
FilterError at /
Unable to apply CompilerFilter (lessc {infile} {outfile})I tried to repeat the same with ./manage.py runserver. It works. So the issue not in configuration or lessc Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com1tag:blogger.com,1999:blog-1156652312374518175.post-81473836734823990522012-03-30T05:26:00.000-04:002012-03-30T05:26:20.243-04:00Install MySQL on Mac OS X to work with PythonI need to get mysql support for python on my Mac OS X Lion.
Download the latest MySQL .DMG distributive from somewhere (i.e. official website) and install it.
sudo pip install python-mysql
It requires superuser privileges to get installed.
What may happen:
while installing mysql-python
Downloading/unpacking mysql-python
Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
Running Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com1tag:blogger.com,1999:blog-1156652312374518175.post-80503186843633718362012-03-07T06:00:00.000-05:002012-03-07T06:00:31.529-05:00Dealing with Tabs in vimTo insert space characters whenever the tab key is pressed, set the 'expandtab' option:
:set expandtab
With this option set, if you want to enter a real tab character use Ctrl-V<tab> key sequence.
To control the number of space characters that will be inserted when the tab key is pressed, set the 'tabstop' option. For example, to insert 4 spaces for a tab, use:
:set tabstop=4
After the Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-53662680512368074212012-02-17T01:20:00.000-05:002012-02-17T01:20:43.074-05:00Allow remote connections to MySQL serverTo enable remote access for MySQL server:
$ sudo vim /etc/mysql/my.cnf
### edit my.cnf
### set bind address and comment out or remove skip-networking (if exists)
[mysqld]
...
bind-address=SERVER-EXTERNAL-IP
# skip-networking
$ /etc/init.d/mysql restart
Now it works.Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-25055059671496333482012-02-10T04:58:00.003-05:002012-02-10T04:58:31.532-05:00{less} mix function errorDocumentation tells mix function takes only two parameters, @color1 and @color2. Actually there is a mistake. The correct function definition is
mix(@color1, @color2, value)
, where value denotes how much of @color1 should appear in the result color.
Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com1tag:blogger.com,1999:blog-1156652312374518175.post-87922766065435460952012-02-07T01:23:00.000-05:002012-02-07T01:23:07.464-05:00Trap Ctrl C in Bash#!/bin/bash
# call trapped in case Ctrl+C pressed
trap trapped INT
function trapped() {
echo "CTRL-C pressed"
}
while true; do
sleep 1
echo -n "."
done
Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0tag:blogger.com,1999:blog-1156652312374518175.post-39642476856206248482012-02-03T11:25:00.001-05:002012-02-03T11:25:47.921-05:00Setup Apache2's mod_wsgi on UbuntuIf you get this when restarting Apache2 on Ubuntu
Invalid command 'WSGIDaemonProcess', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.it means you don't have mod_wsgi module installed.
These commands install and enable it.
sudo apt-get install libapache2-mod-wsgi
sudo a2enmod mod-wsgi
sudo /etc/init.d/apache2 restart
Boris Shttp://www.blogger.com/profile/14516674078568554978noreply@blogger.com0