Skip to content

Instantly share code, notes, and snippets.

@sylt
sylt / e.sh
Last active March 23, 2024 17:51
Single bash alias/function for handling emacsclient
# Put this in your ~/.bash_aliases script file
# This function/alias behaves how I wished 'emacsclient -a '' -r -n' would have behaved:
# * Starts an emacs server/window if there is none. Any supplied file(s) are opened in the new window.
# * Otherwise, the supplied file(s) are opened in the already existing emacs window.
function e() {
emacsclient -q -a "sh -c \"emacs -e server-start $@ &\"" --no-wait $@
}
@sylt
sylt / prettyDate.js
Created January 29, 2024 11:01
Date as YYYY-MM-DD HH:MM:SS.sss as local time (ISO 8601)
function prettyDate(date) {
const dateStr = [`${date.getFullYear()}`, `${date.getMonth() + 1}`, `${date.getDate()}`]
.map((part) => part.padStart(2, '0'))
.join('-');
const timeStr = [`${date.getHours()}`, `${date.getMinutes()}`, `${date.getSeconds()}`]
.map((part) => part.padStart(2, '0'))
.join(':');
const fractionStr = `${date.getMilliseconds()}`.padStart(3, '0');
return `${dateStr} ${timeStr}.${fractionStr}`;
@sylt
sylt / ncurses_mouse_movement.c
Created November 22, 2015 20:17
Mouse movement example for NCURSES
// I had problems getting mouse movement events working in ncurses, but after
// some research, it seems as if this is how you can do it. The magic is in the
// printf("\033[?1003h\n") which was the missing piece in the puzzle for me
// (see console_codes(4) for more information). 1003 means here that all events
// (even position updates) will be reported.
//
// This seems to work in at least three X-based terminals that I've tested:
// xterm, urxvt and gnome-terminal. It doesn't work when testing in a "normal"
// terminal, with GPM enabled. Perhaps something for the next gist version? :)
@sylt
sylt / vba-joy.c
Created October 12, 2014 12:42
Program for generating joystick configuration for Visual Boy Advance 1.8.0 on Linux
// Program to generate joystick configuration for Visual Boy Advance
// 1.8.0 on Linux. I know there existed another program before to do
// this, but I could not find it so I wrote this.
//
// It has worked for me, but it might not work for you. Compile with:
// gcc -o vba-joy vba-joy.c -Wall -Wextra $(pkg-config --libs sdl) -std=c99
//
// Usage: ./vba-joy [joystickIndex]
#include <ctype.h>