Skip to content

Instantly share code, notes, and snippets.

View z4y4ts's full-sized avatar
🎯
Focusing

Alexander Zayats z4y4ts

🎯
Focusing
View GitHub Profile
@z4y4ts
z4y4ts / exception
Last active August 29, 2015 14:07
mongoshmongo
Traceback (most recent call last):
File "metrics.py", line 32, in <module>
test()
File "metrics.py", line 27, in test
distance_type='jaccard')
File "/Users/ai/.virtualenvs/unshred/lib/python2.7/site-packages/mongoengine/queryset/base.py", line 201, in create
return self._document(**kwargs).save()
File "/Users/ai/.virtualenvs/unshred/lib/python2.7/site-packages/mongoengine/document.py", line 229, in save
doc = self.to_mongo()
File "/Users/ai/.virtualenvs/unshred/lib/python2.7/site-packages/mongoengine/base/document.py", line 255, in to_mongo
@z4y4ts
z4y4ts / base.py
Last active August 29, 2015 14:17 — forked from mrjoes/base.py
Flask-Admin CSV export model view
class BaseModelView(ModelView):
list_template = 'admin/model_list.html'
export_columns = None
# Exporting
def _get_data_for_export(self):
view_args = self._get_list_extra_args()
# Map column index to column name
@z4y4ts
z4y4ts / app.py
Last active August 29, 2015 14:21 — forked from theskumar/app.py
# -*- coding: utf-8 -*-
''' Generates database schema graph from a relational database.
Usages:
Add database configuation in this file and then
python app.py
Note: You must have your latest database schema in the database
engine you are running against.
'''
from __future__ import unicode_literals, absolute_import
@z4y4ts
z4y4ts / gist:1691021
Created January 27, 2012 21:31
How to join tables on regex — performance test
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..6275.34 rows=882 width=163) (actual time=0.448..1058.363 rows=75615 loops=1)
Join Filter: (((msg.src_addr)::text ~~ (('380'::text || (mnc.code)::text) || '%'::text)) OR ((msg.dst_addr)::text ~~ (('380'::text || (mnc.code)::text) ||
-> Seq Scan on sms_mobilenetworkcode mnc (cost=0.00..1.18 rows=1 width=7) (actual time=0.014..0.042 rows=12 loops=1)
Filter: (length((code)::text) = 2)
-> Seq Scan on messages msg (cost=0.00..4064.76 rows=88376 width=159) (actual time=0.005..16.282 rows=88382 loops=12)
Total runtime: 1064.521 ms
(6 rows)
@z4y4ts
z4y4ts / .zshrc
Created April 28, 2012 14:27
Color prompt with time
# Prompt setup (c) smax 2002, adapted for zsh (c) piranha 2004
# 0-black, 1-red, 2-green, 3-yellow, 4-blue, 5-magenta 6-cyan, 7-white
Cr() { echo '%{\033[3'$1'm%}'; }
hc=`Cr 6`; wc=`Cr 3`; tc=`Cr 7`; w=`Cr 7`; n=`Cr 9`; r=`Cr 1`; y=`Cr 6`; gr=`Cr 2`
[ $UID = 0 ] && at=$r%B'#'%b || at=$w'@'
PW_LEN=25
PS1="$wc%n$at$hc%m $wc%$PW_LEN<..<%~$w>$n"
export RPROMPT=$(echo "$gr%T$n")
unset n b Cr uc hc wc tc tty at r y gr
@z4y4ts
z4y4ts / gist:3181380
Created July 26, 2012 10:23
OS X Mountain Lion virtualenvwrapper fix
Install XCode & Command Line Tools
curl -O http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py
sudo easy_install pip
sudo pip install virtualenvwrapper
@z4y4ts
z4y4ts / trace.sh
Last active October 12, 2015 20:58
web2py trace
function trace() {
local DEV_ROOT=~/dev/branch
local dir=$DEV_ROOT/booking/gui/applications/${1:-booking}/errors/
local ticket=`ls -1t ${dir} | head -1`
python -c "import cPickle as pickle; print pickle.load(open('${dir}/${ticket}', 'r')).get('traceback')"
}
@z4y4ts
z4y4ts / lucid-custom.css
Created June 16, 2013 22:08
WP Lucid theme tweaks
.home .thumb { display: none; }
.comment-reply-link {
background: url(/wp-content/themes/Lucid/images/more-arrow.png) no-repeat center right;
}
.article { padding: 14px; }
.post_content { padding: 36px 14px 30px 14px; }
#main-area .container { width: 1000px; }
#left-area { width: 670px; }
.flexslider img { width: 1000px; }
diff --git a/gluon/languages.py b/gluon/languages.py
--- a/gluon/languages.py
+++ b/gluon/languages.py
@@ -283,6 +283,7 @@
def write_plural_dict(filename, contents):
+ return
if '__corrupted__' in contents:
return
@z4y4ts
z4y4ts / cars.json
Created October 26, 2013 15:49
cars.json
[{"car_model": "Fiat Doblo",
"driver_name": "Vova Igorevich",
"location": "50.438263,30.526319",
"plate_id": "HT 8345 CT",
"status": "free",
"url": "/car/937"},
{"car_model": "Ford Mondeo",
"driver_name": "Vova Alexovich",
"location": "50.447320,30.457700",
"plate_id": "IP 0157 IK",