Skip to content

Instantly share code, notes, and snippets.

View Miqueas's full-sized avatar
👍
Average nerd

Miqueas Miqueas

👍
Average nerd
View GitHub Profile
@Miqueas
Miqueas / GtkToggleCSD.lua
Last active January 31, 2021 03:20
[Lua + Gtk 3] Switches between enabling/disabling the CSD
local lgi = require("lgi")
local Gtk = lgi.Gtk
local GObject = lgi.GObject
local Example = lgi.package("Example")
Example:class("App", Gtk.Application)
Example:class("Header", Gtk.HeaderBar)
Example:class("Window", Gtk.ApplicationWindow)
function Example.App:_init( ... )
@Miqueas
Miqueas / GObjectSubclassing.lua
Last active December 28, 2023 05:27
[Lua + GObject] Subclassing
local lgi = require("lgi")
local GObject = lgi.require("GObject", "2.0")
-- Our new class inherits directly from GObject
local Person = GObject.Object:derive("Person")
-- Class constructor, used by GObject. This function
-- is called one time and is for register our class.
-- Inside this function we can do some things like
-- create some properties, signals and override some
@Miqueas
Miqueas / GioDirectoryRecursive.lua
Last active July 10, 2021 08:16
[Lua + Gio] Reads directory content recursively
local lgi = require("lgi")
local Gio = lgi.require("Gio", "2.0")
local Content = {}
local Dir = ""
function ReadDir(Path, Tab, Indent)
local file = Gio.File.new_for_path(Path)
local enum = file:enumerate_children("standard::name", Gio.FileQueryInfoFlags.NONE)
local path = file:get_path() .. "/"
@Miqueas
Miqueas / GObjectCanonicalPropertiesNames.lua
Created January 28, 2021 03:42
[Lua + GObject] Canonical GObject properties names
-- From my other Gist: https://gist.github.com/M1que4s/9f1eec873f87cb02238bd6de2d435705
local lgi = require("lgi")
local GObject = lgi.require("GObject", "2.0")
local Canonical = GObject.Object:derive("Canonical")
function Canonical:_class_init(Class)
function Class:set_property(id, val, pspec)
if id == 1 then self.priv["prop-a"] = val:get_string()
elseif id == 2 then self.priv["prop-b"] = val:get_string()
@Miqueas
Miqueas / GLibUserDirectories.lua
Last active January 31, 2021 21:57
[Lua + GLib] User directories
local lgi = require("lgi")
local GLib = lgi.require("GLib", "2.0")
--[[ Explanation
Some multimedia apps (music players, for example) that uses GLib and related libraries (Gtk,
GObject, GStreamer, etc...) commonly auto-detects user directories that contains specific
things like music, videos, pictures and documents. That's nice, but... How is it done?
Well... Here's the answer:
@Miqueas
Miqueas / GioSubprocess.lua
Last active March 13, 2021 04:54
[Lua + Gio] Subprocess
local lgi = require("lgi")
local Gio = lgi.require("Gio", "2.0")
--[[ Arguments:
1 (table): The first element is the commandline process name, the rest are commandline arguments
2 (table): A list of Gio.SubprocessFlags
]]
local sub = Gio.Subprocess.new(
{ "echo", "Hello", "world!" },
{ Gio.SubprocessFlags.NONE, Gio.SubprocessFlags.STDOUT_PIPE }
@Miqueas
Miqueas / Bytes.go
Created February 10, 2021 14:43
[Go] Gets the size (in bytes) of a file
package main
// We need only this modules
import (
"os" // For open the file
"fmt" // For print data
"io/ioutil" // For read data
)
// A little function for error checking
@Miqueas
Miqueas / GistsScrapper.go
Last active February 11, 2021 05:27
[Go] Basic scrapper example
package main
import (
// For the exit status
OS "os"
// For printing
Fmt "fmt"
// For commandline arguments
Flag "flag"
// For requests
@Miqueas
Miqueas / Flags.go
Created February 10, 2021 20:57
[Go] Basic example of using commandline arguments
package main
import (
// For printing
Fmt "fmt"
// For arguments parsing
Flag "flag"
)
// Defines a flag for the commandline. Refers to the doc for details:
@Miqueas
Miqueas / JSON.go
Created February 11, 2021 03:14
[Go] Decode and encode JSON
package main
import (
Fmt "fmt"
Str "strings"
Bytes "bytes"
JSON "encoding/json"
)
// Our JSON string to decode