Skip to content

Instantly share code, notes, and snippets.

@etherald
etherald / lock-view.el
Created May 24, 2018 18:42
two emacs lisp functions to lock buffers
(defun lock-view ()
"put all visible buffers in view mode"
(interactive)
(save-window-excursion
(mapcar (lambda (win)
(with-current-buffer (window-buffer win)
(unless buffer-read-only
(view-buffer (current-buffer)))))
(window-list))))
@etherald
etherald / randomfile.pl
Last active February 6, 2018 17:11
recursively choose a number of files optionally matching a regex from a directory or list of directories. defaults to cwd. outputs absolute paths by default, relative with -r. use like so: randomfile -n 23 -p \(mp3\|ogg\|flac\)$ ~/music ~/music2
#!/usr/bin/env perl
# recursively choose a number of files optionally matching a regex
# from a directory or list of directories. defaults to cwd.
# outputs absolute paths by default, relative with -r
# use like so:
# randomfile -n 23 -p \(mp3\|ogg\|flac\)$ ~/music ~/music2
use strict;
use warnings;
<?php function p($c){$r=preg_replace(array("~^ +([^\n]+)~m",'~^-\s+(.*)$~m',
"~-{4,}\r?\n~",'~(http(?:s)?)://([^\s]+)~i','~\n~'),array('<code>$1</code>','<li>$1',
'<hr>','<a href=$1://$2>$2</a>','<br>'),$c);preg_match_all('~([A-Z]\w+){2,}~',$r,
$x);foreach(array_unique($x[0])as$m){$r=str_replace($m,x($m)? "<a href=?$m>$m</a>":
"$m<a href=?e=$m>?</a>",$r);}return$r;}function f($f){@mkdir('wik');return
@file_get_contents("wik/$f.w");}function b($b){echo"<h1><a href=?$b>Backlinks $b"
."</a></h1><div id=c>";foreach(glob('wik/*.w')as$f){$f=substr($f,4,-2);if(strpos(
f($f),$b)!==false)echo"<a href=?$f>$f</a><br>";}echo"</div>";}function x($f){
return file_exists("wik/$f.w");}function e($p){$p=$p?$p:$_GET['e'];echo"<h1>Edit"
." $p</h1><form action='?$p' method=post><textarea name=c cols=50 rows=10>".f($p)
;; reader-mode.el
;; [Fri Dec 22 19:24:09 UTC 2017]
;; displays selected buffer continuously flowed
;; into reader-mode-column-count windows side by side
;; in read-only mode
(defvar reader-mode-column-count 4)
(defun reader-mode (buf)
(interactive "bRead buffer: ")
@etherald
etherald / reaper.php
Created June 18, 2017 01:03
php cache reaper
The snippet of code earlier that allows you to delete all files older than 2 weeks uses the function (filemtime) - which checks the original create date of the file (filesystem independent). You MAY want to use filectime() - that looks at when the file was last changed on YOUR file system.
if (is_dir("$path") )
{
$handle=opendir($path);
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$Diff = (time() - filectime("$path/$file"))/60/60/24;
if ($Diff > 14) unlink("$path/$file");
(defun pop-to-dired-by-date ()
"Uses dired-other-window to display a dired buffer sorted by date on the current buffer's directory"
(interactive)
(when (buffer-file-name)
(let ((coming-from (buffer-file-name))
(dired-listing-switches "-talk"))
(dired-other-window (file-name-directory coming-from))
(dired-goto-file coming-from))))
;;;I use a minor mode for all my "override" key bindings:
(defvar my-keys-minor-mode-map
(let ((map (make-sparse-keymap)))
;;(define-key map (kbd "C-i") 'some-function)
;; top bottom screen
(define-key map (kbd "M-,") (lambda () "Go to top of page" (interactive) (move-to-window-line 0)))
(define-key map (kbd "M-.") (lambda () "Go to bottom of page" (interactive) (move-to-window-line -1)))
;;;I use a minor mode for all my "override" key bindings:
(defvar my-keys-minor-mode-map
(let ((map (make-sparse-keymap)))
;;(define-key map (kbd "C-i") 'some-function)
;; top bottom screen
(define-key map (kbd "M-,") (lambda () "Go to top of page" (interactive) (move-to-window-line 0)))
(define-key map (kbd "M-.") (lambda () "Go to bottom of page" (interactive) (move-to-window-line -1)))
;;; ido-isearch-ibuffer.el --- isearch ibuffer with ido
;; Copyright (C) 2014
;; Author : ET Herald <web@etherald.com>
;; Keywords: buffer, ido, switch, search
;; URL:
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
(defcustom config-basedir "c:/SFDataLoader"
"location of sf dataloader config"
:group 'salesforce)
(defcustom dataloader-bindir "c:/Program Files (x86)/salesforce.com/Data Loader/bin/"
"location of sf dataloader cli tools"
:group 'salesforce)
(defun bean-names (xml)
(mapcar (lambda (node) (xml-get-attribute node 'id))
(xml-get-children