Skip to content

Instantly share code, notes, and snippets.

View edgabaldi's full-sized avatar

Edgar Gabaldi edgabaldi

View GitHub Profile
@edgabaldi
edgabaldi / group_by.js
Created December 8, 2018 10:31
groupBy ES6
const groupBy = (xs, key) => {
return xs.reduce( (rv, x) => {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
console.log(groupBy(['one', 'two', 'three'], 'length'));
// => {3: ["one", "two"], 5: ["three"]}
@edgabaldi
edgabaldi / print_permissions.py
Last active October 26, 2018 16:25
print permissions from group in django
def print_permissions_from(group):
return [p.codename for p in group.permissions.all()]
@edgabaldi
edgabaldi / fix_permissions.py
Created October 19, 2018 12:42
Cria Permissão para model proxy no django 1.6
from __future__ import unicode_literals, absolute_import, division
import sys
from django.db.models import get_models
from django.contrib.auth.management import _get_all_permissions
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentTyped
from django.utils.encoding import smart_text
from django.utils.crypto import get_random_string
hash_key = get_random_string(length=8)
function my_beautful_ps1 {
local __path="\[\033[38;5;8m\][\w]\[$(tput sgr0)\]\[\033[38;5;15m\]"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
local __end_prompt="\[$(tput sgr0)\]\[\033[38;5;202m\]>\[$(tput sgr0)\]"
export PS1="$__path $__git_branch$__end_prompt "
}
my_beautful_ps1
function my_beautful_ps1 {
local __path="\[\033[38;5;8m\][\w]\[$(tput sgr0)\]\[\033[38;5;15m\]"
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
local __end_prompt="\[$(tput sgr0)\]\[\033[38;5;202m\]>\[$(tput sgr0)\]"
export PS1="$__path $__git_branch$__end_prompt "
}
my_beautful_ps1
from unittest import TestCase
import datetime
def d2t(t):
h = int(t)
m = (t * 60) % 60
s = (t * 3600) % 60
a = map(lambda x: int(x), [h, m, s])
return datetime.time(*a)
@edgabaldi
edgabaldi / something.py
Created December 6, 2016 16:26
python is so cool
"""
Before
"""
def something(self, is_closed, is_out_of_time):
if is_closed:
return True
if not is_closed and is_out_of_time:
return True
return False
def _setup_changelist_queryset(self, params):
request = self.factory.get("/", params)
changelist = self._get_changelist(request, model, ma)
return changelist.get_query_set(request)
def _get_changelist(self, request, model, ma):
args = self._get_changelist_args(request, Leilao, self.ma)
return ChangeList(*args)
def _get_changelist_args(self, request, model, ma):
@edgabaldi
edgabaldi / gist:f584a0bab637d8263fea908326cb7664
Last active November 14, 2016 16:54
BASH Shell: For Loop File Names With Spaces
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in $(ls | grep -v git | grep -v salvar_documentos.py | grep -v dt18)
do
mv $f dt18/
done
IFS=$SAVEIFS