Skip to content

Instantly share code, notes, and snippets.

View Wilfred's full-sized avatar

Wilfred Hughes Wilfred

View GitHub Profile
Segmentation fault Tue Sep 5 19:23:15 2017
/home/wilfred/Downloads/pharo6.1-64/bin/lib/pharo/5.0-201707201942/pharo
Pharo VM version: 5.0-201707201942 Thu Jul 20 20:40:54 UTC 2017 gcc 4.6.3 [Production Spur 64-bit VM]
Built from: CoInterpreter VMMaker.oscog-eem.2254 uuid: 4f2c2cce-f4a2-469a-93f1-97ed941df0ad Jul 20 2017
With: StackToRegisterMappingCogit VMMaker.oscog-eem.2252 uuid: 2f3e9b0e-ecd3-4adf-b092-cce2e2587a5c Jul 20 2017
Revision: VM: 201707201942 https://github.com/OpenSmalltalk/opensmalltalk-vm.git $ Date: Thu Jul 20 12:42:21 2017 -0700 $ Plugins: 201707201942 https://github.com/OpenSmalltalk/opensmalltalk-vm.git $
Build host: Linux testing-gce-74d10329-bbfd-42e5-8995-b0e3a68c73cb 3.13.0-115-generic #162~precise1-Ubuntu SMP Fri Mar 24 16:47:06 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
plugin path: /home/wilfred/Downloads/pharo6.1-64/bin [default: /home/wilfred/Downloads/pharo6.1-64/bin/lib/pharo/5.0-201707201942/]
@Wilfred
Wilfred / whileMatchesDo.st
Created August 27, 2017 16:38
pharo conditionals example
whileMatches: aStream do: aBlock
"Execute block, passing in this instance, for every match in stream.
Be extra careful about successful matches which consume no input.
After those, make sure to advance or finish if already at end."
| wholeMatch reachedEnd |
reachedEnd := false.
[ self searchStream: aStream ]
whileTrue: [ wholeMatch := self subexpression: 1.
(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 / 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 / example.el
Created June 2, 2017 16:00
Confusing Emacs argument parsing with cl-defun
(cl-defun wh/foo (arg1 arg2 &key (kwarg1 t))
(list arg1 arg2 kwarg1))
;; We've forgotten arg2, but we get the error:
;; (error "Keyword argument 2 not one of (:kwarg1)")
(wh/foo 1 :kwarg1 2)
;; Instead, it would be clearer to say
;; "Expected a keyword argument (one of (:kwargs1)) but got 1"
@Wilfred
Wilfred / dashtest2.el
Last active August 10, 2017 08:45
function calls vs aliases
;;; dashtest2.el --- benchmarking dash -*- lexical-binding: t -*-
(defun -first-item-fn (lst)
(car lst))
(defalias '-first-item-alias 'car)
(defun wh/benchmark ()
(interactive)
(let ((items (-repeat 20 'foo)))
@Wilfred
Wilfred / calculate_3.el
Last active June 27, 2017 20:52
Exploring programmatically generated elisp with suggest.el
;; given 1, how do we calculate 3?
(length (key-description (char-to-string 1)))
(length (key-description (string 1)))
(1+ (1+ 1))
(length (number-to-string (ftruncate 1)))
(length (number-to-string (fround 1)))
(length (number-to-string (ffloor 1)))
(length (number-to-string (fceiling 1)))
(length (number-to-string (float 1)))
(length (number-to-string (sqrt 1)))
(defun get-faces (pos)
"Get the font faces at POS."
(remq nil
(list
(get-char-property pos 'read-face-name)
(get-char-property pos 'face)
(plist-get (text-properties-at pos) 'face))))
@Wilfred
Wilfred / cached_instances.py
Created September 17, 2013 17:44
Ensure no class gets instantiated twice with the same arguments.
import copy
def make_hash(obj):
"""Make a hash from an arbitrary nested dictionary, list, tuple or
set.
"""
if isinstance(obj, set) or isinstance(obj, tuple) or isinstance(obj, list):
return hash(tuple([make_hash(e) for e in obj]))
@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]);
}
}