Skip to content

Instantly share code, notes, and snippets.

@pestophagous
Last active September 2, 2021 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pestophagous/43c6d52a113fd0c1fe38 to your computer and use it in GitHub Desktop.
Save pestophagous/43c6d52a113fd0c1fe38 to your computer and use it in GitHub Desktop.
scratch pad of various commands to recall
(setq mybuild-command "go build -v main.go && go test -v ./...")
(setq mybuild-command "go test -v github.com/practicum/sandbox/...")
(setq mybuild-command "go build -v github.com/practicum/sandbox/executables/cli/... && go test -v github.com/practicum/sandbox/...")
; run the go build from "high" in the folder tree, so you see longer paths in the compiler errors:
(setq mybuild-dir "/Users/someone/")
; available because of edits I made in go-mode.el (see bottom)
; M-x j (open go definition in this same window)
; M-x jj (jump to go definition in other window)
; C-x C-<left> ; go back in `global-mark-ring'
; C-x C-<right> ; go forward in `global-mark-ring'
go-goto-imports ; Remember that C-x C-<left> will go back in `global-mark-ring'
; M-x dlv ; it should offer to invoke 'dlv debug'. accept that invocation.
; go get github.com/rogpeppe/godef
; (then put godef on PATH however you wish)
godef-jump-other-window ; Remember that C-x <LEFT> will take you back to the previous buffer
; IMPORTS and grouping. needs more investigation:
;
; http://stackoverflow.com/questions/38704769/golang-import-grouping-by-package
(defun my-go-mode-hook ()
; Call Gofmt before saving
(add-hook 'before-save-hook 'gofmt-before-save)
; Customize compile command to run go build
(if (not (string-match "go" compile-command))
(set (make-local-variable 'compile-command)
"go build -v && go test -v && go vet"))
; Godef jump key binding
(local-set-key (kbd "M-.") 'godef-jump)
) ; end defun
(add-hook 'go-mode-hook 'my-go-mode-hook)
; not in love with these yet. if i can get imports to respect groupings, then maybe:
;
; go-import-add
; go-remove-unused-imports ; <--- just takes too long, because it invokes compiler
; here is why 'M-x jj' works:
less go-mode_m-x_alias_004575eb128a.patch
diff --git a/go-mode.el b/go-mode.el
index cc6422b..e2f62d7 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -1588,6 +1588,15 @@ description at POINT."
(interactive "d")
(godef-jump point t))
+(defun jj (point)
+ (interactive "d")
+ (godef-jump point t))
+
+(defun j (point)
+ (interactive "d")
+ (godef-jump point nil))
+
+
(defun go--goto-line (line)
(goto-char (point-min))
(forward-line (1- line)))
# http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Replace.html
# next line is (bsd?) for MAC OS X:
git status -uno -s | while read mode file; do echo $mode $(stat -f "%m" $file) $file; done|sort #readmodefile
#next line works on (debian) linux:
git status -uno -s | while read mode file; do echo $mode $(stat -c "%Y" $file) $file; done|sort #readmodefile
# See more at: https://web.archive.org/web/20210902220828/https://freelinuxtutorials.com/net-tools-vs-iproute-cheat-sheet-ifconfig-vs-ip/
# COMPARING NET-TOOLS (old) VS. (newer) IPROUTE PACKAGE COMMANDS
# arp -a ip neigh
# arp -v ip -s neigh
# arp -s 192.168.1.1 1:2:3:4:5:6 ip neigh add 192.168.1.1 lladdr 1:2:3:4:5:6 dev eth1
# arp -i eth1 -d 192.168.1.1 ip neigh del 192.168.1.1 dev eth1
# ifconfig -a ip addr
# ifconfig eth0 down ip link set eth0 down
# ifconfig eth0 up ip link set eth0 up
# ifconfig eth0 192.168.1.1 ip addr add 192.168.1.1/24 dev eth0
# ifconfig eth0 netmask 255.255.255.0 ip addr add 192.168.1.1/24 dev eth0
# ifconfig eth0 mtu 9000 ip link set eth0 mtu 9000
# ifconfig eth0:0 192.168.1.2 ip addr add 192.168.1.2/24 dev eth0
# netstat ss
# netstat -neopa ss -neopa
# netstat -g ip maddr
# route ip route
#
# route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0 #(analog on next line)
# ip route add 192.168.1.0/24 dev eth0
#
# route add default gw 192.168.1.1 ip route add default via 192.168.1.1
git show 3a8b7e98b4:../SuperLabProject/src/SuperLab/SLCore/StimSubList.h # show file AT a certain version
import -pause 3 -window root screenshot.jpg
# (worked on mac el cap. May 2016.) fetch, pull, & track all branches:
git fetch --all ; git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | csh -xfs
# TODO: get rid of reliance on `csh` ? pipe to 'sh' instead?
# -x sets echo on. echo commands
# -f do not load startup files (start fast)
# -s read from stdin
# pipe to 'sh -x' seems to be a fine alternative
# searching for a stash that was stashed, but then dropped or cleared:
git log $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
# change commit date (before you push)
git filter-branch --env-filter \
"if test \$GIT_COMMIT = '228a5a2ccdfbf156ebaa780a97f467e0289def3b' -o \$GIT_COMMIT = 'da9b1a8ecc7fddb5e6ccb34961c86310dbd2e666'
then
export GIT_AUTHOR_DATE='`date`'
export GIT_COMMITTER_DATE='`date`'
sleep 83
unset GIT_AUTHOR_DATE
unset GIT_COMMITTER_DATE
fi" 101f6abae7ccab0ac^..HEAD
# then if you like what filter-branch did you can: rm -fr "$(git rev-parse --git-dir)/refs/original/"
# (otherwise if you try another filter-branch command: 'A previous backup already exists in refs/original/')
for i in *; do echo "demo. i found $i"; done
# endless loop:
COUNTER=0 ; while [ $COUNTER -lt 10 ]; do echo The counter is $COUNTER; sleep 1; done
# counting loop:
counter=1; while [ $counter -le 10 ]; do echo $counter; ((counter++)); done
# whiteboard cleanup
# https://gist.github.com/lelandbatey/8677901
# if you have a PNG then convert it to JPG first!
convert input.jpg -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 newversion.jpg
# shrink file size of pdf
# http://askubuntu.com/questions/207447/how-to-reduce-the-size-of-a-pdf-file
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
# http://stackoverflow.com/questions/2961635/using-awk-to-print-all-columns-from-the-nth-to-the-last
# will print all but two first columns:
awk '{$1=$2=""; print $0}' somefile
# "reverse" lsof (small d for top-level, big D for recurse whole dir)
lsof -b +D /Users/somebody/Documents/__4_0_copy/build/scons/scons-out/dbg/staging
# fix / repair / remedy / restore / resize too-large, too-big windows with edges offscreen
wmctrl -i -r 0x03c00001 -e 0,100,100,800,800 # you get the numeric id from wmctrl -l
# to make the window edges more easily grabbable:
# per: https://bugs.launchpad.net/ubuntu/+source/unity/+bug/1359350
/usr/share/themes/Ambiance/gtk-3.0/apps/unity.css
# -UnityDecoration-extents value from '28px 0 0 0' to '28px 10px 10px 10px'.
# grep grep grep grep (various grep usages)
grep -rn --include=\*.{cc,h} WordToFind . # grep only cc files and h files
grep --exclude-dir=html -rni WordToFind . # grep while skipping doxygen html directory
# CODE-POINT
# is a "concept", one of these:
# U+0048
# "multi-byte"
# means CHAR ! (simple char, not w_char)
# such that one "letter" might use two BYTES
# Linux and Mac use UTF-8.
# Windows uses UTF-16 (which has SURROGATE PAIRS).
# UTF-16:
# The improvement that UTF-16 made over UCS-2 is its ability to encode characters in planes 1–16, not just those in plane 0 (BMP: Basic Multilingual Plane). This was done by taking an unassigned portion of the 16 bit UCS-2 space.
# UTF-16 represents non-BMP characters (those from U+10000 through U+10FFFF) using a pair of 16-bit words, known as a surrogate pair. First 10000(base-16) is subtracted from the code point to give a 20-bit value. This is then split into two separate 10-bit values each of which is represented as a surrogate with the most significant half placed in the first surrogate. To allow safe use of simple word-oriented string processing, separate ranges of values are used for the two surrogates: 0xD800–0xDBFF for the first, most significant surrogate (marked brown) and 0xDC00-0xDFFF for the second, least significant surrogate (marked azure).
# For example, the character at code point U+10000 becomes the code unit sequence 0xD800 0xDC00, and the character at U+10FFFD, the upper limit of Unicode, becomes the sequence 0xDBFF 0xDFFD. Unicode and ISO/IEC 10646 do not, and will never, assign characters to any of the code points in the U+D800–U+DFFF range, so an individual code value from a surrogate pair does not ever represent a character.
# Because the most commonly used characters are all in the Basic Multilingual Plane, code is often not tested thoroughly with surrogate pairs. This leads to persistent bugs, and potential security holes, even in popular and well-reviewed application software.
# Q: How do I convert a UTF-16 surrogate pair such as <D800 DC00> to UTF-8? A one four byte sequence or as two separate 3-byte sequences?
# A: The definition of UTF-8 requires that supplementary characters (those using surrogate pairs in UTF-16) be encoded with a single four byte sequence. However, there is a widespread practice of generating pairs of three byte sequences in older software, especially software which pre-dates the introduction of UTF-16 or that is interoperating with UTF-16 environments under particular constraints. Such an encoding is not conformant to UTF-8 as defined. See UTR #26: Compatability Encoding Scheme for UTF-16: 8-bit (CESU) for a formal description of such a non-UTF-8 data format. When using CESU-8, great care must be taken that data is not accidentally treated as if it was UTF-8, due to the similarity of the formats. [AF] & [MD]
# Q: How do I convert an unpaired UTF-16 surrogate to UTF-8?
# A different issue arises if an unpaired surrogate is encountered when converting ill-formed UTF-16 data. By represented such an unpaired surrogate on its own as a 3-byte sequence, the resulting UTF-8 data stream would become ill-formed. While it faithfully reflects the nature of the input, Unicode conformance requires that encoding form conversion always results in valid data stream. Therefore a converter must treat this as an error. [AF]
touch bla.3.hmmm.txt
touch bla.12.hmmm.txt
touch bla.26.hmmm.txt
touch bla.28.hmmm.txt
touch bla.119.hmmm.txt
ls * | sort -nk 1.5 # sort the above files by their numeric content at pos 5 (1-based)
mysql --show-warnings --default-character-set=utf8 --user=licenseserver -p --database=this_database_name
# good old youtube rain:
# https://www.youtube.com/watch?v=mQ9OWMsJBTk
# remember how to set breakpoints into the win api, if needed:
# {,,Kernel32.dll}_GetProcessTimes@20
# {,,Kernel32.dll}_GetThreadTimes@20
# {,,Kernel32.dll}_QueryPerformanceCounter@4
# http://www.zachburlingame.com/2011/09/setting-a-debug-breakpoint-in-a-win32-api-in-visual-studio/
# another reference:
# http://bugslasher.net/2011/03/08/how-to-set-breakpoints-without-source-code-in-visual-studio-2010/
# ========================= DEBIAN SOURCE PACKAGES =====================================
# https://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html#s-sourcebuild
# 7.14 How do I build binary packages from a source package?
# If you prefer to do things manually, and don't want to use devscripts, follow this procedure:
# You will need all of
# foo_*.dsc,
# foo_*.tar.gz and
# foo_*.diff.gz to compile the source (note: there is no .diff.gz for some packages that are native to Debian).
# Once you have them (How do I install a source package?, Section
# 7.13), if you have the dpkg-dev package installed, the following
# command:
# dpkg-source -x foo_version-revision.dsc
# dpkg-buildpackage -rfakeroot -b # first cd into foo-version dir !!! <------ !!!
# dpkg -i ../foo_version-revision_arch.deb # to install the newly-built package(s).
query.getDatabaseQuery().getSQLString()
this.getClass().getName().endsWith("ponent")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment