Skip to content

Instantly share code, notes, and snippets.

#include "jsapi.h"
int main(int argc, const char *argv[])
{
JS_Init();
JSRuntime *rt = JS_NewRuntime(8L * 1024 * 1024, JS_USE_HELPER_THREADS);
if (!rt)
return 1;
@ptomato
ptomato / callargs.cpp
Last active October 9, 2016 23:10
Templated scanf-like function
#include <iostream>
struct SomeStruct {
int val;
};
template<typename T>
bool
assign(const char c, T& ref) {
return false;
// compile me with:
// g++ -g -O0 -o testconv testconv.cpp `pkg-config --cflags --libs mozjs-24` -std=c++11
// output:
// JS_ValueToInt32: did not convert
// JS::ToInt32: converted, value is 0
#include <iostream>
#include <jsapi.h>
static JSClass global_class = {
#include <gtk/gtk.h>
#include <stdio.h>
static GtkWidget *mainWindow = NULL;
void
prompt_window (void)
{
GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (mainWindow),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
@ptomato
ptomato / gist:0e70598951f1ce809d5e9625a0b0dd8e
Last active May 16, 2016 00:08
Localize using gettext

How to localize using gettext

This document does not try to explain how to enable gettext support in an application. There are other documents that describe that process better. (Need links!)

The PO format and the PO files

Even as a developer, knowing some elementary stuff about the PO format, the format of the actual translations, is very useful.

The PO format is a really simple format, which probably at least partly explains its success and widespread use. The format is basically a hash list consisting of ''msgid'' and ''msgstr'' pairs, with the msgid being the original English string and key, and the msgstr being the translated value of it. As the English string is the key, all instances of the exact same English string in the code will be represented by exactly only one key/value pair, referred to as a ''message'', in the PO file. Usually this is not a problem, but instead a benefit of the format, as the exact same string won't have to be translated more than once by the translator. Below is

import math
from gi.repository import Gdk, Gtk, Pango
WIDTH = 150
HEIGHT = 207
CSS = '''
.frame { border: 1px solid red; }
'''
class FixedSize(Gtk.Frame):
@ptomato
ptomato / setup.sh
Last active October 5, 2018 12:52
Configure DevDocs on EC2
sudo yum update
sudo yum install gobject-introspection-devel gtk3-devel gstreamer1-devel \
libsoup-devel json-glib-devel gcc-c++ patch readline-devel openssl-devel \
bison bzip2 sqlite-devel git flex intltool python2-devel libxslt-devel \
docbook-xsl python-markdown
curl -O ftp://mirror.switch.ch/pool/4/mirror/scientificlinux/7rolling/x86_64/os/Packages/libyaml-devel-0.1.4-11.el7_0.x86_64.rpm
curl -O ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/TheIndifferent:/rhel7-icewm/rhel7-shared/noarch/itstool-2.0.2-2.1.noarch.rpm
sudo rpm -ivh libyaml-devel-0.1.4-11.el7_0.x86_64.rpm itstool-2.0.2-2.1.noarch.rpm
sudo su - root # otherwise repos can't be reached?? http://stackoverflow.com/questions/28802298
@ptomato
ptomato / css.md
Created August 12, 2015 04:27
GTK CSS properties
[
{
"playlist": [],
"machine_name": "math",
"subcategories": [
{
"playlist": [
{
"status": "0",
"vid": "Kf9KjCKmDcU",
<!DOCTYPE html>
<html lang="en" dir="ltr" class="client-nojs">
<head>
<meta charset="UTF-8" />
<title>American bullfrog - Wikipedia, the free encyclopedia</title>
<meta name="generator" content="MediaWiki 1.26wmf1" />
<link rel="alternate" href="android-app://org.wikipedia/http/en.m.wikipedia.org/wiki/American_bullfrog" />
<link rel="alternate" type="application/x-wiki" title="Edit this page" href="/w/index.php?title=American_bullfrog&amp;action=edit" />
<link rel="edit" title="Edit this page" href="/w/index.php?title=American_bullfrog&amp;action=edit" />
<link rel="apple-touch-icon" href="//bits.wikimedia.org/apple-touch/wikipedia.png" />