Skip to content

Instantly share code, notes, and snippets.

View qxxt's full-sized avatar

qxxt

View GitHub Profile
@qxxt
qxxt / auto-indent.el
Created August 4, 2023 14:19
Automatically indent list of files and save them.
(let ((files (file-expand-wildcards "init-lisp/init-*.el")))
(mapc
(lambda (f)
(with-current-buffer (find-file-noselect f)
(indent-region (point-min) (point-max))
(save-buffer)))
files))
@qxxt
qxxt / packages-update-interactive
Last active July 29, 2023 08:48
Simple tools for upgrading emacs packages
;;; packages-update-interactive.el --- Simple tools for upgrading Emacs packages interactively
;; -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(require 'package)
(require 'time-date)
(defcustom package-refresh-interval 2
"DAYS until `package-refresh-contents'."
@qxxt
qxxt / arith.el
Last active July 21, 2023 20:31
Simple arithmetic parser on Emacs Lisp
(require 'calc-misc)
(defun last-elem (list)
(car (last list)))
(defun pow (num pow)
(if (floatp pow)
(error "No float"))
(if (zerop pow)
@qxxt
qxxt / goimports.el
Created July 8, 2023 07:42
Simple hack for calling goimports on buffer on Emacs.
(defun goimports-buffer ()
"Format current buffer with goimports."
(interactive)
(let ((gofmt-command-bak gofmt-command)
(gofmt-args-bak gofmt-args))
(setq gofmt-command "goimports"
gofmt-args nil)
(with-current-buffer (current-buffer)
(gofmt))
(setq gofmt-command gofmt-command-bak
package main
import (
"bufio"
"crypto/tls"
"fmt"
"log"
"net"
"os"
"strings"
@qxxt
qxxt / main_test.go
Last active January 12, 2022 02:00
Parsing hosts Golang
// BSD Zero Clause License
//
// Copyright (c) 2022 qxxt
//
// Permission to use, copy, modify, and/or distribute this software for
// any purpose with or without fee is hereby granted.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
@qxxt
qxxt / main.go
Created January 8, 2022 15:15
Golang get the last/first n line of a bytes
// Get first 10th line
// x := trimByteLine(b, 10, false)
//
// Get last 20th line
// y := trimByteLine(b, 20, true)
func trimByteLine(b []byte, maxL int, reverse bool) []byte {
line := 0
byteLen := len(b) - 1
if reverse {
@qxxt
qxxt / main.go
Created January 6, 2022 19:00
Reading Large Bytes in Reverse Line Order [Golang]
// https://go.dev/play/p/qKDFxiJQAfF
package main
import (
"fmt"
)
func main() {
someBytes := []byte(`Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
@qxxt
qxxt / 01-clamp-mixin.scss
Last active November 1, 2022 15:28
A fluid typography + responsive typography fallback on SASS
@mixin clamp-calc (
$property,
$min-size,
$max-size,
$min-screen-width: 320px,
$max-screen-width: 1280px
) {
$min-screen-width-rem: $min-screen-width / 16px * 1rem;
$max-screen-width-rem: $max-screen-width / 16px * 1rem;