Skip to content

Instantly share code, notes, and snippets.

View edgabaldi's full-sized avatar
🏠
Working from home

Edgar Gabaldi edgabaldi

🏠
Working from home
View GitHub Profile
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
mplayer -vo xv tv:// -tv driver=v4l2:width=640:height=480:fps=30:device=/dev/video0
@edgabaldi
edgabaldi / mock_file_field.py
Created July 13, 2016 18:07
Mocking Django Filefiled
from django.core.files import File
s = SimpleModel()
s.audio_file = File(open("media/testfiles/testaudio.wav"))
s.save()
@edgabaldi
edgabaldi / json_serializer.py
Created December 11, 2015 01:34
JSON Serialize Example
>>> import json
>>> import datetime
>>> from django.core.serializers.json import DjangoJSONEncoder
>>> di = {'now': datetime.datetime.now()}
>>> json.dumps(di, cls=DjangoJSONEncoder)
'{"now": "2015-12-10T23:32:42.344"}'