Skip to content

Instantly share code, notes, and snippets.

View chrisbarrett's full-sized avatar
🦈

Chris Barrett chrisbarrett

🦈
View GitHub Profile
;; 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
@chrisbarrett
chrisbarrett / emr-binding.el
Created April 16, 2013 11:07
An example of an EMR binding
;;; 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")
@chrisbarrett
chrisbarrett / ruby-hideshow.el
Last active October 16, 2019 13:33
Ruby code folding using hideshow
(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 / array_obj.h
Last active March 24, 2017 09:41
C object using blocks language extension
#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 / c_obj_usage.c
Last active March 24, 2017 09:41
C Array object usage example
#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 / cal.el
Last active December 20, 2015 05:08
Macro for writing math expressions with infix syntax. Requires calc, smartparens, dash and s.
(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 / cal-usage.el
Created July 25, 2013 01:15
Usage example of `cal`
; Infix algebra in Lisp because yolo
(cal
sin(2) * ([1,2,3] + [4,5,6])
)
; => [0.174497483513, 0.244296476918, 0.314095470323]
@chrisbarrett
chrisbarrett / Learn Emacs in 7 days.el
Last active February 9, 2020 06:13
Paste into the scratch buffer and `M-x eval-buffer` to begin the journey.
(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))
// 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"