Skip to content

Instantly share code, notes, and snippets.

View Wilfred's full-sized avatar

Wilfred Hughes Wilfred

View GitHub Profile
@Wilfred
Wilfred / gist:5125727
Created March 9, 2013 20:59
file path to string in elisp
(defun open-file (path)
"Open the file PATH and return a string of its contents."
(with-temp-buffer
(insert-file-contents-literally path)
(buffer-substring (point-min) (point-max))))
@Wilfred
Wilfred / replace-nested-list.el
Last active December 15, 2015 05:19
Replace all occurrences of atom FROM with TO in an arbitrarily nested list.
(require 'dash)
(defun replace-nested-list (from to list)
"Replace all occurrences of atom FROM with TO in an arbitrarily nested LIST."
(--map
(cond
((consp it) (in-ns--replace-nested-list from to it))
((eq it from) to)
('t it))
list))
@Wilfred
Wilfred / update_pypi_from_jenkins.sh
Last active December 15, 2015 07:18
Updating a local Pip cache based on a Jenkins server.
#!/bin/bash
set -e
echo 'Creating ~/.pip-cache...'
mkdir -p ~/.pip-cache
echo 'Writing ~/.pip/pip.conf...'
mkdir -p ~/.pip
@Wilfred
Wilfred / foo.c
Created March 27, 2013 12:43
abusing C
#include <stdio.h>
int banana(int x) {
return;
}
void main() {
int c;
printf("c: %d, banana: %d\n", c, banana(1));
@Wilfred
Wilfred / gist:5320601
Created April 5, 2013 16:21
Running erefactor-elint on erefactor.el
----- Linting by /usr/bin/emacs -----
Loading vc-git...
Evaluating (progn (require (quote cl)) (require (quote easy-mmode)))...
Evaluating (require (quote flymake) nil t)...
Initializing elint...
uncompressing tooltip.el.gz...
uncompressing tooltip.el.gz...done
uncompressing syntax.el.gz...
uncompressing syntax.el.gz...done
(defun* virtualenv-search--dwim-at-point ()
"If there's an active selection, return that.
Otherwise, get the symbol at point and return a search term for its definition."
(when (use-region-p)
(return (buffer-substring-no-properties (region-beginning) (region-end))))
(-when-let* ((symbol (symbol-at-point))
(symbol-name (symbol-name symbol)))
(return (format "%s %s" (if (s-lowercase? symbol-name) "def" "class") symbol-name)))) ;; return should be return-from virtualenv-search--dwim-at-point
(defun virtualenv-search ()
@Wilfred
Wilfred / cached.py
Last active December 16, 2015 15:59
Memoize an arbitrary Python function using memcache
from django.core.cache import cache
from functools import wraps
from inspect import ismethod
import copy
def make_hash(obj):
"""Make a hash from an arbitrary nested dictionary, list, tuple or
set.
@Wilfred
Wilfred / show-your-colors.el
Created May 4, 2013 23:35
show-your-colours.el --- an HTTP server showing the current buffer fontified
;;; show-your-colours --- an HTTP server showing the current buffer fontified
;; Author: Wilfred Hughes <[email protected]>
;; Version: 0.1
;; Package-Requires: ((s "1.3.0"))
;;; Commentary:
;; Allow others to see what you're editing in Emacs. For live
;; screencasts, or general Emacs advocacy. If you have multiple
@Wilfred
Wilfred / tco.el
Last active December 17, 2015 13:19
toying with TCO in elisp
;; tco.el --- tail-call optimisation -*- lexical-binding: t -*-
(require 'dash)
(eval-when-compile (require 'cl))
(setq lexical-binding 't)
(defun tco-add-trampoline (fun-name new-name form)
"Given quoted soure FORM, replace calls to FUN-NAME (a symbol)
with a lambda expression that returns the result of the FUN-NAME call."
(--map
@Wilfred
Wilfred / dropdown.html
Created May 30, 2013 17:54
strange dropdown behaviour -- try opening the select. Only occurs on Chrom[e|ium] on Linux.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#dock {
width: 70px;
background-color: green;
height: 100%;