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 / appendQuery.nim
Created March 15, 2022 14:40
[Nim] Simple operator for `Uri` to help append queries
import std/uri
proc `?+`*(url: Uri, ql: openArray[tuple[string, string]]): Uri =
var qs = @ql
if url.query.len() != 0:
for k, v in url.query.decodeQuery():
qs.add( (k, v) )
return url ? qs
@Miqueas
Miqueas / utils.lua
Last active March 8, 2022 15:59
[Lua] Small set of some OS and filesystem utilities
-- Determines if this script is running on Windows
os.is_win = package.config:sub(1, 1) == "\\"
-- Return the path to the temp dir
function os.get_temp_dir()
if os.is_win then
-- Windows. Same as:
-- os.getenv("TEMP")
-- os.getenv("TMP")
return os.getenv("UserProfile") .. "/AppData/Local/Temp"
@Miqueas
Miqueas / Gtk4Example.nim
Created October 16, 2021 04:01
[Nim] Simple GTK 4 example
import gintro/gobject
import gintro/gio
import gintro/gtk4
proc activate(app: gtk4.Application) =
let win = gtk4.newApplicationWindow(app)
win.defaultSize = (800, 600)
win.present()
let app = gtk4.newApplication("org.gtk.example")
@Miqueas
Miqueas / arrays.c
Last active October 14, 2021 04:26
[C] Cursed or interesting?
#include <stdio.h>
/* Explanation
Arrays in C are just pointers. So, basically they points
to the address of the first element and when we indexing
using [], we're just performing an addition and the order
doesn't matter at all for that operator in C. Also, the
array identifier is also the first element itself, as I
said, is just a pointer.
@Miqueas
Miqueas / Problem.c
Last active October 14, 2021 04:52
The 3x + 1 problem
#include <stdio.h>
#include <stdlib.h>
int problem(int n) {
if (n == 1) {
printf("End\n");
return n;
} else if ((n % 2) == 0) {
printf("Even: %d\n", n);
return problem(n / 2);
@Miqueas
Miqueas / Guess.py
Created April 6, 2021 16:44
[Python] Classic guessing game
from random import randint as rand
MagicNum = rand(1, 100)
Lives = 3
print("Guess the number!")
print("Enter your choice:")
choice = int(input("> "))
while True:
@Miqueas
Miqueas / Password.vala
Last active March 17, 2021 04:41
[Vala + Gtk 3] Generic password window
// From my other gist: https://gist.github.com/Miqueas/c52a7f6684036030572a66d1f58ba574
Gtk.Grid build_grid() {
var grid = new Gtk.Grid() {
visible = true,
column_spacing = 6,
row_spacing = 6,
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
};
@Miqueas
Miqueas / Password.c
Last active March 17, 2021 02:03
[C + Gtk 3] Generic password window
#include <gtk/gtk.h>
GtkWidget *user, *pass, *confirm, *clear, *check;
GRegex *patt;
GtkWidget* build_grid() {
GtkWidget *label;
GtkWidget *grid = g_object_new(
GTK_TYPE_GRID,
@Miqueas
Miqueas / Guess.lua
Last active February 24, 2021 18:25
[Lua] Classic guessing game
-- Generates a constantly-changin number
-- Note: Lua 5.4 don't need this
math.randomseed(os.time())
local MagicNum = math.random(100)
local Lives = 3
print ("Guess the number!")
print ("Enter your choice:")
io.write("> ")
@Miqueas
Miqueas / App.rb
Created February 17, 2021 23:27
[Ruby + GTK 3] Simple GTK app
require "gtk3"
app = Gtk::Application.new "com.example.ruby-gtk3", :FLAGS_NONE
app.signal_connect :activate do |app|
head = Gtk::HeaderBar.new
head.visible = true
head.title = "Ruby GTK+ 3 example"
head.show_close_button = true