Skip to content

Instantly share code, notes, and snippets.

View magcius's full-sized avatar
🐬
it's a dAmN cOld NiGhT tryin 2 figure out this life

Jasper St. Pierre magcius

🐬
it's a dAmN cOld NiGhT tryin 2 figure out this life
View GitHub Profile
static BOOL
inside_segment(int v, int v1, int v2)
{
if (v1 < 0 && v2 < 0) /* line */
return TRUE;
else if (v1 < 0) /* ray */
return v <= v2;
else if (v2 < 0) /* ray */
return v >= v1;
else /* line segment */
@magcius
magcius / tutorial.rst
Created August 20, 2012 03:25 — forked from washort/tutorial.rst
parsley tutorial

Parsley Tutorial

From Regular Expressions To Grammars

Parsley is a pattern matching and parsing tool for Python programmers.

@magcius
magcius / tutorial.rst
Created August 14, 2012 04:36 — forked from washort/tutorial.rst
parsley docs

Parsley Tutorial

Let's parse it up with Parsley. Following the standard example of other parsing frameworks, we're going to build a standard mathematical expression parser. Unlike other frameworks like PyParsing, Parsley grammars are defined in a giant string, rather than a special DSL.

Let's start with something that can interpret a collection of digits, and spit out a number:

import parsley
@magcius
magcius / listmode.c
Created August 13, 2012 19:25
List the current mode of the CRTC.
/* gcc -o listmode listmode.c $(pkg-config --cflags --libs glib-2.0 libdrm) */
#include <glib.h>
#include <fcntl.h>
#include <stdlib.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
int
main (int argc, char **argv)
@magcius
magcius / displaybuffer.c
Created August 13, 2012 19:40
Create a buffer on the card, and display it for five seconds
/* gcc -o displaybuffer displaybuffer.c $(pkg-config --cflags --libs glib-2.0 libdrm) */
#include <glib.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
int
@magcius
magcius / listconnectors.c
Created August 13, 2012 18:09
List all connectors on the machine.
/* gcc -o listconnectors listconnectors.c $(pkg-config --cflags --libs glib-2.0 libdrm) */
#include <glib.h>
#include <fcntl.h>
#include <stdlib.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
int
main (int argc, char **argv)
@magcius
magcius / listconnectors.c
Created August 13, 2012 17:56
Try and find the active connector.
/* gcc -o listconnectors listconnectors.c $(pkg-config --cflags --libs glib-2.0 libdrm) */
#include <glib.h>
#include <fcntl.h>
#include <stdlib.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
int
main (int argc, char **argv)
const Lang = imports.lang;
const Signals = imports.signals;
const Tweener = imports.tweener.tweener;
const Clutter = imports.gi.Clutter;
Clutter.init(null);
let white = Clutter.Color.get_static(Clutter.StaticColor.WHITE);
#include <sdl.h>
struct _EventFuncs {
void (*on_keydown) (char key, void *user_data);
void (*on_loop) (void *user_data);
};
typedef struct _EventFuncs EventFucs;
void event_loop(EventFuncs *event_funcs, void *user_data) {
#include <cairo/cairo.h>
#include <math.h>
static void
draw_region (cairo_t *cr,
cairo_region_t *region)
{
cairo_rectangle_int_t box;
int n_boxes, i;