Skip to content

Instantly share code, notes, and snippets.

@julien-duponchelle
julien-duponchelle / semaphore.js
Created January 31, 2012 21:22 — forked from jayjanssen/semaphore.js
Node.js semaphores
var Semaphore = function(callback, context) {
this.semaphore = 0;
this.callback = callback;
this.context = context || this;
};
Semaphore.prototype.increment = function(i)
{
if (i == undefined) {
i = 1;
@julien-duponchelle
julien-duponchelle / backup.sh
Created February 27, 2012 16:09
Dotcloud backup to S3 improved
#!/bin/bash
#
# Improved version of http://docs.dotcloud.com/guides/backups/
#
HOSTNAME=`hostname`
TAG="${HOSTNAME}_$(TZ=UTC date +%Y-%m-%d_%H:%M:%S_UTC)"
[ "$3" ] || {
echo "Please specify what to backup, how, and where."
@julien-duponchelle
julien-duponchelle / oneiric
Created July 23, 2012 19:57
Support scratchbox for oneiric in debootstrap (/usr/share/debootstrap/scripts/oneiric)
case $ARCH in
amd64|i386)
default_mirror http://archive.ubuntu.com/ubuntu
;;
sparc)
case $SUITE in
gutsy)
default_mirror http://archive.ubuntu.com/ubuntu
;;
*)
function __rvm_prompt {
rvm-prompt ' ' i v g
}
function __color_prompt {
local G='\[\033[01;32m\]'
local B='\[\033[01;34m\]'
local W='\[\033[00m\]'
local R='\[\033[01;31m\]'
local Y='\[\033[01;33m\]'
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Dump all replication events from a remote mysql server
#
from pymysqlreplication import BinLogStreamReader
import gc
# inspired by http://ariejan.net/2010/08/23/resque-how-to-requeue-failed-jobs
# retry all failed Resque jobs except the ones that have already been retried
# This is, for instance, useful if you have already retried some jobs via the web interface.
Resque::Failure.count.times do |i|
Resque::Failure.requeue(i) unless Resque::Failure.all(i, 1)['retried_at'].present?
end
# retry all :)
Resque::Failure.count.times do |i|
#Use current directory as default search scope in Finder
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
#Show Path bar in Finder
defaults write com.apple.finder ShowPathbar -bool true
#Show Status bar in Finder
defaults write com.apple.finder ShowStatusBar -bool true
#Enable AirDrop over Ethernet and on unsupported Macs running Lion
@julien-duponchelle
julien-duponchelle / pre-commit
Last active September 6, 2016 11:07
Git PEP 8 pre commit hook
#!/bin/bash
echo "Pre-commit started"
echo "PEP 8"
git diff --cached --name-only | grep .py | grep -v old_ | xargs autopep8 --in-place -v --aggressive --aggressive
git diff --cached --name-only | grep .py | grep -v old_ | xargs git add
git diff --cached --name-only | grep .py | grep -v old_ | xargs pep8
if [ $? == 0 ]
@julien-duponchelle
julien-duponchelle / qt_migrate.py
Created April 17, 2015 15:01
QT4 to QT5 GNS3 migration
import os
import sys
import re
import inspect
from PyQt5 import QtWidgets
class FilePatcher:
def __init__(self, path):
self._path = path
self._line_number = 1
@julien-duponchelle
julien-duponchelle / upload_file_qt
Created April 29, 2015 20:10
Upload large file with Qt
from PyQt5 import QtCore,QtNetwork
import sys
app = QtCore.QCoreApplication(sys.argv)
f = QtCore.QFile("test.image")
url = QtCore.QUrl("http://localhost:8001/v1/dynamips/vms/test.image")