Skip to content

Instantly share code, notes, and snippets.

View hansek's full-sized avatar

Jan Tezner hansek

  • Prague, Czech Republic
View GitHub Profile
@hansek
hansek / models.py
Created March 24, 2017 12:15
Allow to define abstract class and don't hardcode upload_to path for each FileField
from django.db import models
class BaseFileField(models.FileField):
"""
Allow to define abstract class and don't hardcode upload_to path for each FileField
class BaseFile(models.Model):
name = models.CharField(
@hansek
hansek / models.py
Created March 16, 2017 09:10
Django File mixin to automatically folderize uploaded file by app label and ID
from django.db import models
class FileAppIdFolderMixin(models.Model):
def upload_to(self, filename):
return '{app}/{id}/{filename}'.format(
app=self._meta.app_label,
id=self.id,
filename=filename
# Bash-it theme inspired by theme "Sexy" and "Bobby" themes
# https://gist.github.com/hansek
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
if [ -t 1 ]; then
# Bash-it theme based on Solarized colors
# https://gist.github.com/hansek
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
# Solarized
# Hansek Bash Prompt, inspired by theme "Sexy" and "Bobby"
# thanks to them
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
if tput setaf 1 &> /dev/null; then
@hansek
hansek / atLeastOneOf
Last active August 29, 2015 14:22
atLeastOneOf - MODX FormIt Hook : at least one of validated field have to be correct
<?php
/**
* atLeastOneOf
*
* Custom MODX FormIt hook to check if at least one of defined field is correctly filled
*
* !!! To proper work have to be set on last validate field (phone in example)
*
* Usage example:
* &customValidators=`atLeastOneOf`
@hansek
hansek / rsync.sh
Created September 25, 2014 09:26
Script to easily manage Rsync settings to sync project media
#!/bin/bash
# check if config file exists
if [ ! -f $(dirname "$0")/rsync_config.sh ]; then
echo -e "\e[41mERROR:\e[0m Config file not found!"
exit 1
fi
# include config file
source $(dirname "$0")/rsync_config.sh
@hansek
hansek / modx_cache_disabler.sql
Created September 17, 2014 12:49
SQL to disable caching in MODX Revolution for Development purpose
-- disable all cache options
UPDATE `modx_system_settings` SET value = 0
WHERE `area` = 'caching' AND `xtype` = 'combo-boolean';
-- reactivate cache_disabled :)
UPDATE `modx_system_settings` SET value = 1
WHERE `key` = 'cache_disabled';
-- disable compress JS and CSS
UPDATE `modx_system_settings` SET value = 0
@hansek
hansek / gist:8594678
Created January 24, 2014 09:47
Presta - cross selling - orders
SELECT o.id_order
FROM ps_orders o
LEFT JOIN ps_order_detail od ON (od.id_order = o.id_order)
WHERE o.valid = 1
AND od.product_id = 991
@hansek
hansek / gist:8594656
Created January 24, 2014 09:45
Presta - cross selling - products
SELECT od.product_id,
pl.name,
pl.link_rewrite,
p.reference,
i.id_image,
product_shop.show_price,
cl.link_rewrite category,
p.ean13,
COUNT(*) AS product_count
FROM ps_order_detail od