Skip to content

Instantly share code, notes, and snippets.

@victorono
victorono / .bashrc
Created May 30, 2015 18:40
Applying Kwin Blur to Transparent Konsole/Yakuake Windows
konsolex=$(qdbus | grep konsole | cut -f 2 -d\ )
if [ -n konsolex ]; then
for konsole in $konsolex
do
xprop -f _KDE_NET_WM_BLUR_BEHIND_REGION 32c -set _KDE_NET_WM_BLUR_BEHIND_REGION 0 -id `qdbus $konsole /konsole/MainWindow_1 winId`;
done
fi
if [ `qdbus | grep yakuake` ]; then
xprop -f _KDE_NET_WM_BLUR_BEHIND_REGION 32c -set _KDE_NET_WM_BLUR_BEHIND_REGION 0 -name Yakuake;
fi
@victorono
victorono / split.js
Created May 13, 2015 19:45
Override Internet Explorer implementation of String.split
/*
* String.split(delimiter,limit)
* Override Internet Explorer implementation of String.split to handle regular
* expression capture groups in the same manner as all other browsers. Each
* capture group in the matched text will be included in the split array.
*/
if("a'b".split(/(')/g).length==2){
String.prototype.split = function(delimiter/*,limit*/){
if(typeof(delimiter)=="undefined"){
return [this];
@victorono
victorono / highlight.py
Created April 6, 2015 14:24
highlight.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django import template
from django.utils.safestring import mark_safe
import re
register = template.Library()
@register.filter(name='highlight')
@victorono
victorono / forms.py
Created November 24, 2014 03:19
Django forms: default value if user leaves field blank
class YourForm(forms.Form):
...
def clean_field(self):
data = self.cleaned_data['field']
if not data:
data = self.instance.field
return data
@victorono
victorono / .bashrc
Created November 24, 2014 03:17
My bashrc promt
export PS1="\[$(tput bold)\]\[$(tput setaf 4)\][\[$(tput setaf 6)\]\u\[$(tput setaf 6)\]@\[$(tput setaf 6)\]\h \[$(tput setaf 1)\]\W\[$(tput setaf 4)\]]\\$ \[$(tput sgr0)\]"
@victorono
victorono / gist:8813af2b1dcdbe1f92c3
Last active August 29, 2015 14:07
Using a local cache for pip packages
# edit your .bashrc
nano ${HOME}/.bashrc
if [ ! -d "${HOME}/.pip-packages" ]; then
mkdir ${HOME}/.pip-packages
fi
alias pipcache='pip install --download ${HOME}/.pip-packages'
alias pipinstall='pip install --no-index --find-links=file://${HOME}/.pip-packages/'
from django.db import models
class Person(models.Model):
_first_name = models.CharField(max_length=30, db_column='first_name')
last_name = models.CharField(max_length=30)
@property
def first_name(self):
"""your logic here, return value"""
return "foo"
@victorono
victorono / site_detection.py
Created September 10, 2014 01:37
Detect domain and set id
class SiteDetectionMiddleware:
def process_request(self, request):
settings.SITE_ID = 1
host = request.META.get('HTTP_HOST')
if host:
try:
site = Site.objects.get(domain=host)
settings.SITE_ID = site.id
@victorono
victorono / lazy_carousel.js
Created August 5, 2014 15:46
Lazy load bootstrap carousel images
@victorono
victorono / is_mobile.js
Created July 31, 2014 19:26
check is mobile with javascript
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},