Skip to content

Instantly share code, notes, and snippets.

View ttys3's full-sized avatar
💭
sad, ttyS0 has been taken by other user

ttys3

💭
sad, ttyS0 has been taken by other user
View GitHub Profile
@thanhminhmr
thanhminhmr / README.md
Last active March 28, 2025 12:34
Go doesn't have ternary, so created one...

go-ternary

Yes, I know—yet another attempt at bringing a ternary-like experience to Go. But hey, Go doesn’t have one, and I wasn’t around when the last million were written.

Why?

Because Go doesn't have a ternary operator, and according to the official FAQ, it likely never will. The reasoning? To prevent developers from writing "impenetrably complex expressions." But let's be real—poor coding practices exist in all forms. Instead of outright banning a useful construct, wouldn’t compiler warnings for overly complicated ternary expressions have been a more reasonable approach?

Since that's not happening, here’s go-ternary—because sometimes, a one-liner is just nicer than an if-else.

@thesamesam
thesamesam / xz-backdoor.md
Last active April 7, 2025 09:15
xz-utils backdoor situation (CVE-2024-3094)

FAQ on the xz-utils backdoor (CVE-2024-3094)

This is a living document. Everything in this document is made in good faith of being accurate, but like I just said; we don't yet know everything about what's going on.

Update: I've disabled comments as of 2025-01-26 to avoid everyone having notifications for something a year on if someone wants to suggest a correction. Folks are free to email to suggest corrections still, of course.

Background

@wijayaerick
wijayaerick / slog_console_handler.go
Last active July 27, 2024 08:05
Example ConsoleHandler for golang.org/x/exp/slog Logger
// ConsoleHandler formats slog.Logger output in console format, a bit similar with Uber's zap ConsoleEncoder
// The log format is designed to be human-readable.
//
// Performance can definitely be improved, however it's not in my priority as
// this should only be used in development environment.
//
// e.g. log output:
// 2022-11-24T11:40:20+08:00 DEBUG ./main.go:162 Debug message {"hello":"world","!BADKEY":"bad kv"}
// 2022-11-24T11:40:20+08:00 INFO ./main.go:167 Info message {"with_key_1":"with_value_1","group_1":{"with_key_2":"with_value_2","hello":"world"}}
// 2022-11-24T11:40:20+08:00 WARN ./main.go:168 Warn message {"with_key_1":"with_value_1","group_1":{"with_key_2":"with_value_2","hello":"world"}}
@Deminder
Deminder / inhibit-screensaver.lua
Last active June 17, 2023 12:09
Inhibit screensaver: mpv flatpak on GNOME wayland (workaround)
-- ~/.var/app/io.mpv.Mpv/config/mpv/scripts/inhibit-screensaver.lua
--
-- Workaround for inhibiting screensaver for io.mpv.Mpv flatpak (if not paused)
-- Issue: [vo/gpu/wayland] GNOME's wayland compositor lacks support for the idle inhibit protocol. This means the screen can blank during playback.
-- Until this is merged: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/111
-- Non-flatpak version: https://gist.github.com/crazygolem/a7d3a2d3c0cee5d072c0cbbbdee69286
--
-- NOTE: if mpv does not exit cleanly (e.g. with SIGKILL), an orphan process will keep inhibiting the screensaver
--
-- Arch: x86_64
@bert
bert / Makefile.example
Last active August 6, 2024 19:10
GTK4 Building applications
CC ?= gcc
PKGCONFIG = $(shell which pkg-config)
CFLAGS = $(shell $(PKGCONFIG) --cflags gtk4)
LIBS = $(shell $(PKGCONFIG) --libs gtk4)
GLIB_COMPILE_RESOURCES = $(shell $(PKGCONFIG) --variable=glib_compile_resources gio-2.0)
GLIB_COMPILE_SCHEMAS = $(shell $(PKGCONFIG) --variable=glib_compile_schemas gio-2.0)
SRC = exampleapp.c exampleappwin.c exampleappprefs.c main.c
BUILT_SRC = resources.c
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / reload udev rules without reboot
Last active November 28, 2023 06:45
How to reload udev rules without reboot?
# When i was faced with this warning in lvm when i run lvm command it works but it took
# WARNING: Device /dev/dm-20 not initialized in udev database even after waiting 10000000 microseconds.
# It look my problem is solved by reloading udev rules without reboot with this command:
udevadm control --reload-rules && udevadm trigger
@crazygolem
crazygolem / mpv-gnome-inhibit.lua
Last active January 29, 2025 15:29
Prevent the screen from blanking under GNOME+Wayland while a video is playing
--[[
Prevent the screen from blanking while a video is playing.
This script is a workaround for the GNOME+Wayland issue documented in the
[Disabling Screensaver] section of the mpv manual, and depends on
gnome-session-inhibit (usually provided by the gnome-session package) to set up
the inhibitors.
@shadmansaleh
shadmansaleh / colorscheme_generator.lua
Last active January 14, 2022 06:31
Genarates colorscheme for corrent highlights in neovim
-- This script has been succeeded by
-- https://github.com/shadmansaleh/colorsceme_generator.nvim
-- Thid script is nolonger maintained so please use the plugin version.
-- This file creates a colorscheme from aleady available colorscheme
-- Author : Shadman Saleh
-- Licence : You can do whatever you want with it but do provide proper cradit
-- Uses :
@wolfeidau
wolfeidau / embed.go
Created December 20, 2020 21:03
Golang embed with echo and tests
package server
import (
"embed"
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
@bmcbm
bmcbm / setup-nvdia-suspend.sh
Last active April 25, 2025 08:40
NVIDIA Suspend fix
# Use systemd for managing NVIDIA driver suspend in drivers ====>>> PRIOR to version 470 <<<=====
# https://download.nvidia.com/XFree86/Linux-x86_64/450.66/README/powermanagement.html
# https://forums.developer.nvidia.com/t/unable-to-set-nvidia-kernel-module-parameters/161306
# Please note: In Fedora Linux you may need to just install the xorg-x11-drv-nvidia-power pakage
# as sugested by @goombah88 in the comments below.
TMP_PATH=/var/tmp
TMPL_PATH=/usr/share/doc/nvidia-driver-460/
echo "options nvidia NVreg_PreserveVideoMemoryAllocations=1 NVreg_TemporaryFilePath=${TMP_PATH}" | sudo tee /etc/modprobe.d/nvidia-power-management.conf