Skip to content

Instantly share code, notes, and snippets.

View AdrienLemaire's full-sized avatar

Adrien Lemaire AdrienLemaire

View GitHub Profile
@AdrienLemaire
AdrienLemaire / gist:945542
Created April 28, 2011 00:22
Performance counter decorator
def time_and_log(func):
"""
A decorator to call a function and log the time spent inside
Usage:
@time_and_log
somefunc(someargs):
pass
"""
@AdrienLemaire
AdrienLemaire / todo.sh
Created May 21, 2011 10:29
Find all the TODO in a django project which need to be fixed
# Find all the TODO in the code which need to be fixed
echo "Templates"
grep -Irn --include=*.html --exclude-dir="coverage_html" "TODO" *
echo -e '\nPython'
grep -Irn --include=*.py --exclude-dir="coverage_html"\
--exclude-dir="development-tools" "TODO" *
echo -e '\nOther'
@AdrienLemaire
AdrienLemaire / Questions
Created June 21, 2011 00:28
Kiwi Pycon Give-away
GitHub username: Fandekasp
Day job: Software Engineer
Favorite open source project: Python
Open Source contributions (if any): django-sphinx-autodoc, django-nuages (work in progress)
Stranded on an island, what 3 items do you take: swimsuit, laptop, wifi antenna
Tie-breaker, pick a number between 1 and 20,000: 15000
@AdrienLemaire
AdrienLemaire / fab_jip.py
Created August 1, 2011 13:27
Pip-like tool to keep js modules up to date from github
import os
from fabric.api import local, lcd
import default_settings as settings
class jip(object):
"""
Pip-like tool to manage all the static modules
@AdrienLemaire
AdrienLemaire / ftpplugintex.vim
Created September 21, 2011 12:56
Mupdf hack to open pdf directly to the (sub)*section you're editing from vim in Latex
" Function: OpenPdfToSection
function! OpenPdfToSection()
let g:my_section = substitute(getline(search('\\\(sub\)\?section', 'bn')), '\\\%(sub\)\?section{\([^}]\+\)}', '\1', '')
" some weird trailing space can appear, remove them
let g:my_section = substitute(g:my_section, "^ *", "", "g")
let g:Tex_ViewRuleComplete_pdf = 'mupdf -f "'.g:my_section.'" -r 102 $*.pdf'
call Tex_ViewLaTeX()
" reinitialize the variable to keep <leader>lv working
let g:Tex_ViewRuleComplete_pdf = 'mupdf -r 102 $*.pdf'
endfunction
@AdrienLemaire
AdrienLemaire / create_github_circle.py
Created October 3, 2011 06:49
Create a circle on Google+ for your github contacts
#!/usr/bin/env python
'''
File: create_github_circle.py
Author: Adrien Lemaire
Description: Generate a csv file for google+ using the github api 3
'''
import pycurl
import json
@AdrienLemaire
AdrienLemaire / fab_boto.py
Created October 19, 2011 03:50
Boto script
def restart_server(server_name=None):
"""Restart the server if needed (e.g. server down due to abusive cpu usage
by a program
how to use::
$ fab restart_server:serverName
List of available servers names:
@AdrienLemaire
AdrienLemaire / fab_coverage.py
Created October 19, 2011 06:04
fab coverage
""""
Required: fabric, django, coverage, django-coverage, termcolor
""""
from coverage.misc import CoverageException
from termcolor import colored
def coverage(html=1):
"""Run coverage tests with html output, or
or return only the coverage percentage::
@AdrienLemaire
AdrienLemaire / fabric.plugin.zsh
Created December 27, 2011 05:50
zsh-completion for Fabric in Oh-my-zsh
#compdef fab
_targets() {
_describe -t commands "fabric targets" target_list
}
output_levels=(
'status: Status messages, i.e. noting when Fabric is done running, if the user used a keyboard interrupt, or when servers are disconnected from. These messages are almost always relevant and rarely verbose.'
'aborts: Abort messages. Like status messages, these should really only be turned off when using Fabric as a library, and possibly not even then. Note that even if this output group is turned off, aborts will still occur – there just won’t be any output about why Fabric aborted!'
'warnings: Warning messages. These are often turned off when one expects a given operation to fail, such as when using grep to test existence of text in a file. If paired with setting env.warn_only to True, this can result in fully silent warnings when remote programs fail. As with aborts, this setting does not control actual warning behavior, only whether warning messages are printed or hidden.'
@AdrienLemaire
AdrienLemaire / notification_timer
Created August 25, 2014 05:32
notification_timer
#!/bin/bash
# Notification timer, to drop in ~/bin/
function timer () {
while [ "$(date "+%H:%M")" != "$exec_time" ]
do
sleep 60
done
notify-send -i dialog-warning "$title" "$message"