Skip to content

Instantly share code, notes, and snippets.

View FlyingJester's full-sized avatar

Martin McDonough FlyingJester

View GitHub Profile
@FlyingJester
FlyingJester / test.cpp
Last active January 7, 2016 01:38
Demonstration of using using differing templates of a template parameter
#include <functional>
#include <algorithm>
#include <cstdio>
template<template<typename> class Op >
void Test(int &ia, int &ib, float &fa, float &fb, bool first){
if(first){
Op<int> op;
ia = op(ia, ib);
}
[14:44] mischief | one daemon to rule them all, one daemon to find them, one daemon to bring them all and in the darkness bind them!
[14:45] oldlaptop | must we cast it into the fires of /dev/null?
[14:45] mischief | you must travel to mount freedesktop.org and face lord poettering's all seeing eye
@FlyingJester
FlyingJester / tower_event.m
Created August 11, 2015 21:15
SDL2 Events from Mercury
%===============================================================================
:- module tower_event.
%===============================================================================
:- interface.
%===============================================================================
:- import_module io.
:- type point ---> point(x::int, y::int).
:- type button ---> left ; middle ; right.
:- module numberizer.
:- interface.
:- type numberizer.number_type ---> prime ; even ; other.
:- func numberizer.categorize(int::in) = (numberizer.number_type::out) is det.
:- pred numberizer.prime(int::in) is semidet.
:- pred numberizer.even(int::in) is semidet.
#include <FL/Fl_Window.H>
#include <FL/Fl_Text_Editor.H>
#include <FL/Fl_Text_Buffer.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl.H>
#include <FL/fl_ask.H>
#include <string>
@FlyingJester
FlyingJester / canonicalize.c
Created April 15, 2015 01:01
Simple Path Canonicalizer
#include <stdlib.h>
#include <string.h>
char *TS_CanonicalizePathName(const char * const in){
// Slightly overengineered, we double our string size (cap) when we need more room
unsigned current_stack_cap = 16, current_stack_len = 1;
unsigned *len_stack = malloc(current_stack_cap*sizeof(unsigned));
const char **str_stack = malloc(current_stack_cap*sizeof(const char *)),
*at = in;
int FlareParseString_C_1(const char * const string, const char *old_start, size_t len, void(*parse_callback_)(const char *, size_t, enum FlareFormat_C, void *), void *arg_){
const char *at = string;
unsigned skipped = 0; /* This will be used for term checking in case of UTF-8, non-ascii spaces. */
if(!((*string!='\0') && len)){
parse_callback_(old_start, string-old_start, e_c_normal, arg_);
return 1;
}
if(memcmp(string, "//", FULLMETAL_MIN(2, len))==0){
@FlyingJester
FlyingJester / xlib.m
Created March 13, 2015 23:32
A prototype X11/Xlib binding for Mercury
:- module xlib.
:- interface.
:- import_module maybe.
:- import_module bool.
:- import_module list.
:- import_module io.
% A fairly terrible, custom-made Xlib binding for Mercury.
% Unless something is pretty trivial in C (for instance, xlib.event_window),
@FlyingJester
FlyingJester / gist:8adafd25ddf4e7acc944
Created February 8, 2015 09:43
There is no reason C++ needs to look like this.
Process 36596 stopped
* thread #1: tid = 0x546008, 0x00000001035b2f94 libSapphire.dylib`std::__1::__tree_iterator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, void*>*, long> std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int> > >::find<std::__1::basic_str
@FlyingJester
FlyingJester / kashyyyk
Created January 20, 2015 21:31
Kashyyyk MingW patch
diff -Naurp src/Kashyyyk_src/kashyyyk/channel.hpp tmp/Kashyyyk_src/kashyyyk/channel.hpp
--- src/Kashyyyk_src/kashyyyk/channel.hpp 2014-10-27 14:16:16 -0400
+++ tmp/Kashyyyk_src/kashyyyk/channel.hpp
@@ -14,6 +14,16 @@
#include <memory>
#include <string>
#include <mutex>
+#ifdef __MINGW32__
+#include <stdio.h>
+#include <pthread.h>