Skip to content

Instantly share code, notes, and snippets.

View EricCrosson's full-sized avatar
💭
This is not my status.

Eric Crosson EricCrosson

💭
This is not my status.
View GitHub Profile
@EricCrosson
EricCrosson / image-processing.cpp
Last active December 15, 2015 14:29
A convolution function that takes a kernel and an image.
QVector<QRgb>
MainWindow::convolveImage(QImage* img,
QVector<double>; kernel,
short kernel_size)
{
int width = img->width();
int height = img->height();
int len = width * height;
QVector<QRgb> imvec = vectorOfImagePixels(img);
@EricCrosson
EricCrosson / gcd.pl
Last active December 15, 2015 14:29
A perl script to find the greatest common denominator of two integers.
sub gcd {
my ($m, $n) = @_;
until ($n == 0) {
($m, $n) = ($n, $m % $n);
}
return $m;
}
@EricCrosson
EricCrosson / gcd-recursion.pl
Created March 30, 2013 03:58
A recursive perl script to find the greatest common denominator of two integers.
#!/usr/bin/perl -w
use strict;
sub gcd {
my ($m, $n) = @_;
if ($n == 0) {
return $m;
}
return gcd($n, $m % $n);
@EricCrosson
EricCrosson / init-host.sh
Created March 30, 2013 04:05
Code to run a specific host's bash init script, if applicable.
[ -f ~/Dropbox/config/user.init.d/`hostname`.sh ] && \
. ~/Dropbox/config/user.init.d/`hostname`.sh
@EricCrosson
EricCrosson / create-host-init-script.sh
Created March 30, 2013 04:06
A script to set up my host-specific bash init scripts.
touch ~/Dropbox/config/user.init.d/`hostname`.sh
chmod +x ~/Dropbox/config/user.init.d/`hostname`.sh
@EricCrosson
EricCrosson / insert-pairs.el
Last active December 15, 2015 14:29
Some defuns to insert pairs of useful programming delimeters.
(define-key global-map (kbd "C-M-j")
(defun insert-surrounding-parentheses (&optional arg)
(interactive "p")
(dotimes (i arg) (insert "()")
(backward-char 1))))
(define-key global-map (kbd "C-M-k")
(defun insert-surrounding-braces (&optional arg)
(interactive "p")
(dotimes (i arg) (insert "{}")
@EricCrosson
EricCrosson / insert-pairs-macro.el
Last active December 15, 2015 14:29
Some keybindings to insert common programming delimeters.
(defmacro esc/define-displaced-yank (funcname data)
"Create a defun of name FUNCNAME that yanks and moves according
to DATA. DATA is of the form (STR, MOVE). STR is the string to
yank and MOVE is the number of chars to move backward.
Note that negative values of MOVE are valid."
(let ((funsymbol (intern (format "esc/yank-displaced-%s" funcname)))
(docstring (format "(insert \"%s\") and (backward-char %d).
This command can be prefixed, and will iterate N times."
(car data) (or (cadr data) 1)))
@EricCrosson
EricCrosson / new-lecture.el
Last active December 15, 2015 14:29
A defun that I have used to differentiate between lectures in school notes.
(defun new-lecture ()
"Used to insert a new block and today's date."
(interactive)
(end-of-buffer)
(newline-and-indent)
(newline-and-indent)
(re-search-backward "\\* Lecture ")
(end-of-line)
(backward-word)
(kill-line)
@EricCrosson
EricCrosson / demonstration-kmacro.el
Created March 30, 2013 04:18
An Emacs-produced function, defined via keyboard macro.
(fset 'demonstration
[?\C-r ?L ?e ?c ?t ?u ?r ?e ? ?\C-m ?\C-e ?\M-b ?\C-k ?\C-y ?\M-> ?\C-n ?\C-n ?* ?\S- ?L ?e ?c ?t ?u ?r ?e ? ?\C-y ?\C-\' ?i ?n ?c ?r ?e return ?\C-j ?\C-\' ?d ?a ?t ?e return ?\C-j ?\C-j])
@EricCrosson
EricCrosson / w3m-scroll-google-results.el
Last active December 15, 2015 14:38
Emacs Lisp to scroll between google results in a w3m search. This script looks for the regex associated with each result, and ensures that it has found a valid result by checking for the presence of a hyperlink. So far, she works great.
(defun w3m-first-or-subsequent-google-result ()
"Move point to the first (or subsequent) google result.
See also \\[w3m-prev-google-result]."
(interactive)
(w3m-find-a-google-result))
(defun w3m-prev-google-result ()
"Move point to the previous google result.
Complimentary function to \\[w3m-first-or-subsequent-google-result]."
(interactive)