Skip to content

Instantly share code, notes, and snippets.

@victorono
victorono / .vimrc
Created January 23, 2017 20:46 — forked from simonista/.vimrc
A basic .vimrc file that will serve as a good template on which to build.
" 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
@victorono
victorono / py2_py3.py
Created January 16, 2017 15:51
python 3 unicode migration
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
@victorono
victorono / check_all.js
Created December 27, 2016 21:06
jQuery mark all input checkbox
$('input[type=checkbox]').map(function(){
return $(this).val();
});
$('input[type=checkbox]:checked').map(function(){
return $(this).val();
});
@victorono
victorono / centos_python.sh
Created December 19, 2016 20:38 — forked from selfboot/centos_python.sh
CentOS 6.8: Install Python 2.7.10, pip, virtualenv, and virtualenvwrapper on CentOS
#!/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
@victorono
victorono / caseless.py
Created December 13, 2016 22:16
This case-insensitive option parser relies on having a case-insensitive dictionary type available
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):
@victorono
victorono / remove_duplicates.py
Last active April 26, 2024 17:57
Django - remove duplicate objects where there is more than one field to compare
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)
)
@victorono
victorono / string_util.py
Created December 7, 2016 01:25
returns a string with accent to REGEX expression to find any combinations in accent insentive way
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# import re
from unicodedata import normalize
DIACRITICS_REPLACEMENTS = {
'a': 'àáâãäåæåāa',
'e': 'èéêëẽėęe',
'i': 'ìíîïĩīįi',
@victorono
victorono / new_ubuntu.sh
Created October 24, 2016 13:45 — forked from borfast/new_linux.sh
A script to automatically install as much software as possible for my Ubuntu/Linux Mint development workstation
#!/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?
@victorono
victorono / fix_permissions_plex.sh
Last active July 14, 2020 03:12
plex permissions to access partition mount
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
@victorono
victorono / object_filter.js
Created October 20, 2016 20:04
Some minor explanation: - We use Array.prototype.filter() function to filter out the keys that start with `imageIds2 - We use Array.prototype.reduce() to convert an array of filtered keys into an object of key-value pairs. For that we use the initial value of {} (an empty object), fill it and return from every execution step.
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) {