Skip to content

Instantly share code, notes, and snippets.

View dwcoates's full-sized avatar

Dodge Coates dwcoates

  • Chess.com
  • New York, NY
View GitHub Profile
@dwcoates
dwcoates / build-gcc.sh
Created December 29, 2021 22:43 — forked from jeetsukumaran/build-gcc.sh
Build and Install GCC Suite from Scratch
#! /bin/bash
GCC_VERSION="5.2.0"
WORKDIR="$HOME/src/"
INSTALLDIR="/platform"
## NOTE: XCode must be installed (through App Store) and the following run to install command-line tools.
## THIS IS IMPORTANT! Among other things, it creates '/usr/include' and installs the system header files.
# xcode-select --install
@dwcoates
dwcoates / org-latex-export-region-to-pdf.el
Created January 27, 2018 19:55
A function for cleanly exporting current active region to pdf. Unlike normal exporting, prompts for filename and declutters output.
(defun org-latex-export-region-to-pdf (beg end &optional no-declutter)
"Export the current region to pdf, prompting for output filename.
This can be done by narrowing region, but it's a bit slow, and
the output is ugly and cluttered. More importantly, it also
writes the pdf file for the region using the name of the
original file, which is obviously annoying.
with NO-DECLUTTER non-nil, don't declutter the pdf output."
(interactive (if (region-active-p)
@dwcoates
dwcoates / eshell-swap-prompts.el
Created December 14, 2017 05:39
Swap between minimal/cwd+git eshell prompts.
(defun eshell-default-prompt-function ()
(interactive)
(concat
(system-name) ":"
(propertize (car (last (split-string (pwd-repl-home (eshell/pwd)) "/"))) 'face
`(:foreground "#cdcd00"))
(or (curr-dir-git-branch-string (eshell/pwd)))
(propertize "# " 'face 'default)))
(defun eshell-short-prompt-function ()
@dwcoates
dwcoates / track-eshell.el
Created December 13, 2017 19:51
Track eshell sessions dwim-style
(defvar eshell-previous-buffer nil)
(defvar eshell-session-alist nil)
(defun dwc-switch-to-terminal (arg)
(interactive "p")
(if (eq arg 4)
(progn
(let ((sesh (alist-get (current-buffer) eshell-session-alist)))
(if sesh
(progn
@dwcoates
dwcoates / sgml-copy-or-kill-element.el
Last active December 1, 2017 19:52
Copy or kill HTML element at point in Emacs
(defun sgml-copy-or-kill-element (arg)
(interactive "P")
(let ((cut-tag (lambda ()
(let ((beg (point))
(end (save-excursion (sgml-skip-tag-forward 1)
(point))))
(kill-ring-save beg end)
(when arg
(delete-region beg end))))))
(save-excursion (if (sgml-beginning-of-tag)
@dwcoates
dwcoates / repl.el
Last active December 15, 2017 00:53
elisp code for interactive programming in python
(defvar python-shell-send-code-step-on-function nil
"If non-nil, step sending a function to the python interpreter.")
(defun python-shell-step-after-defun ()
(forward-paragraph)
;; when at last paragraph, don't step to beginning of "next" paragraph
(unless (equal (line-number-at-pos (point))
(progn (forward-paragraph) (line-number-at-pos (point))))
(backward-paragraph)
(forward-line 1)))
@dwcoates
dwcoates / repl.py
Created June 7, 2017 18:29
some elisp code for interactive pythoning
(defvar python-shell-send-code-step-on-function nil
"If non-nil, step sending a function to the python interpreter.")
(defun python-shell-step-after-defun ()
(forward-paragraph)
;; when at last paragraph, don't step to beginning of "next" paragraph
(unless (equal (line-number-at-pos (point))
(progn (forward-paragraph) (line-number-at-pos (point))))
(backward-paragraph)
(forward-line 1)))
@dwcoates
dwcoates / python-send-code-dwim.el
Last active December 15, 2017 01:01
Convenient function for sending python code to shell
(defvar python-shell-send-code-step-on-function nil
"If non-nil, step sending a function to the python interpreter.")
(defun python-shell-step-after-defun ()
(forward-paragraph)
;; when at last paragraph, don't step to beginning of "next" paragraph
(unless (equal (line-number-at-pos (point))
(progn (forward-paragraph) (line-number-at-pos (point))))
(backward-paragraph)
(forward-line 1)))
attrs = ["other_exceptions",
"deletes",
"encode_exceptions",
"english_count",
"total_fails",
"total_parses",
"file_count"]
history = dict(zip(attrs, [0] * len(attrs)))
@dwcoates
dwcoates / read_json.py
Last active March 11, 2017 19:38
for pops
import json
import gzip
import io
def read_json(filename, gz=None):
"""
Read in comma-newline delimited json files encoded in latin-1.
"""
_io = gzip.io if gz else io