Skip to content

Instantly share code, notes, and snippets.

@ptomato
ptomato / .jshintrc
Created April 26, 2014 00:17
My .jshintrc for GJS development
{
"esnext": true,
"evil": false,
"indent": 4,
"moz": true,
"multistr": true,
"sub": true,
"trailing": true,
"undef": true,
"predef": [
@ptomato
ptomato / clone.js
Created September 19, 2014 08:44
Clone a GObject
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const Gir = imports.gi.GIRepository;
// G_PARAM_READWRITE is not yet properly introspected
const READWRITE = GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE;
const dontCloneTheseProperties = [
['Gtk', 'Widget', 'parent'], // would try to add the new widget to the same parent
['Gtk', 'Widget', 'margin'], // sets all margin properties at once
@ptomato
ptomato / gjsoverridesreader.js
Last active August 29, 2015 14:14
GJS overrides reader
const Gio = imports.gi.Gio;
let file = Gio.File.new_for_path(ARGV[0]);
let moduleName = file.get_basename().split('.')[0];
imports.searchPath.unshift(file.get_parent().get_path());
let module = imports[moduleName];
imports.searchPath.shift();
// Create missing parts of GObject-introspected API. Since we are importing the
V=0
VERBOSE = $(VERBOSE_$(V))
VERBOSE_0 = @echo " GEN $@";
VERBOSE_1 =
VIDEXT = webm
video_names = \
endless-01-desktop.m4v endless-08-offline.m4v \
endless-02-folders.m4v endless-09-writer.m4v \
<!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" />
[
{
"playlist": [],
"machine_name": "math",
"subcategories": [
{
"playlist": [
{
"status": "0",
"vid": "Kf9KjCKmDcU",
@ptomato
ptomato / css.md
Created August 12, 2015 04:27
GTK CSS properties
@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
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 / 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