Skip to content

Instantly share code, notes, and snippets.

@mirskiy
mirskiy / jdiff.sh
Created April 2, 2017 16:51
Diff json with vimdiff
# Add this to your .bashrc or .bash_aliases
jdiff() {
# Diff json files faster
# Uses python json.dump with sort_keys=True to fix ordering, then vimdiff
if [[ $# -ne 2 ]]; then
echo "syntax: jdiff file1 file2"
return
fi
@mirskiy
mirskiy / django.py
Created September 28, 2016 21:09
django tricks
# model new insance or update
# http://stackoverflow.com/a/35647389
self._state.adding == True creating
self._state.adding == False updating
@mirskiy
mirskiy / RelatedFieldListFilter.txt
Last active August 20, 2020 23:31
RelatedFieldListFilter vs RelatedOnlyFieldListFilter
from the source:
class RelatedOnlyFieldListFilter(RelatedFieldListFilter):
def field_choices(self, field, request, model_admin):
pk_qs = model_admin.get_queryset(request).distinct().values_list('%s__pk' % self.field_path, flat=True)
return field.get_choices(include_blank=False, limit_choices_to={'pk__in': pk_qs})
ex if:
class Author(models.Model):
country = models.ForeignKey('Country')
@mirskiy
mirskiy / tmux_install.sh
Last active December 26, 2018 06:37
Install tmux 2.2 on Ubuntu 14.04 from source
sudo apt-get update
sudo apt-get install -y libevent-dev libncurses-dev make
wget https://github.com/tmux/tmux/releases/download/2.2/tmux-2.2.tar.gz
tar xvzf tmux-2.2.tar.gz
cd tmux-2.2/
./configure && make
sudo make install
@mirskiy
mirskiy / tmux
Last active March 21, 2016 02:08
tmux
# detach others
<prefix> D
# resize
<prefix> :resize[-pane] -(U|D|R|L) [numCells]
@mirskiy
mirskiy / system.sh
Last active March 21, 2016 02:04
system
1996 sudo hciconfig hci0 up
1997 sudo hidd --connect 00:22:48:86:E6:CA
@mirskiy
mirskiy / cmd.sh
Last active November 17, 2016 16:20
commanding lines
## history
# Quick substitution. Repeat the last command, replacing string1 with string2. Equivalent to ``!!:s/string1/string2/'' (see Modifiers below).
^string1^string2^
# Swap usage
vmstat
# display in hex
echo 'test' | hd