Skip to content

Instantly share code, notes, and snippets.

View Wilfred's full-sized avatar

Wilfred Hughes Wilfred

View GitHub Profile
@Wilfred
Wilfred / remove-props.el
Created March 25, 2017 00:12
remove text properties
;; Loosely based on `erc-remove-text-properties-region'.
(defun wh/remove-text-properties-region ()
"Remove all text properties from the current buffer."
(interactive)
(let ((inhibit-read-only t))
(set-text-properties (point-min) (point-max) nil)))
@Wilfred
Wilfred / dashtest.el
Last active September 18, 2019 11:21
dolist vs mapcar
;;; dashtest.el --- benchmarking dash -*- lexical-binding: t -*-
(defmacro --map-mapcar (form list)
(declare (debug (form form)))
`(mapcar (lambda (it) ,form) ,list))
(defmacro --map-loop (form list)
(declare (debug (form form)))
(let ((result-sym (make-symbol "result")))
`(let (,result-sym)
@Wilfred
Wilfred / arrays.c
Created January 3, 2017 23:18
looping over array in C
void print_elements(int* arr, int arr_length) {
for (int i = 0; i < arr_length; i++) {
printf("arr[i] = %d\n", arr[i]);
}
}
@Wilfred
Wilfred / Cargo.toml
Last active January 21, 2021 17:51
Calling a C function from Rust
[package]
name = "remacs"
version = "0.1.0"
authors = ["Wilfred Hughes <me@wilfred.me.uk>"]
[lib]
crate-type = ["staticlib"]
(defun racer--slurp (path)
"Return the contents of file PATH as a string."
(with-temp-buffer
(insert-file-contents-literally path)
(buffer-string)))
@Wilfred
Wilfred / foo.js
Created October 27, 2016 23:38
return inside finally
function foo() {
try {
throw new Error();
} finally {
return 42;
}
}
// Logs 42
console.log(foo());
@Wilfred
Wilfred / so.css
Created October 12, 2016 13:34
Hide notifications and network updates on SO: stylish configuration
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("stackoverflow.com") {
#hot-network-questions {
display: none;
}
.community-bulletin {
display: none;
}
(require 'dash)
(defun wh/ido-switch-buffer-with-filename ()
"Switch to a buffer with ido, including the filename in the prompt."
(interactive)
(let* ((bufs (buffer-list))
(bufs-with-paths
(--map (with-current-buffer it
(if (buffer-file-name)
(format "%s <%s>" (buffer-name) (buffer-file-name))
class Parent(object):
def __init__(self):
# I inherit from object, so I don't need to call:
# super().__init__()
# right? If Python only had single inheritance, that would be
# true. I could see, statically, what method is next in the
# lookup path.
pass
@Wilfred
Wilfred / text.md
Created May 8, 2016 15:17
TCO and unbounded stacks

Suppose we want to write a filter function in Scheme:

;; Return a list containing all the ITEMS where PRED
;; returns #t.
(define (my-filter items pred)
  (if (pair? items)
      (if (pred (car items))
          (cons (car items) (my-filter (cdr items) pred))
          (my-filter (cdr items) pred))

'()))