Skip to content

Instantly share code, notes, and snippets.

View simark's full-sized avatar

Simon Marchi simark

  • Montréal, Canada
View GitHub Profile
@simark
simark / gist:ef475431a804cad220f2
Created November 17, 2014 06:06
stacktraces of threads in python
def stacktraces():
code = []
for threadId, stack in sys._current_frames().items():
code.append("\n# ThreadID: %s" % threadId)
for filename, lineno, name, line in traceback.extract_stack(stack):
code.append('File: "%s", line %d, in %s' %
(filename, lineno, name))
if line:
code.append(" %s" % (line.strip()))
@simark
simark / gist:61915d6b62715a10d084
Last active August 29, 2015 14:02
Global breakpoints comments
* Permissions and scope (system-global vs user-global)
Use case:
A user would like to debug its CGI web application written in C with
GDB. It is hosted on a shared server, where Apache runs as www-data.
When a request comes in, Apache forks, does some some suid magic to run
the CGI program as the user and the program finishes. It can be
difficult to debug this, since the user can't attach a debugger to
Apache. He can use the trick of putting a sleep or infinite loop in its
program, but that is always inconvenient.
@simark
simark / gist:9622857
Created March 18, 2014 15:50
Convertir descriptions de liste en utf-8
def iso_to_utf(m):
m.Lock()
try:
m.description.decode('utf-8')
except UnicodeDecodeError as e:
# La description n'est pas en utf-8, on la transforme.
m.description = m.description.decode('iso-8859-1').encode()
m.Save()
Les étapes entre le moment où on tappe "ls -1 *.txt" suivi de "enter" dans bash et le moment où on peut lire la liste des fichiers à l'écran. C'est très rapide, mais il s'en passe des choses...
$ ls -l undossier *.txt
-rw-rw-r-- 1 simark simark 0 Mar 9 22:17 bob.txt
-rw-rw-r-- 1 simark simark 0 Mar 9 22:17 machin.txt
-rw-rw-r-- 1 simark simark 0 Mar 9 22:17 truc.txt
undossier:
total 0
-rw-rw-r-- 1 simark simark 0 Mar 9 22:29 unfichier
@simark
simark / finishbp.py
Created January 21, 2014 21:41
GDB Python finish breakpoint bug reproduction
class EnterBreakpoint(gdb.Breakpoint):
def __init__(self):
super(EnterBreakpoint, self).__init__("hopefully_notinlined")
def stop(self):
FinishBp()
class FinishBp(gdb.FinishBreakpoint):
def stop(self):
print("I am here")
@simark
simark / gist:7946448
Last active December 31, 2015 06:19
Database update
// Enlever prix/quantités usagé
db.pieces.update({_id: {$exists: true}}, { $rename: {'prixneuf':'prix', 'quantiteneuf':'quantite'}, $unset: {'quantiteusage': true, 'prixusage': true} }, {multi: true})
// Trouver factures problématiques
db.factures.find({ 'pieces': {$elemMatch: { 'quantiteusage': {$exists: true}, 'quantiteneuf': {$exists: true} }} })
@simark
simark / _commands
Last active December 16, 2015 17:59
$ lttng create
$ lttng enable-event -u -a
$ lttng start
$ ./memcached
Generate some traffic. There are some printfs that indicate that both tracepoints should be hit.
$ lttng stop
$ lttng destroy