Skip to content

Instantly share code, notes, and snippets.

Avatar
😸

Chris Barrett chrisbarrett

😸
View GitHub Profile
View sexp.go
// Compiler from Go types to an S-Expression representation.
//
// The output a drop-in replacement for the Elisp JSON parser output, and can be
// consumed directly with `read`.
package main
import (
"strconv"
"strings"
@chrisbarrett
chrisbarrett / Learn Emacs in 7 days.el
Last active Feb 9, 2020
Paste into the scratch buffer and `M-x eval-buffer` to begin the journey.
View Learn Emacs in 7 days.el
(url-copy-file "http://ulrichdesign.ca/wp-content/uploads/2011/11/YOU-LACK-discipline.jpg"
"~/discipline.jpg")
(defun you-lack-discipline ()
(interactive)
(insert-image (create-image "~/discipline.jpg")))
(dolist (k '([up] [left] [down] [right]))
(global-set-key k 'you-lack-discipline))
@chrisbarrett
chrisbarrett / cal-usage.el
Created Jul 25, 2013
Usage example of `cal`
View cal-usage.el
; Infix algebra in Lisp because yolo
(cal
sin(2) * ([1,2,3] + [4,5,6])
)
; => [0.174497483513, 0.244296476918, 0.314095470323]
@chrisbarrett
chrisbarrett / cal.el
Last active Dec 20, 2015
Macro for writing math expressions with infix syntax. Requires calc, smartparens, dash and s.
View cal.el
(defmacro cal (&rest expression)
"Evaluate algebraic EXPRESSION using calc."
(let*
((expr (with-temp-buffer
(lisp-mode)
(insert (->> expression
(-map 'pp-to-string)
(apply 'concat)
(s-replace (rx space) "")))
;; Unpack unquote forms applied by the lisp reader.
@chrisbarrett
chrisbarrett / c_obj_usage.c
Last active Mar 24, 2017
C Array object usage example
View c_obj_usage.c
#include <stdio.h>
#include "array_obj.h"
int main()
{
// Allocate an array of 5 ints.
Array_new(xs, int, 5);
// Initialize elements using their indices.
xs.each_i(^(int x, int i) { xs.set(i, i); });
// Print elements.
@chrisbarrett
chrisbarrett / array_obj.h
Last active Mar 24, 2017
C object using blocks language extension
View array_obj.h
#include <assert.h>
#include <stdlib.h>
#define Array_new(name, type, len) \
typedef void(^name##_each)(type); \
typedef void(^name##_each_i)(type, int); \
\
struct { \
type *data; \
size_t length; \
@chrisbarrett
chrisbarrett / ruby-hideshow.el
Last active Oct 16, 2019
Ruby code folding using hideshow
View ruby-hideshow.el
(eval-after-load "hideshow"
'(add-to-list 'hs-special-modes-alist
`(ruby-mode
,(rx (or "def" "class" "module" "{" "[")) ; Block start
,(rx (or "}" "]" "end")) ; Block end
,(rx (or "#" "=begin")) ; Comment start
ruby-forward-sexp nil)))
@chrisbarrett
chrisbarrett / emr-binding.el
Created Apr 16, 2013
An example of an EMR binding
View emr-binding.el
;;; Let-bind variable
(emr-declare-action emr-extract-to-let emacs-lisp-mode "let-bind"
:predicate (not (or (emr--looking-at-definition?)
(emr--looking-at-decl?)
(emr--looking-at-let-binding-symbol?)))
:description "let")
View init.el
;; Initialize packages.
(require 'package)
(dolist (source '(("melpa" . "http://melpa.milkbox.net/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")))
(add-to-list 'package-archives source))
(package-initialize)
(unless package-archive-contents