Skip to content

Instantly share code, notes, and snippets.

View mdogo's full-sized avatar

Manuel Dominguez mdogo

  • Doofinder
  • Madrid, Spain
View GitHub Profile
@mdogo
mdogo / dynamic_cast.py
Created February 13, 2013 19:19
Dynamic casting of basic types on Python
getattr(__builtin__, type_of)(value)
# Where type_of is a string with the casting type and value the value to cast
@mdogo
mdogo / serializers.py
Created July 1, 2014 09:55
Flat serializer for Django-rest-framework
class UserProfileSerializer(serializer.ModelSerializer):
class Meta:
model = UserProfile
fields = ['profile_info']
class UserSerializer(serializer.ModelSerializer):
profile_info = serializers.CharField(source='profile.profile_info')
class Meta:
model = User
import time
from pycallgraph import Config, GlobbingFilter, PyCallGraph
from pycallgraph.output import GraphvizOutput
from django.conf import settings
class CallgraphMiddleware(object):
def process_view(self, request, callback, callback_args, callback_kwargs):
if settings.DEBUG and 'graph' in request.GET:
config = Config(
@mdogo
mdogo / .bashrc
Last active August 29, 2015 14:07
A bash recipe to mantain your config organized.
# [...]
# Instead of adding a lot of changes to my .bashrc files I split
# those changes in small files and put those files in a .bash directory.
if [ -d ~/.bash/ ]; then
for script in ~/.bash/*; do
if [ -f $script ]; then
. "$script"
fi
done
@mdogo
mdogo / fibonacci_itertools.md
Last active October 22, 2022 12:10
Itertools examples with Fibonacci Sequence

By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. The recursive definition of the fibonacci number in Python is:

def fiboncci(n):
    if n == 0:
      return 0
    elif n == 1:
      return 1
 else
@mdogo
mdogo / git_stats.sh
Created October 16, 2014 14:58
GIT Repo stats
git log --author="<author_name>" --pretty=tformat: --numstat | \
gawk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END \
{ printf "added lines: %s removed lines: %s total lines: %s\n",add,subs,loc }' -
@mdogo
mdogo / 0_reuse_code.js
Created October 21, 2015 08:32
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console