Skip to content

Instantly share code, notes, and snippets.

View chergert's full-sized avatar
💭
I'm on GitLab https://gitlab.gnome.org/chergert

Christian Hergert chergert

💭
I'm on GitLab https://gitlab.gnome.org/chergert
View GitHub Profile
@chergert
chergert / pre-commit
Created November 2, 2012 21:43
Run GLib unit tests before commit! (.git/hooks/pre-commit)
#!/usr/bin/env bash
make test
code=$?
if [ "$code" == "0" ]; then
exit 0
fi
echo -n "Not all tests pass. Commit (y/n): "
@chergert
chergert / mongo.js
Created October 31, 2012 08:23
make your own mongo server with javascript ... if thats your thing
/*
* Requires mongo-glib from master and gobject-introspection. Run with gjs.
*/
let Mongo = imports.gi.Mongo;
let MainLoop = imports.mainloop;
let Server = new Mongo.Server();
/* Listen on 27017 */
Server.add_inet_port(27017, null, null);
@chergert
chergert / dropline-status-icon.c
Created October 24, 2012 00:41
example for status icon
#include "dropline-status-icon.h"
G_DEFINE_TYPE(DroplineStatusIcon, dropline_status_icon, GTK_TYPE_STATUS_ICON)
struct _DroplineStatusIconPrivate
{
/*
* XXX: Put stuff you need during runtime here.
*/
gpointer dummy;
@chergert
chergert / oidtest.c
Created October 19, 2012 21:36
convert 96-bit bson object id to 24 character string plus NUL byte.
static void
OidToString4(const guint8 *id, /* IN */
gchar *idstr) /* OUT */
{
static const guint16 hex[] = {
#if G_BYTE_ORDER == G_BIG_ENDIAN
12336, 12337, 12338, 12339, 12340, 12341, 12342, 12343, 12344, 12345, 12385, 12386, 12387, 12388, 12389, 12390, 12592, 12593, 12594, 12595, 12596, 12597, 12598, 12599, 12600, 12601, 12641, 12642, 12643, 12644, 12645, 12646, 12848, 12849, 12850, 12851, 12852, 12853, 12854, 12855, 12856, 12857, 12897, 12898, 12899, 12900, 12901, 12902, 13104, 13105, 13106, 13107, 13108, 13109, 13110, 13111, 13112, 13113, 13153, 13154, 13155, 13156, 13157, 13158, 13360, 13361, 13362, 13363, 13364, 13365, 13366, 13367, 13368, 13369, 13409, 13410, 13411, 13412, 13413, 13414, 13616, 13617, 13618, 13619, 13620, 13621, 13622, 13623, 13624, 13625, 13665, 13666, 13667, 13668, 13669, 13670, 13872, 13873, 13874, 13875, 13876, 13877, 13878, 13879, 13880, 13881, 13921, 13922, 13923, 13924, 13925, 13926, 14128, 14129, 14130, 14131, 14132, 14133, 14134, 14135, 14136, 14137, 14
@chergert
chergert / uber-pixring.c
Created September 4, 2012 21:12
pixmap ring buffer
/* uber-pixring.c
*
* Copyright (C) 2012 Christian Hergert <chris@dronelabs.com>
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
@chergert
chergert / watch_for_androids.c
Created August 15, 2012 07:12
Listen via udev for android devices or nokia n9.
#include <gudev/gudev.h>
#include <string.h>
static gboolean
looks_like_android (GUdevDevice *device)
{
const gchar *model;
gboolean ret = FALSE;
gchar *lower;
@chergert
chergert / mongoserver.py
Created July 26, 2012 21:30
Just enough of a mongoserver to handle a mongo shell connecting.
#!/usr/bin/env python
"""
A sample Mongo server that handles enough of the commands to connect
with the mongo shell.
Requires: https://github.com/chergert/mongo-async-python-driver
"""
from collections import OrderedDict
@chergert
chergert / serial.c
Created July 22, 2012 20:36
opening a serial port for r/w
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
int
open_port (void)
@chergert
chergert / mongo_bad_utf8_insert.py
Created February 15, 2012 22:49
fun times with mongo utf8
#!/usr/bin/env python
#
# This is an example showing that Mongo performs no UTF-8 validation on
# documents inserted into your collection. This is unfortunate, in that if
# you want that feature, you should juse use the binary type.
#
# If you perform a db.errors.find() it will look like the object was shorted
# as there is a \0 in the the middle of a string. However, if you use
# mongodump -h localhost -d test -c errors -o steamydump
@chergert
chergert / chergsedit.py
Created March 19, 2011 01:33
try to get spacing/formatting right for my C style with gtksourceview
#!/usr/bin/env python
"""
A simple editor built for live editing in GLib'ish manner.
"""
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import GtkSource