Languages

Snippet to read Input.Event struct's from /dev/input/event* using IOChannel's

4
Your rating: None Average: 4 (1 vote)
/*
 * To compile: valac --pkg=linux --pkg=posix inputeventreader.vala
 *
 * Description:
 *   This example uses of the GLib's main loop and IOChannel's
 *   to listen for Input.Event's on one or more /dev/input/event*
 *   devices, and outputs the values to standard output.
 *
 * Copyright 2010, Robert Thomson.
 *
 * Released under the MIT License
 */
using Linux;
using Posix;
 
class InputEventReader {
 
    // Read a single input event from the channel, and print out the values.
    private static bool gio_in(IOChannel gio, IOCondition condition) {
        if((condition & IO

[Genie] Cairo transparent window

5
Your rating: None Average: 5 (3 votes)
[indent=4]
 
/* Build with valac --pkg gtk+-2.0 --pkg cairo yourfile.gs */
 
uses
    Gtk
    Cairo
 
class TransparentWindow : Gtk.Window
 
    init
        this.type = Gtk.WindowType.TOPLEVEL
        /* Set the title is useless !

Example for reading archives using libarchive

4.333335
Your rating: None Average: 4.3 (3 votes)
/* archive.vala - Example for using the libarchive bindings in Vala.
 *
 * Copyright (C) 2009 Julian Andres Klode <jak@debian.org>
 *
 * Copying and distribution of this file, with or without modification,
 * are permitted in any medium without royalty provided the copyright
 * notice and this notice are preserved.

Extract Arabic Words From a Text File

5
Your rating: None Average: 5 (4 votes)
/**
*
*    Description  : A simple snippet to demonstrate how to extract Arabic Words in Vala programming language
*    Vala version : 0.7.8
*    Developed by : Emad Al-Bloushi
*    Date         : Mon 23 Nov, 2009
*    Compile with : valac --pkg gee-1.0 word.vala
*
**/

Using Google AJAX Language API

5
Your rating: None Average: 5 (3 votes)
/**
*
*    Description  : A simple snippet to demonstrate how to use Google AJAX API in Vala programming language
*    Vala version : 0.7.8
*    Developed by : Emad Al-Bloushi
*    Date         : Thu 12 Nov, 2009
*    Compile with : valac --thread --pkg libsoup-2.4 --pkg json-glib-1.0 GoogleTranslator.vala
*    Refer to     : http://code.google.com/apis/ajaxlanguage/documentation/#fonje
*
**/

[Genie] Clutter simple sample

0
Your rating: None
[indent=4]
 
/* Requires Vala >= 0.7.9
valac --pkg clutter-1.0 yourfile.gs */
 
uses
    Clutter
 
class ClutterDemo
 
    animations : array of Animation
    stage : Stage
    rectangles : array of Rectangle
    const colors : array of string = { "blanched almond", "OldLace", "MistyRose", "White", "LavenderBlush", "CornflowerBlue", "chartreuse", "chocolate", "light coral", "medium violet red", "LemonChiffon2", "RosyBrown3" }
 
    construct ()
        stage = Stage.get_default ()
        rectangles = new array of Rectangle[colors.length]
        stage.hide.connect (Clutter.main_q

[Genie] LibSoup simple server

0
Your rating: None
[indent=4]
 
def default_handler(server : Soup.Server, msg : Soup.Message, path : string, query : GLib.HashTable?, client : Soup.ClientContext)
    response_text : string = "<html><body><p>Current location: %s</p><p><a href=\"/xml\">Test XML</a></p>

[Genie] Simple server test

5
Your rating: None Average: 5 (1 vote)
[indent=4]
 
def process_request (input : InputStream, output : OutputStream) raises Error
    var data_in = new DataInputStream (input)
    line : string
    while ((line = data_in.read_line (null, null)) != null)
        print line
        if (line.strip () == "") do break
 
    content : string = "<html><h1>Hello from Genie server</h1></html>"
    var header = new StringBuilder ()
    header.append ("HTTP/1.0 200 OK\r\n")
    header.append ("Content-Type: text/html\r\n")
    header.append_printf ("Content-Length: %lu\r\n\r\n", content.size ())
    output.write (header.str, heade

Soup - sample using parameters

0
Your rating: None
//compile with: valac --thread --pkg libsoup-2.4 main.vala -o soup_post
using Soup;
class rpc_request
{
	private static rpc_request request_instance;
	private HashTable<string,string> args;
	private rpc_request()
	{
		args=new HashTable<string,string>(str_hash,str_equal);
	}
	public static rpc_request get_instance()
	{
		if(null==request_instance)
		{
			request_instance=new rpc_request();
		}
		return request_instance;
	}
	public void add_parameter(string name,string val)
	{
		args.insert(name,val);
	}
	private string prepare()
	{
		Soup.URI myuri=new Soup.URI("http://

Simple Gedit plugin

0
Your rating: None
/**
* You'll need to grab the attached files and remove the .txt at the end of them in order to use this.
* I put both the vapi and deps file in /usr/share/vala/vapi/ to have them readily available.  You can also keep them in your project folder if you want, * but you'll need to update the compile line to reflect that
* the compiled .so and gedit-plugin files go in ~/.gnome2/gedit/plugins/
* Sample makefile is also attached.
* 
* Displays a button on the top Gedit panel that displays a color dialog when clicked.
Syndicate content