This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Don't try to be vi compatible | |
set nocompatible | |
" Helps force plugins to load correctly when it is turned back on below | |
filetype off | |
" TODO: Load plugins here (pathogen or vundle) | |
" Turn on syntax highlighting | |
syntax on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
unicode = unicode | |
except NameError: | |
# 'unicode' is undefined, must be Python 3 | |
str = str | |
unicode = str | |
bytes = bytes | |
basestring = (str, bytes) | |
else: | |
# 'unicode' exists, must be Python 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('input[type=checkbox]').map(function(){ | |
return $(this).val(); | |
}); | |
$('input[type=checkbox]:checked').map(function(){ | |
return $(this).val(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# According to: | |
# How To Set Up Python 2.7.6 and 3.3.3 on CentOS 6.4 | |
# https://www.digitalocean.com/community/tutorials/how-to-set-up-python-2-7-6-and-3-3-3-on-centos-6-4 | |
yum -y update | |
yum groupinstall -y 'development tools' | |
yum install -y zlib-dev openssl-devel sqlite-devel bzip2-devel | |
yum install xz-libs | |
wget http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CaselessDictionary(dict): | |
"""Dictionary that enables case insensitive searching while preserving case sensitivity | |
when keys are listed, ie, via keys() or items() methods. | |
Works by storing a lowercase version of the key as the new key and stores the original key-value | |
pair as the key's value (values become dictionaries).""" | |
def __init__(self, initval={}): | |
if isinstance(initval, dict): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Count, Max | |
unique_fields = ['field_1', 'field_2'] | |
duplicates = ( | |
MyModel.objects.values(*unique_fields) | |
.order_by() | |
.annotate(max_id=Max('id'), count_id=Count('id')) | |
.filter(count_id__gt=1) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# import re | |
from unicodedata import normalize | |
DIACRITICS_REPLACEMENTS = { | |
'a': 'àáâãäåæåāa', | |
'e': 'èéêëẽėęe', | |
'i': 'ìíîïĩīįi', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Assuming Linux Mint 18. Should also mostly work with Ubuntu 16.04 | |
## Installing .deb packages could be done in a single go if I added the | |
## necessary repositories beforehand but this way the script is more | |
## modular and I can comment out any sections if I want to. | |
## TODO: install Prey | |
## TODO: Rewrite this with Salt/Ansible? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo gpasswd -a plex plugdev | |
sudo gpasswd -a plex root | |
sudo gpasswd -a plex sudo | |
sudo gpasswd -a plex $(whoami) | |
sudo gpasswd -a $(whoami) plex | |
sudo service plexmediaserver restart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = { | |
title: 'fsdfsd', | |
titleZh: 'fsdfsd', | |
body: 'fsdf', | |
bodyZh: 'sdfsdf', | |
imageIds: '/uploads/tmp/image-3.png', | |
imageIdsZh: '' | |
}; | |
var z = Object.keys(data).filter(function(k) { |