Skip to content

Instantly share code, notes, and snippets.

@jclosure
jclosure / log4j_mdc
Last active August 29, 2015 14:04
extend log4j with MDC properties
# Setup your log4j ConversionPattern to include a new ApplicationId field
log4j.appender.out.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{ApplicationId} | %m%n
# You can now set this value in your java code like this
private void setupLogging() {
org.apache.log4j.MDC.put("ApplicationId", "XZY321");
}
@jclosure
jclosure / scheme_macros
Created July 31, 2014 02:57
The case for scheme macros
;3-state condition defined as a function
(define (3-state
value
positive-body
zero-body
negative-body)
(cond
((zero? value) zero-body)
((positive? value) positive-body)
(else negative-body)))
@jclosure
jclosure / petite-repl
Last active August 29, 2015 14:07
Setup Petite Scheme as Your REPL Within Emacs
;put this in your ~/.emacs file
;ref: http://community.schemewiki.org/?emacs-tutorial
;;; Always do syntax highlighting
(global-font-lock-mode 1)
;;; Also highlight parens
(setq show-paren-delay 0
show-paren-style 'parenthesis)
(show-paren-mode 1)
@jclosure
jclosure / find_emacs_keybindings
Created October 22, 2014 02:13
Discover Your Keybindings In Emacs
An extremely useful thing to know in emacs is how to discover what keys are bound to which commands on your own.
If you know the name of the command -- goto-line. If you type 'C-h w' (Control+h and then w), Emacs will as you "Where is command: ". Type goto-line and hit enter, and it will tell you what keystrokes (if any) are bound to that command.
There are a bunch more similar features. 'C-h k' does the inverse -- asks you for a keystroke and then tells you the command it runs; 'C-h b' shows all current keybindings; 'C-h a' will search for a string, so you might type 'C-h a goto' to search for commands with "goto" in the name; 'C-h v' describes variables; 'C-h f' describes functions; etc.
@jclosure
jclosure / brew_update_via_git
Created October 22, 2014 05:17
Update Homebrew via GIT Because Its Just a Git Repo
This can help if you have problems with: brew update
Don't forget to fetch the origin!!!
$ cd /usr/local
$ git fetch origin
$ git reset --hard origin/master
@jclosure
jclosure / emacs_path_to_shell_path
Created October 29, 2014 02:17
Set your emacs PATH to match shell PATH
;;ADD THIS TO INIT.EL
;; set the path as terminal path [http://lists.gnu.org/archive/html/help-gnu-emacs/2011-10/msg00237.html]
(setq explicit-bash-args (list "--login" "-i"))
;; fix the PATH variable for GUI [http://clojure-doc.org/articles/tutorials/emacs.html#osx]
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell
@jclosure
jclosure / excel_range_locking
Created December 20, 2014 21:13
Excel Range Locking For Functions
To keep Excel from dynamically moving the target range for a function, use the $ in front of the col and row references.
On a windows machine, you can toggle through the "lock down" methods with the F4 key.
A '$' will lock down the reference to an absolute one versus a relative one. You can lock down the column, row or both. Here is a locked down absolute reference for your example.
(A1-MIN($A$1:$A$30))/(MAX($A$1:$A$30)-MIN($A$1:$A$30))
@jclosure
jclosure / tar_copy
Created December 27, 2014 01:38
Delta Fold-In File Copying With tar
(cd /opt/jboss-fuse && tar c .) | (cd /mnt/lastbackup/jboss-fuse && tar xf -)
@jclosure
jclosure / gist:b3c7b3c8e455533de1fb
Created January 16, 2015 02:44
Use PowerShell to Create WinForms on the Fly
$firstName = New-Object System.Windows.Forms.textBox
$firstName.add_KeyUp({ $fullName.Text = $firstName.text + " " + $lastName.text})
$lastName = New-Object System.Windows.Forms.textBox
$lastName.top += 50
$lastName.add_KeyUp({ $fullName.Text = $firstName.text + " " + $lastName.text})
$fullName = New-Object System.Windows.Forms.textBox
$fullName.top += 100
@jclosure
jclosure / cli_data_hacks
Created February 3, 2015 03:26
CLI Big Data Hacks
# Count the number of lines in a file
cat file.txt | wc -l
# Jump to a line with less
less +392800g file.txt
# View the top of a file (eg. view the column headers of a csv file)
head file.txt
# Grab the first 8 fields of a delimeted file and save to another