Skip to content

Instantly share code, notes, and snippets.

View malexandre's full-sized avatar

Marc Alexandre malexandre

View GitHub Profile
@malexandre
malexandre / Rakefile
Created October 22, 2012 15:07
Rakefile for Jekyll with draft & publish management
require 'date'
desc "Given a title as an argument, create a new post file"
task :draft, :title do |t, args|
puts "Creating _drafts/#{args.title}"
filename = "#{args.title.gsub(/\s/, '_').downcase}.markdown"
path = File.join("_drafts", filename)
if File.exist? path; raise RuntimeError.new("Won't clobber #{path}"); end
File.open(path, 'w') do |file|
file.write <<-EOS
@malexandre
malexandre / gist:3934578
Created October 22, 2012 21:34
Bash function for Jekyll to create drafts & publish them
function draft()
{
local editor=""
local title=""
while test $# -gt 0; do
case "$1" in
-c)
editor="$2"
shift
shift
@malexandre
malexandre / Main.sublim-menu
Created April 17, 2014 10:03
Config file to add custom 3 pane mode in sublime text 3, with one pane large as the 2 other pane combined. Put this file in .config/sublime-text-3/Packages/User.
[{
"id": "view",
"children": [{
"id": "layout",
"children": [
{
"command": "set_layout",
"caption" : "Custom: 3 Pane (2T 1B)",
"mnemonic": "C",
"args": {
@malexandre
malexandre / gist:10994396
Last active August 29, 2015 13:59
Exécution des tests en Python

Pour exécuter des tests en Python à partir de la console, il faut utiliser nosetests. Nosetests est dispo sur les dépots Python avec son plugins Google AppEngine :

sudo pip install nose nosegae

Il faut ensuite appeler la bonne ligne de commande. Pour se faire, voici une fonction bash à mettre dans son ~/.bashrc :

function gae-test()
{
@malexandre
malexandre / Side Bar.sublime-menu
Created May 15, 2014 13:02
Opening file path in terminal from ST3 (path = /home/marc/.config/sublime-text-3/Packages/User/SideBarEnhancements/Open With/)
[
{"id": "side-bar-files-open-with",
"children":
[
{
"caption": "Chrome",
"id": "side-bar-files-open-with-chrome",
"command": "side_bar_files_open_with",
"args": {
@malexandre
malexandre / .gitconfing
Created November 5, 2014 08:26
Git aliases
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
eu = "!f() { git diff --name-status --diff-filter=U | cut -f2 ; }; subl `f`"
au = "!f() { git diff --name-status --diff-filter=U | cut -f2 ; }; git add `f`"
pop = !sh -c 'git stash pop'
ro = "!git stash; git rebase origin/$1; git pop"
reb = "!git fetch; git ro $1"
mp = "!git stash; git checkout $1; git merge @{-1}; git push origin $1; git checkout @{-1}; git pop"
rmp = "!git reb $1; git mp $1"
@malexandre
malexandre / .bashrc
Created November 5, 2014 08:39
Bash prompt with git information (example: `[6@pts] 09:38:52 marc ~/git/gitg [>master|-0|+0]` (with color))
function promptGit()
{
if [[ -d ./.git ]]; then
local change_waiting_commit=`if git status | grep -q "nothing to commit (working directory clean)"; then echo ""; else echo ">"; fi`
local current_branch=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`
local commits_behind=`git rev-list --left-right $current_branch...origin/master | grep -c "^>"`
local commits_ahead=`git rev-list --left-right $current_branch...origin/master | grep -c "^<"`
echo " [$change_waiting_commit$current_branch|-$commits_behind|+$commits_ahead]"
fi
}
@malexandre
malexandre / copyList.js
Created December 18, 2014 17:03
Copy an array into another that already exists (like 'dest = src;', except that it keeps the reference to the existing array)
function copyArray(src, dest)
{
// (performance: http://jsperf.com/empty-javascript-array & http://jsperf.com/array-extending-push-vs-concat)
while(dest.length > 0)
{
dest.pop();
}
if (src)
{
for (var i = 0; i < src.length; ++i)
@malexandre
malexandre / xls-to-xlsx-conversion.py
Last active October 28, 2021 18:58
Convert xls file to xlsx in python
import xlrd
from openpyxl.workbook import Workbook as openpyxlWorkbook
# content is a string containing the file. For example the result of an http.request(url).
# You can also use a filepath by calling "xlrd.open_workbook(filepath)".
xlsBook = xlrd.open_workbook(file_contents=content)
workbook = openpyxlWorkbook()
for i in xrange(0, xlsBook.nsheets):