Skip to content

Instantly share code, notes, and snippets.

View JEG2's full-sized avatar

James Edward Gray II JEG2

View GitHub Profile
@JEG2
JEG2 / test.el
Created December 25, 2011 04:15
(kill-new "KILLED")
@JEG2
JEG2 / test.el
Created December 25, 2011 04:16
(kill-new "KILLED")
A_CONSTANT = :outside
class AClass
A_CONSTANT = :inside
end
p A_CONSTANT # => :outside
p AClass::A_CONSTANT # => :inside
Paste me!
Paste me!
@JEG2
JEG2 / paste_test.txt
Created January 20, 2012 22:01
Testing Gists from within Emacs.
This should be a public Gist.
@JEG2
JEG2 / header.yasnippet
Created January 22, 2012 04:43
A snippet I can't get quite right yet.
# -*- mode: snippet -*-
# name: header
# key: ;;;
# --
${1:$(let ((starter (or comment-start "#"))) (concat starter (make-string (length "abc") (string-to-char (substring starter -1)))))}
${1:Header}$0
@JEG2
JEG2 / functions.el
Created January 24, 2012 01:05
An attempt to escape content for a regular expression.
(defun jeg2s-regex-escape (str)
"Escape all special regular expression characters in the passed string."
(if (stringp str)
(jeg2s-regex-escape (cons "" (split-string str "" t)))
(if (>= (safe-length str) 2)
(if (and (not (string= "\\" (car str))) (cadr (string-match "[.*+?^$\\\\[]" str)))
(concat (car str) "\\" (cadr str) (jeg2s-regex-escape (cddr str)))
(concat (car str) (jeg2s-regex-escape (cdr str)))
(mapconcat 'identity str "")))))
@JEG2
JEG2 / functions.el
Created January 24, 2012 01:10
Some regular expression helpers.
(defun jeg2s-regex-replace (str regex replacement &optional fixedcase literal)
"Replace a regular expression in the passed string, if it occurs."
(or (when (string-match regex str)
(replace-match replacement fixedcase literal str))
str))
(defun jeg2s-regex-replace-all (str regex replacement &optional fixedcase literal)
"Replace a regular expression everywhere it occurs in the passed string."
(if (string-match regex str)
(jeg2s-regex-replace-all (replace-match replacement fixedcase literal str)
s = "james"
substrings = [ ]
s.size.times do |length|
s.split("").permutation(length + 1) do |perm|
if s.include? perm.join
substrings << perm
end
end
end