Skip to content

Instantly share code, notes, and snippets.

@pendolf
pendolf / gitignore.md
Created July 19, 2016 10:36 — forked from nepsilon/gitignore.md
Understand what .gitignore rule is ignoring your files — First published in fullweb.io issue #54

Understand what .gitignore rule is ignoring your files

Ready to commit, you fire your git status and you don’t see your files 🤔.

Use this command to ask Git what rule is causing this ignore:

$ git check-ignore -v filename

For instance to see what rule ignores tests.pyc:

@pendolf
pendolf / git-change-commit-messages.md
Created July 19, 2016 10:21 — forked from nepsilon/git-change-commit-messages.md
How to change your commit messages in Git? — First published in fullweb.io issue #55

How to change your commit messages in Git?

At some point you’ll find yourself in a situation where you need edit a commit message. That commit might already be pushed or not, be the most recent or burried below 10 other commits, but fear not, git has your back 🙂.

Not pushed + most recent commit:

git commit --amend

This will open your $EDITOR and let you change the message. Continue with your usual git push origin master.

@pendolf
pendolf / better-flow-control.py
Created June 9, 2016 13:23 — forked from nepsilon/python-better-flow-control.md
Better Flow Control with Python
try:
# What you want to do, which might
# very well raise an exception
except IndexError as ex:
# What do to when IndexError is raised
except MyModule.itsException as ex:
# What do to when MyModule raised an exception
except Exception as ex:
# What do to when any other Exception is raised
else:
@pendolf
pendolf / .gitconfig
Created June 9, 2016 13:21 — forked from nepsilon/a-better-setup-for-git.md
A better setup for Git
# The basics, who you commit as:
[user]
name = John Doe
email = john@doe.org
# Your Github username
[github]
user = githubusername
# Some aliases to save 1000s keystrokes each year:
[alias]
log = log --color
@pendolf
pendolf / python-timeit.py
Created June 9, 2016 13:20 — forked from nepsilon/python-timeit.md
A simple way to benchmark your code in Python
import random
def sort_rand():
random.seed('pouet')
pool = [random.random() for i in range(1000)]
sorted_pool = sorted(pool)
return sorted_pool
if __name__ == "__main__":
sorted_nb = sort_rand()
@pendolf
pendolf / cron-tips.sh
Created June 9, 2016 13:20 — forked from nepsilon/cron-tips.md
Better using Cron
# Cron only provides a limited environment.
# To simulate it to test run your scripts
# first add this to your cron:
* * * * * env > ~/cronenv
# This will export the limited cron environment to a file.
# Now launch a new shell using this file to test your scripts:
$ env - `cat ~/cronenv` /bin/sh
# Tell it what email to send output to:
# (You need to install Postfix locally before)
@pendolf
pendolf / bobp-python.md
Created November 20, 2015 05:04 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@pendolf
pendolf / django_testing_view_decorators.py
Last active September 22, 2015 07:31 — forked from benoitbryon/django_testing_view_decorators.py
Sample code to illustrate a blog post about testing view decorators in Django apps.
"""Testing Django view decorators.
This code was originally published as part of an article at
http://tech.novapost.fr/django-testing-view-decorators-en.html
To run this file:
.. code-block:: sh
virtualenv --distribute --no-site-packages testing
@pendolf
pendolf / fabfile.py
Last active September 3, 2015 06:46 — forked from onyxfish/fabfile.py
Chicago Tribune News Applications fabric deployment script
from fabric.api import *
"""
Base configuration
"""
env.project_name = '$(project)'
env.database_password = '$(db_password)'
env.site_media_prefix = "site_media"
env.admin_media_prefix = "admin_media"
env.newsapps_media_prefix = "na_media"
// This function gets cookie with a given name
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));