Skip to content

Instantly share code, notes, and snippets.

View blaxter's full-sized avatar

Jesús García Sáez blaxter

  • Zaragoza, Spain
View GitHub Profile
@blaxter
blaxter / rsync nonstop
Last active August 29, 2015 14:02
sync files one way
# sudo aptitude install inotify-tools
[email protected]
SOURCE=source_dir
TARGET=target_dir
while inotifywait -r $SOURCE ; do
rsync -avz $SOURCE $DEST:$TARGET
done
@blaxter
blaxter / punch
Last active August 29, 2015 14:01
puncher for internal Zentyal timetracker
#!/usr/bin/env python
import keyring
import re
import os
import sys
import requests
import configobj
import getpass
@blaxter
blaxter / Vagrantfile
Created March 27, 2014 16:45
openchange cloud vagrant
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.module_path = "puppet/modules"
puppet.manifest_file = "site.pp"
puppet.options = "--verbose --debug"
end
@blaxter
blaxter / singleapp.py
Created April 18, 2013 15:13
PySide QSingleApplication
class QSingleApplication(QApplication):
def single_start(self, widget):
self.widget = widget
self.local_socket = QLocalSocket()
self.local_socket.connected.connect(self.another_instance_started)
self.local_socket.error.connect(self.first_instance)
self.local_socket.connectToServer("foobar", QIODevice.WriteOnly)
def another_instance_started(self):
self.local_socket.write("foobar")
@blaxter
blaxter / standup
Last active December 15, 2015 22:49
standup
function yesterworkday()
{
if [[ "Mon" == "$(date +%a)" ]]
then
echo "last friday"
else
echo "yesterday"
fi
}
@blaxter
blaxter / pr.md
Created March 26, 2013 00:35 — forked from piscisaureus/pr.md
Pull request locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@blaxter
blaxter / log_decorator.py
Last active December 14, 2015 04:48
log method decorator
import logging
def log_method(fun):
"""
Example output (it will depend of you logging setup, obviously):
2013-02-25 16:13:58+0100 [-] DEBUG:root:--> Foo.update_bar
2013-02-25 16:13:58+0100 [-] DEBUG:root:<-- Foo.update_bar (0.052)
"""
def with_logging(self, *args, **kwargs):
method_name = '%s.%s' % (self.__class__.__name__, fun.__name__)
@blaxter
blaxter / pymodules.py
Created January 24, 2013 17:25
Create symlinks for python modules installed in /usr/share/pyshared in /usr/lib/pymodules/python2.7/
import os
def touch(fname, times=None):
with file(fname, 'a'):
os.utime(fname, times)
def create_pyshare_symlinks(package):
base_subdir = '/'.join(package.split('.'))
base_from = '/usr/share/pyshared/' + base_subdir
base_to = '/usr/lib/pymodules/python2.7/' + base_subdir
@blaxter
blaxter / retry decorator
Created December 12, 2012 20:09
retry decorator for python like the ruby one
class retry(bject):
"""
Decorator to retry function calls in case they raise exceptions
times - retries times (0 means only called once, like this decorator was
not used at all)
sleep - sleep time to wait aftera failure
debug - whether print to stdout info or not
"""
def __init__(self, times=1, sleep=0, debug=False):
self.times = times
@blaxter
blaxter / nmea
Created July 17, 2012 15:17
Nmea info
=== GGA - Global Positioning System Fix Data ===
Time, Position and fix related data for a GPS receiver.
------------------------------------------------------------------------------
11
1 2 3 4 5 6 7 8 9 10 | 12 13 14 15
| | | | | | | | | | | | | | |
$--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh<CR><LF>
------------------------------------------------------------------------------