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.
View auto-indent.el
(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
View packages-update-interactive
;;; 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
View arith.el
(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.
View goimports.el
(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
View gist:4313ff856891e0b3db35524ca7bc4de4
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
View main_test.go
// 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
View main.go
// 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]
View main.go
// 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
View 01-clamp-mixin.scss
@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;