Skip to content

Instantly share code, notes, and snippets.

@ptomato
ptomato / class.js
Created July 14, 2017 03:32
Inventing GObject ES6 Classes (4)
var MyClass = GObject.registerClass({
    GTypeName: 'MyNamespaceMyClass',
    Implements: [Gio.Initable, MyInterface],
    Properties: { 'prop': GObject.ParamSpec.int( /* etc. */ ) },
    Signals: { 'signal': { /* etc. */ } },
}, class MyClass extends GObject.Object {
    constructor(props={}) {
super(props);
// etc.
}
@ptomato
ptomato / decorators.js
Last active July 14, 2017 05:53
Inventing GObject ES6 Classes (3)
@GObject.Class('MyNamespaceMyClass')
@GObject.implements([Gio.Initable, MyCustomInterface])
@GObject.signal('signal', { /* etc. */ })
class MyClass extends GObject.Object {
    constructor(props={}) {
super(props);
// etc.
}
 
    @GObject.property.int('Short name', 'Blurb', GObject.ParamFlags.READABLE, 42)
@ptomato
ptomato / verbose.js
Last active July 14, 2017 04:29
Inventing GObject ES6 Classes (2)
class MyClass extends GObject.Object {
    static get GTypeName { return 'MyNamespaceMyClass'; }
    static get Implements { return [Gio.Initable, MyCustomInterface]; }
    static get Properties {
        return {
            'prop': GObject.ParamSpec.int( /* etc., etc. */ ),
        };
    }
    static get Signals {
        return {
@ptomato
ptomato / legacy.js
Last active July 14, 2017 03:02
Inventing GObject ES6 Classes (1)
const MyClass = new Lang.Class({
    Name: 'MyClass',
    GTypeName: 'MyNamespaceMyClass',
    Extends: GObject.Object,
    Implements: [Gio.Initable, MyCustomInterface],
    Properties: {
        'prop': GObject.ParamSpec.int( /* etc., etc. */ ),
    },
    Signals: {
        'signal': { param_types: [ /* etc., etc. */ ] },
@ptomato
ptomato / lexical.cpp
Created April 30, 2017 19:55
how to get the lexical scope of an executed script
/* g++ -g -Wno-invalid-offsetof -DDEBUG -std=c++11 -o lexical `pkg-config --cflags --libs mozjs-45` lexical.cpp */
#include <iostream>
#include "js-config.h"
#include "jsapi.h"
#include "js/Initialization.h"
#include "jsfriendapi.h"
static JSClass global_class = {
@ptomato
ptomato / leafnode.js
Created April 22, 2017 20:17
The Mad Scientist Review - GJS Generator Example
const Gio = imports.gi.Gio;
function* leafnodes(file) {
let enumerator = file.enumerate_children('standard::*', 0, null);
let info;
while ((info = enumerator.next_file(null))) {
let child = enumerator.get_child(info);
if (info.get_file_type() === Gio.FileType.DIRECTORY)
yield* leafnodes(child);
else
@ptomato
ptomato / gio-cat.js
Last active April 22, 2017 20:03
The Mad Scientist Review - GJS Promise example
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
function wrapPromise(obj, cancellable, asyncName, finishName, ...inArgs) {
return new Promise((resolve, reject) => {
let callerStack = new Error().stack
.split('\n')
.filter(line => !line.match(/<Promise>|wrapPromise/))
.join('\n');
obj[asyncName](...inArgs, cancellable, (obj, res) => {
/* gcc -o undrflow undrflow.c `pkg-config --cflags --libs gobject-2.0` */
#include <glib-object.h>
#define PROP_FOO 1
#define TEST_TYPE_FOO test_foo_get_type ()
G_DECLARE_FINAL_TYPE (TestFoo, test_foo, TEST, FOO, GObject);
struct _TestFoo
{
@ptomato
ptomato / kitten.css
Created December 20, 2016 23:41
Cat picture news article with constraints
.headerView {
background-color: lightgray;
}
.headline {
font-size: 30pt;
background-color: yellow; /* So we can see the sizing */
}
.byline {
*** Building gcab *** [1/1]
make -j 5
GEN libgcab/gcab-enums.c
GEN libgcab/gcab-enums.h
CC libgcab/libgcab_1_0_la-gcab-cabinet.lo
CC libgcab/libgcab_1_0_la-gcab-folder.lo
CC libgcab/libgcab_1_0_la-gcab-file.lo
warning: unknown warning option '-Waggressive-loop-optimizations'
[-Wunknown-warning-option]
warning: unknown warning option '-Wclobbered'; did you mean '-Wconsumed'?