Skip to content

Instantly share code, notes, and snippets.

@b4n
b4n / threading.c
Created August 27, 2012 09:07
Threading with GTK
#include <gtk/gtk.h>
typedef struct
{
GtkWidget *window;
guint progress_id;
} WorkerData;
@b4n
b4n / lcs.c
Last active February 11, 2018 03:56
/*
* License: GPLv2+
* Author: Colomban Wendling <colomban@geany.org>
*/
/*
* FIXME: improve function names (e.g. strvstrv doesn't simply do strstr anymore)
*/
#include <stdlib.h>
@b4n
b4n / config-diff.sh
Created January 28, 2017 16:24
Script to diff configuration files (INI-style)
#!/bin/bash
# Diffs 2 configuration files, sorting their content by sections to and key
# names to get a meaningful diff.
sed_escape() {
sed 's/[][/\\.$^]/\\\0/g' <<<"$1"
}
read_section_sorted() {
@b4n
b4n / geany-run-helper.c
Created November 9, 2016 10:09
Attempt at a helper program wrapping a call, displaying the exit status and waiting on the user
/*
* geany-run-helper.c - this file is part of Geany, a fast and lightweight IDE
*
* Copyright 2016 Colomban Wendling <ban(at)herbesfolles(dot)org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
@b4n
b4n / gen-gir.sh
Last active March 6, 2016 21:21
Generate Geany-1.0.gir from geany-gtkdoc.h with sciwrappers methods on the ScintillaObject itself
#!/bin/sh
set -e
trap 'rm -f /tmp/get-type.txt geany-gtkdoc-tmp.h' EXIT INT QUIT TERM
# prepare the get-type list
cat > /tmp/get-type.txt <<EOF
get-type:stash_group_get_type
get-type:tm_source_file_get_type
@b4n
b4n / main.c
Created December 29, 2013 20:28
Issue with GtkActionGroup inside GtkBuilder definitions
#include <gtk/gtk.h>
int
main (int argc,
char **argv)
{
GObject *object;
GtkBuilder *builder;
GError *err = NULL;
@b4n
b4n / ptimer.c
Last active December 15, 2015 21:18
Very simple timer using POSIX API
/*
* ptimer.c
* A timer using POSIX API
*
* Copyright (c) 2005-2008, Colomban Wendling <ban@herbesfolles.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
@b4n
b4n / relative-project.py
Created October 2, 2012 14:12
Finding file after project move
import os
def path_inside(path, dir):
path = os.path.normpath(path)
dir = os.path.normpath(dir)
return os.path.commonprefix([path, dir]) == dir
def path_samepath(a, b):
return os.path.normpath(a) == os.path.normpath(b)
/* old, one loop
*
* With not enough data (< 4096):
* mem_read (..., 1, 4096): 162.099252s (100000000 runs)
* mem_read (..., 4096, 1): 0.967107s (100000000 runs)
* With enough data (>= 4096):
* mem_read (..., 1, 4096): 2274.210934 (100000000 runs)
* mem_read (..., 4096, 1): 10.416469 (100000000 runs)
*/
@b4n
b4n / mergetags
Last active August 29, 2015 14:24
mergetags -- A tool to update entries for a single file in a CTags tag file
#!/bin/sh
#
# FIXME: better error checking. As many commands are piped, their return code
# is not properly checked.
export LANG=C
set -e
### argument parsing