Skip to content

Instantly share code, notes, and snippets.

View codebrainz's full-sized avatar

Matthew Brush codebrainz

View GitHub Profile
@codebrainz
codebrainz / newwin_dynamic.patch
Created July 28, 2015 01:03
Fix "Open in New Window" feature
diff --git a/src/utils.c b/src/utils.c
index c5edd5a..37ae12a 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -2154,30 +2154,35 @@ const gchar *utils_resource_dir(GeanyResourceDirType type)
void utils_start_new_geany_instance(const gchar *doc_path)
{
- const gchar *const *argv;
const gchar *command = is_osx_bundle() ? "open" : "geany";
@codebrainz
codebrainz / main.c
Created June 23, 2015 02:48
List include files using libclang
#include <stdio.h>
#include <stdlib.h>
#include <clang-c/Index.h>
enum CXChildVisitResult
onVisitCursor(CXCursor cursor, CXCursor parent, CXClientData client_data)
{
if (clang_getCursorKind(cursor) == CXCursor_InclusionDirective) {
CXFile file = clang_getIncludedFile(cursor);
AC_DEFUN([AX_POSIX], [
AC_MSG_CHECKING([for POSIX 2008 support])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#define _POSIX_C_SOURCE 200809L
#include <unistd.h>
# if !defined(_POSIX_VERSION) || _POSIX_VERSION < 200809L
# error "Not POSIX 2008"
#endif
int main() { return 0; }
])], [
@codebrainz
codebrainz / gist:95681f9d30937359f6f5
Last active August 29, 2015 14:16
Make "hunting for Scintilla" a little more robust
diff --git a/src/document.c b/src/document.c
index 8a57d93..edaed0d 100644
--- a/src/document.c
+++ b/src/document.c
@@ -226,16 +226,8 @@ GeanyDocument *document_find_by_filename(const gchar *utf8_filename)
/* returns the document which has sci, or NULL. */
GeanyDocument *document_find_by_sci(ScintillaObject *sci)
{
- guint i;
-
@codebrainz
codebrainz / gist:8587a1ddc8e020a71fef
Last active January 11, 2022 16:25
Simple assembly parser in Bison
%{
#include "stdinc.h"
#include "parser.h"
#include "tokens.h"
#include "lexer.h"
static void parser_error(YYLTYPE *locp, struct Parser* par, const char *message);
#define parser_lex(a,b,c) parser_lex(a,b,(c)->scanner)
@codebrainz
codebrainz / gist:69b8df344481b51112c5
Last active August 29, 2015 14:13
Run build system when sources change
#!/bin/bash
# Inspired by: https://exyr.org/2011/inotify-run/
# base source dir, found from script's dir, in my case it's `..` to the base srcdir
SRCDIR=$(cd "$(dirname $(dirname "$0"))"; pwd -P)
# command to run initially and on file changes, in my case in `build` dir
COMMAND="make -C $SRCDIR/build"
@codebrainz
codebrainz / listdeps.py
Last active August 29, 2015 14:12
Getting a list of header dependencies using GCC -MM
#!/usr/bin/env python3
import argparse
import json
import re
import sys
from collections import OrderedDict
from subprocess import Popen, PIPE
RE_INC = re.compile(r'^(?P<target>.+?):\s+(?P<deps>.+?)$', re.MULTILINE)
@codebrainz
codebrainz / scope_exit.hxx
Last active August 29, 2015 14:12
A macro/template implementation of C++ scope guard
#pragma once
#include <utility>
namespace ScopeExitNamespace__ {
template<typename T> struct OnScopeExit__ {
T func;
OnScopeExit__(T func) : func(std::move(func)) {}
~OnScopeExit__() noexcept { func(); }
};
@codebrainz
codebrainz / test.ast
Last active August 29, 2015 14:11
Sample C++ TreeGen output
//
// test.ast - Sample AST description for treegen
//
target CPlusPlus {
// In string literals,
// $$ is target/variable (for externs)
// $_ is "this" or "self", etc. (for nodes and externs)
// $@ is the type (for nodes and externs)
#include <setjmp.h>
#include <stdio.h>
#define WHILE(while_expr) { \
int jumped____; \
jmp_buf redo_target____; \
int restarted____; \
restarted____ = setjmp(redo_target____); \
jumped____ = 1; \
while ((while_expr)||(jumped____=0)) {