Skip to content

Instantly share code, notes, and snippets.

@Pagliacii
Pagliacii / config.el
Created Mar 24, 2021
Auto-switch to relative line number if activating the visual mode. Doom Emacs.
View config.el
;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type 'absolute)
;; Auto-switch to relative line number if entering the visual mode
(add-hook! 'evil-visual-state-entry-hook #'menu-bar--display-line-numbers-mode-relative)
(add-hook! 'evil-visual-state-exit-hook #'menu-bar--display-line-numbers-mode-absolute)
@Pagliacii
Pagliacii / reverse-proxy.org
Last active Mar 10, 2021
Basic Nginx reverse proxy to forwarding requests from host to virtual machine local server.
View reverse-proxy.org

This idea came from I am trying to access the local server inside a virtual machine from the browser on the host machine. Maybe you would ask why did I not use the Nat network port forwarding? The primary reason is that I want to keep my config files to be consistent for all machines. So I don’t need to change its contents when using those configs on virtual machines. *Click* Nice

@Pagliacii
Pagliacii / insert-file-content.org
Last active Feb 21, 2021
Quick insert file content into .org file. You can specify a history version of the file!
View insert-file-content.org
#+name: show-file-content
#+header: :exports none :tangle no :results value raw
#+header: :var path="./README.org" :var revision="HEAD"
#+header: :var start=1 :var end=-1
#+begin_src emacs-lisp
(substring
  (shell-command-to-string
    (format "git show %s:%s | sed -n '%d,%sp;d'"
            revision
@Pagliacii
Pagliacii / process_exists.ahk
Created Feb 9, 2021
This function checks if the specified name process exists and returns the unique ID (HWND) of the first matching window.
View process_exists.ahk
processExist(name) {
DetectHiddenWindows, On
existed := WinExist("ahk_exe" name)
DetectHiddenWindows, Off
Return existed
}
@Pagliacii
Pagliacii / add_menu_items.ahk
Created Feb 9, 2021
Add custom menu items to the AHK tray menu, which lets you can edit the current running script with your favored editor.
View add_menu_items.ahk
#NoEnv ; Recommended for performance and compatibility with future AutoHotKey releases.
SendModeInput ; Recommended for new scripts due to its superior speed and reliability.
#Persistent ; Keeps a script permanently running (that is, until the user closes it or ExitApp is encountered.
insertMenuItemsBeforeStandard()
;
; This functions inserts your menu items before the standard menu
;
insertMenuItemsBeforeStandard() {
@Pagliacii
Pagliacii / which_command.ps1
Last active Feb 21, 2021
A which command implementation in PowerShell
View which_command.ps1
Function WhichCommand(
[String]$cmd
) {
try {
$Command = Get-Command -ErrorAction Stop $cmd
}
catch {
Write-Host -ForegroundColor Red ("{0} not found" -f $cmd)
Return
}
@Pagliacii
Pagliacii / falsehoods-programming-time-list.md
Created Jan 15, 2021 — forked from timvisee/falsehoods-programming-time-list.md
Falsehoods programmers believe about time, in a single list
View falsehoods-programming-time-list.md

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@Pagliacii
Pagliacii / SendUnicode.ahk
Last active Nov 14, 2020
This function pops up the input box to ask the user to enter some Unicode to input the corresponding character into the current input area.
View SendUnicode.ahk
getUnicodeFromInputBox()
{
Sleep, 10
InputBox, Code, AutoHotkey, Enter the Unicode, , 320, 112
Send, {U+%Code%}
}
; Binding to CapsLock+x
CapsLock & x::getUnicodeFromInputBox()
@Pagliacii
Pagliacii / proxy.sh
Last active Feb 7, 2021
A shell script to run command behind the proxy.
View proxy.sh
#!/usr/bin/env bash
# 0. (Optional) Rename this script name to "proxy"
# 1. Replace the <protocol>, <ip> and <port> to the actual value of your proxy respectively.
# 2. Run this command `sudo chmod +x <path to proxy>` to make sure this script is executable.
# 3. Add this script path to the PATH environment variable.
# 4. Run your actual command like this: `proxy ping www.google.com`.
export ALL_PROXY=<protocol>://<ip>:<port>
export HTTP_PROXY=<protocol>://<ip>:<port>
@Pagliacii
Pagliacii / AutoHotkey.ahk
Created Jul 31, 2020
Preventing the left mouse button double-click in the small period, because the microswitch of my left mouse button has some damages. Base on the AutoHotkey script.
View AutoHotkey.ahk
debounceLeftClick()
{
Sleep, 10
if !GetKeyState("LButton", "P")
{
n := 1
BlockInput, On
Loop {
Sleep, 10
if (n++ > 9)