working on it ...

Filters

Explore Public Snippets

Sort by

Found 59 snippets

    public by marceloviana modified Nov 14, 2016  1500  14  4  0

    Csharp consumindo Rest + lendo JSON

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net;
    using System.IO;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    
    namespace ExemploChatBot
    {
        public partial class Chat : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void enviar_Click(object sender, EventArgs e)
            {
                string txt_campo_texto = campo_texto.Text;
    
                var url = "http://128.0.0.1:5000/site?id=2542&texto_digitado="+ txt_campo_texto + "";
    
                var syncClient = new WebClient();
                var content = syncClient.DownloadString(url);            
    
                dynamic registro = JObject.Parse(content);
                campo_texto.Text = registro.pergunta;
    
            }
        }
    }

    external by ???????? modified Jan 1, 2018  12  0  1  0

    Wildcards in vala

    Wildcards in vala: wildcards.vala
    public class Container<T> : Object {
    	public T value { get; set; }
    	
    	public Container (T value) {
    		_value = value;
    	}
    }
    
    void main () {
    	Container<void*> obj;
    	
    	// (Container<void*>) <- required because 'int' is not a pointer type
    	obj = (Container<void*>) new Container<int>(111);
    	print("hello %d!\n", ((Container<int>)obj).value); // hello 111!
    	
    	// (Container<void*>) <- NOT required because 'Container' is a pointer type
    	obj = new Container<Container<int>>( new Container<int>(222) );
    	print("hello %d!\n", ((Container<Container<int>>)obj).value.value); // hello 222!
    }
    
    

    external by Carlos Suárez modified Dec 4, 2017  11  0  1  0

    Show app-notification gnome-style.

    Show app-notification gnome-style.: ticket.vala
    /*
    * Authored by: Carlos Suárez <bitseater@gmail.com>
    * https://github.com/bitseater
    */
    int main (string[] args) {
        Gtk.init (ref args);
    
        var window = new Gtk.Window ();
        window.title = "Ticket";
        window.set_border_width (0);
        window.set_position (Gtk.WindowPosition.CENTER);
        window.set_default_size (450, 350);
        window.destroy.connect (Gtk.main_quit);
    
        //contenido ventana
        var overlay = new Gtk.Overlay ();
        var content = new Gtk.Box (Gtk.Orientation.VERTICAL, 10);
        var label2 = new Gtk.Label (" Ejemplo de ticket");
        var button_2 = new Gtk.Button.with_label ("Muestra ticket");
        content.pack_start (label2, true, true, 0);
        content.pack_start (button_2, false, false, 0);
    
        //contenido ticket
        var ticket = new Gtk.Revealer ();
        ticket.halign = Gtk.Align.CENTER;
        ticket.valign = Gtk.Align.START;
        ticket.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
        ticket.transition_duration = 500;
        var frame = new Gtk.Frame (null);
        frame.get_style_context ().add_class ("app-notification");
        var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5);
        var label = new Gtk.Label ("Esta es una notificación");
        var button = new Gtk.Button.from_icon_name ("window-close-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
        button.relief = Gtk.ReliefStyle.NONE;
        button.receives_default = true;
        box.pack_start (label, false, true, 0);
        box.pack_end (button, false, false, 0);
        frame.add (box);
        ticket.add (frame);
    
        //Acciones
        button.clicked.connect (() => {
            ticket.reveal_child = false;
        });
    
        button_2.clicked.connect (() => {
            ticket.reveal_child = true;
        });
    
        //Añadir a la ventana
        overlay.add_overlay (content);
        overlay.add_overlay (ticket);
        window.add (overlay);
        window.show_all ();
    
        Gtk.main ();
        return 0;
    }
    
    

    external by BZHDeveloper modified Nov 18, 2017  11  0  1  0

    drag & drop Gtk.FlowBoxChild

    drag & drop Gtk.FlowBoxChild: drag-box-child.vala
    public abstract class DragBoxChild : Gtk.FlowBoxChild {
    	construct {
    		Gtk.TargetEntry te = { "STRING",        0, 0 };
    		Gtk.TargetEntry ue = { "text/plain",    0, 0 };
    		Gtk.TargetEntry ve = { "text/uri-list", 0, 1 };
    		
    		Gtk.TargetEntry targetentries[] = { te, ue, ve };
    		
    		Gtk.drag_dest_set (this, Gtk.DestDefaults.ALL, targetentries, Gdk.DragAction.COPY);
    		drag_data_received.connect ((context, x, y, data, info, time) => {
    			if (data.get_text() != null)
    				uris_received (new string[] { data.get_text() });
    			else
    				uris_received (data.get_uris());
    		});
    	}
    	
    	public signal void uris_received (string[] uris);
    }
    
    public class LabelChild : DragBoxChild {
    	Gtk.Label label;
    	
    	construct {
    		this.label = new Gtk.Label (this.text);
    		add (this.label);
    		uris_received.connect (uris => {
    			this.label.label = string.joinv ("; ", uris);
    		});
    	}
    	
    	public LabelChild (string text) {
    		GLib.Object (text : text);
    	}
    	
    	public string text { get; construct; }
    }
    
    public static void main (string[] args) {
    	Gtk.init (ref args);
    	var win = new Gtk.Window();
    	var box = new Gtk.FlowBox();
    	box.add (new LabelChild ("toto"));
    	box.add (new LabelChild ("tutu"));
    	box.add (new LabelChild ("titi"));
    	win.add (box);
    	win.show_all();
    	Gtk.main();
    }
    
    
    

    external by BZHDeveloper modified Nov 18, 2017  14  0  2  0

    Drag & Drop data

    Drag & Drop data: drag-data-sample.vala
    public static void main (string[] args) {
    	Gtk.init (ref args);
    	var win = new Gtk.Window();
    	var box = new Gtk.EventBox();
    	var label = new Gtk.Label ("drag data here");
    	
    	Gtk.TargetEntry te = { "STRING",        0, 0 };
    	Gtk.TargetEntry ue = { "text/plain",    0, 0 };
    	Gtk.TargetEntry ve = { "text/uri-list", 0, 1 };
    	
    	Gtk.TargetEntry targetentries[] = { te, ue, ve };
    	
    	Gtk.drag_dest_set (box, Gtk.DestDefaults.ALL, targetentries, Gdk.DragAction.COPY);
    	box.drag_data_received.connect ((context, x, y, data, info, time) => {
    		print ("text : %s\n", data.get_text());
    		foreach (string uri in data.get_uris())
    			print ("uri : %s\n", uri);
    	});
    	box.add (label);
    	win.add (box);
    	win.show_all();
    	Gtk.main();
    }
    
    
    

    external by BZHDeveloper modified Nov 18, 2017  14  0  1  0

    Gee.Collection deserialization

    Gee.Collection deserialization: gee-collection-deserialization.vala
    public class Tutu : GLib.Object {
    	Gee.ArrayList<int> list;
    	
    	construct {
    		this.list = new Gee.ArrayList<int>();
    	}
    	
    	public Gee.List<int> array {
    		get {
    			return this.list;
    		}
    	}
    	
    	public string chaine { get; set; }
    	public int64 valeur { get; set; }
    }
    
    public class Tata : GLib.Object {
    	Gee.ArrayList<Tutu> list;
    	
    	construct {
    		this.list = new Gee.ArrayList<Tutu>();
    	}
    	
    	public Gee.List<Tutu> tutus {
    		get {
    			return this.list;
    		}
    	}
    	
    	public string name { get; set; }
    }
    
    public class Tugudu : GLib.Object {
    	string str;
    	
    	public Tugudu (Value val) {
    		this.value = val;
    	}
    	
    	public GLib.Value value {
    		get {
    			return this.str;
    		}
    		set {
    			this.str = value.get_string();
    		}
    	}
    }
    
    public static void main (string[] args) {
    	string json = """{
    	"name" : "toto",
    	"tutus" : [
    		{ "chaine" : "pojposdgfj", "valeur" : 3968 },
    		{ "chaine" : "oifghsioii", "valeur" : 3096 },
    		{
    			"chaine" : "qsxziufhze",
    			"valeur" : 1932,
    			"array" : [ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ]
    		}
    	]
    }""";
    	var object = GJson.Object.parse (json);
    	var tata = (Tata)GJson.deserialize_object (typeof (Tata), object);
    	print ("%s\n", tata.name);
    	tata.tutus.foreach (tutu => {
    		print ("\t%s : %lld\n", tutu.chaine, tutu.valeur);
    		foreach (int i in tutu.array)
    			print ("\t\t%d\n", i);
    		return true;
    	});
    }
    
    
    

    external by Kelvin modified Nov 4, 2017  26  0  1  0

    GPU Provider for Ubuntu indicator-multiload

    GPU Provider for Ubuntu indicator-multiload: gpuprovider.vala
    /******************************************************************************
     * Copyright (C) 2017 Yukai Miao <tjumyk@gmail.com>                           *
     *                                                                            *
     * This program is free software; you can redistribute it and/or modify       *
     * it under the terms of the GNU General Public License as published by       *
     * the Free Software Foundation; either version 3 of the License, or          *
     * (at your option) any later version.                                        *
     *                                                                            *
     * This program is distributed in the hope that it will be useful,            *
     * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
     * GNU General Public License for more details.                               *
     *                                                                            *
     * You should have received a copy of the GNU General Public License along    *
     * with this program; if not, write to the Free Software Foundation, Inc.,    *
     * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                *
     ******************************************************************************/
    
    public class GpuProvider : Provider {
        public GpuProvider() {
            base("gpu", {"util", "memtotal", "memused", "memfree"}, 'p');
        }
    
        public override void update() {
    	    try {
                string[] spawn_args = {"nvidia-smi", "-i", "0", "--query-gpu=utilization.gpu,memory.total,memory.used,memory.free", "--format=csv,noheader,nounits"};
                string spawn_stdout;
                string spawn_stderr;
                int spawn_status;
                Process.spawn_sync(null, spawn_args, null, SpawnFlags.SEARCH_PATH, null, out spawn_stdout, out spawn_stderr, out spawn_status);
                string[] columns = spawn_stdout.split(", ");
                this.values[0] = double.parse(columns[0]) / 100.0;
                for(int i = 1 ; i < 4; ++i)
                    this.values[i] = double.parse(columns[i]) * 1000000;
            } catch (SpawnError e) {
                stdout.printf ("Error: %s\n", e.message);
            }
        }
    }
    
    
    

    external by robertsanseries modified Oct 16, 2017  14  0  1  0

    valac --pkg gtk+-3.0 EntryNumber.vala

    valac --pkg gtk+-3.0 EntryNumber.vala: EntryNumber.vala
    using Gtk;
    using Gdk;
    
    public static int main (string[] args) {
        Gtk.init (ref args);
    
        Application app = new Application ();
        app.show_all ();
        Gtk.main ();
        return 0;
    }
    
    public class Application : Gtk.Window {
        
        public Application () {
            this.title = "My Gtk.Window";
            this.window_position = Gtk.WindowPosition.CENTER;
            this.set_default_size (350, 300);
            this.hide_titlebar_when_maximized = false;
    
            EntryNumber entry_number = new EntryNumber (Gtk.InputPurpose.DIGITS);
            entry_number.include_icon_clean ();
            entry_number.changed.connect (() => {
                entry_number.input_digits(); 
            });
    
            this.add (entry_number);
        }
    }
    
    public class EntryNumber : Gtk.Entry {
    
        private string old = "";
    
        public EntryNumber (Gtk.InputPurpose purpose) {
            this.input_purpose = purpose;
        }   
    
        public  void input_digits () {
            try {
                this.text = this.text.replace (" ", "");
                
                var regex = new Regex ("""^[0-9]{1,}$""");
                var regex_match = regex.match (this.text);
                
                if (regex_match) {
                    this.old = this.text;
                } else if (this.text != "") {
                    this.text = this.old;
                }    
            } catch (Error e) {
                message (e.message);
            }    
        }
    
        public void include_icon_clean () {
            this.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "edit-clear");
            this.icon_press.connect ((pos, event) => {
                if (pos == Gtk.EntryIconPosition.SECONDARY) {
                    this.set_text ("");
                }
            });
        }
    }
    
    

    external by BZHDeveloper modified Oct 1, 2017  13  0  1  0

    Custom GStreamer playbin

    Custom GStreamer playbin: custom-playbin.vala
    namespace Vod {
    	public class Player : GLib.Object {
    		Gst.Pipeline pipeline;
    		Gst.Element decodebin;
    		Gst.Element audio_queue;
    		Gst.Element video_queue;
    		Gst.Element audio_convert;
    		Gst.Element video_convert;
    		Gst.Element asink;
    		Gst.Element vsink;
    		
    		construct {
    			this.pipeline = new Gst.Pipeline (name);
    			this.decodebin = Gst.ElementFactory.make ("decodebin", "decodebin");
    			this.audio_queue = Gst.ElementFactory.make ("queue", "audio-queue");
    			this.video_queue = Gst.ElementFactory.make ("queue", "video-queue");
    			this.audio_convert = Gst.ElementFactory.make ("audioconvert", "audio-convert");
    			this.video_convert = Gst.ElementFactory.make ("videoconvert", "video-convert");
    			this.asink = Gst.ElementFactory.make ("autoaudiosink", "audio-sink");
    			this.vsink = Gst.ElementFactory.make ("autovideosink", "video-sink");
    			
    			this.pipeline.add_many (this.decodebin, 
    				this.audio_queue, this.audio_convert, this.asink, 
    				this.video_queue, this.video_convert, this.vsink);
    			
    			this.audio_queue.link (this.audio_convert);
    			this.audio_convert.link (this.asink);
    			this.video_queue.link (this.video_convert);
    			this.video_convert.link (this.vsink);
    			
    			this.decodebin.pad_added.connect (pad => {
    				if (pad.caps.to_string().has_prefix ("audio"))
    					pad.link (this.audio_queue.get_static_pad ("sink"));
    				else
    					pad.link (this.video_queue.get_static_pad ("sink"));
    			});
    			
    			notify["source"].connect (() => {
    				this.pipeline.add (this.source);
    				this.source.link (this.decodebin);
    			});
    			
    			notify["audio-sink"].connect (() => {
    				this.audio_convert.unlink (this.asink);
    				this.pipeline.remove (this.asink);
    				this.asink = audio_sink;
    				this.pipeline.add (this.asink);
    				this.audio_convert.link (this.asink);
    			});
    			
    			notify["video-sink"].connect (() => {
    				this.video_convert.unlink (this.vsink);
    				this.pipeline.remove (this.vsink);
    				this.vsink = video_sink;
    				this.pipeline.add (this.vsink);
    				this.video_convert.link (this.vsink);
    			});
    			
    			notify["uri"].connect (() => {
    				if (this.source != null) {
    					this.source.unlink (this.decodebin);
    					this.pipeline.remove (this.source);
    				}
    				if (ReplaySrc.uri_is_valid (uri)) {
    					var src = new ReplaySrc();
    					src.location = uri;
    					this.source = src;
    				}
    				else
    					this.source = Gst.Element.make_from_uri (Gst.URIType.SRC, uri, null);
    			});
    		}
    		
    		public Player (string name) {
    			GLib.Object (name : name);
    		}
    		
    		public Gst.StateChangeReturn set_state (Gst.State state) {
    			return this.pipeline.set_state (state);
    		}
    		
    		public string name { get; construct; }
    		
    		public string uri { get; set; } 
    		
    		public Gst.Element audio_sink { get; set; }
    		
    		public Gst.Element video_sink { get; set; }
    		
    		public Gst.Element source { get; set; }
    	}
    }
    
    
    

    external by BZHDeveloper modified Aug 19, 2017  14  0  1  0

    test utilities

    test utilities: ubuntu-utils.vala
    /* utils.vapi generated by valac UNKNOWN, do not modify. */
    
    namespace System {
    	[CCode (cheader_filename = "utils.h")]
    	public class Distribution : GLib.Object {
    		public Distribution ();
    		public string codename { get; construct; }
    		public string description { get; construct; }
    		public string id { get; construct; }
    		public string release { get; construct; }
    	}
    	[CCode (cheader_filename = "utils.h")]
    	public class Kernel : GLib.Object {
    		public class Version : GLib.Object {
    			public string to_string ();
    			public string kernel_type { get; private set; }
    			public uint major { get; private set; }
    			public uint micro { get; private set; }
    			public uint minor { get; private set; }
    			public uint revision { get; private set; }
    		}
    		public Kernel ();
    		public string to_string ();
    		public string architecture { owned get; }
    		public string name { owned get; }
    		public System.Distribution operating_system { get; private set; }
    		public string pc_name { owned get; }
    		public System.Kernel.Version version { owned get; }
    	}
    	[CCode (cheader_filename = "utils.h")]
    	public class Source : GLib.Object, Gee.Hashable<System.Source> {
    		public Source (System.SourceType source_type, string uri, string suite);
    		public string to_string ();
    		public bool active { get; set construct; }
    		public Gee.Set<string> components { get; }
    		public System.SourceType source_type { get; construct; }
    		public string suite { get; construct; }
    		public string uri { get; construct; }
    	}
    	[CCode (cheader_filename = "utils.h")]
    	public class SourceList : Gee.AbstractSet<System.Source> {
    		public SourceList ();
    		public override bool add (System.Source source);
    		public override void clear ();
    		public override bool contains (System.Source source);
    		public override Gee.Iterator<System.Source> iterator ();
    		public static System.SourceList open (string path) throws GLib.Error;
    		public override bool remove (System.Source source);
    		public override bool read_only { get; }
    		public override int size { get; }
    	}
    	[CCode (cheader_filename = "utils.h")]
    	public enum SourceType {
    		DEB,
    		DEB_SRC;
    		public string get_nick ();
    		public static System.SourceType from_nick (string nick);
    	}
    }
    
    
    • Public Snippets
    • Channels Snippets