Skip to content

Instantly share code, notes, and snippets.

View davidfischer-ch's full-sized avatar

David Fischer davidfischer-ch

View GitHub Profile
@brantfaircloth
brantfaircloth / cool_argparse_stuff.py
Created December 7, 2011 16:47
Some cool argparse stuff
class FullPaths(argparse.Action):
"""Expand user- and relative-paths"""
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values)))
def is_dir(dirname):
"""Checks if a path is an actual directory"""
if not os.path.isdir(dirname):
msg = "{0} is not a directory".format(dirname)
raise argparse.ArgumentTypeError(msg)
@fabiomontefuscolo
fabiomontefuscolo / models.py
Created January 9, 2012 19:20
Let the Django FileField overwrite files with the same name
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.db import models
class OverwriteStorage(FileSystemStorage):
'''
Muda o comportamento padrão do Django e o faz sobrescrever arquivos de
mesmo nome que foram carregados pelo usuário ao invés de renomeá-los.
'''
@fny
fny / jquery.regex-selector.js
Created February 22, 2012 21:22
Regex Selector for jQuery - James Padolsey
jQuery.expr[':'].regex = function(elem, index, match) {
var matchParams = match[3].split(','),
validLabels = /^(data|css):/,
attr = {
method: matchParams[0].match(validLabels) ?
matchParams[0].split(':')[0] : 'attr',
property: matchParams.shift().replace(validLabels,'')
},
regexFlags = 'ig',
regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
@ramnathv
ramnathv / gh-pages.md
Created March 28, 2012 15:37
Creating a clean gh-pages branch

Creating a clean gh-pages branch

This is the sequence of steps to follow to create a root gh-pages branch. It is based on a question at [SO]

cd /path/to/repo-name
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" > index.html
@willurd
willurd / web-servers.md
Last active April 28, 2024 21:38
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@ragingwind
ragingwind / Backend Architectures Keywords and References.md
Last active April 17, 2024 10:51
Backend Architectures Keywords and References
@arunoda
arunoda / gist:7790979
Last active February 16, 2024 14:05
Installing SSHPass

Installing SSHPASS

SSHPass is a tiny utility, which allows you to provide the ssh password without using the prompt. This will very helpful for scripting. SSHPass is not good to use in multi-user environment. If you use SSHPass on your development machine, it don't do anything evil.

Installing on Ubuntu

apt-get install sshpass

Installing on OS X

@yahyaKacem
yahyaKacem / string_converter.py
Created December 29, 2013 13:51
Convert camel-case to snake-case in python. e.g.: CamelCase -> snake_case e.g.: snake_case -> CamelCase e.g.: CamelCase -> dash-case e.g.: dash-case -> CamelCase By: Jay Taylor [@jtaylor] Me<modifier>: Yahya Kacem <fuj.tyoli@gmail.com> Original gist: https://gist.github.com/jaytaylor/3660565
#!/usr/bin/env python
"""
Convert camel-case to snake-case in python.
e.g.: CamelCase -> snake_case
e.g.: snake_case -> CamelCase
e.g.: CamelCase -> dash-case
e.g.: dash-case -> CamelCase
By: Jay Taylor [@jtaylor]
Me<modifier>: Yahya Kacem <fuj.tyoli@gmail.com>
Original gist: https://gist.github.com/jaytaylor/3660565
from rest_framework import serializers
class HyperlinkedIdentityField(serializers.HyperlinkedIdentityField):
"""
This is a performance wrapper for HyperlinkedIdentityField.
We save a ton of time by not calling reverse potentially
thousands of times per request.
"""
def __init__(self, *args, **kwargs):
@dbrgn
dbrgn / mixins.py
Last active September 13, 2018 20:44
Moved to https://github.com/dbrgn/drf-dynamic-fields