Skip to content

Instantly share code, notes, and snippets.

View w33tmaricich's full-sized avatar

Alexander Maricich w33tmaricich

  • LightFeather.io
  • Bowie, MD
View GitHub Profile
@w33tmaricich
w33tmaricich / arraylist-map.clj
Last active March 21, 2016 14:08
clj: converts a java arraylist to a map
(defn arraylist->map¬
"Converts an arraylist java object to a list"
[al]
(loop [finished-list {}
counter 0]
(if (>= counter (.size al))
finished-list
(recur (into finished-list (.get al counter))
(inc counter)))))
@w33tmaricich
w33tmaricich / key-with-value.clj
Last active March 21, 2016 14:08
clj: retrieves the first key that has the associated value
(defn key-with-value¬
"Retrieves the first key that has the associated value"
[list-items value]
(first (filter (comp #{value} list-items) (keys list-items))))
@w33tmaricich
w33tmaricich / contains-keys.clj
Last active March 21, 2016 14:09
clj: checks if all keys are contained within a map
(defn contains-keys?
"True if all keys are contained within the map"
[maps keywords]
(let [map-list maps
all-keys keywords]
(if (empty? all-keys)
true
(if (contains? map-list (first all-keys))
(recur map-list (rest all-keys))
false))))
@w33tmaricich
w33tmaricich / str-int.clj
Last active March 21, 2016 14:09
clj: convert a string to an int
(defn str->int
"Converts a string to an integer"
[string]
(Integer. (re-find #"\d+" string)))
@w33tmaricich
w33tmaricich / linkpath.sh
Last active March 21, 2016 14:09
sh: retrieve file path through simlink
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
@w33tmaricich
w33tmaricich / colors.sh
Last active March 21, 2016 14:09
sh: bash color codes and usage
bla='\033[0;30m'
red='\033[0;31m'
gre='\033[0;32m'
yel='\033[0;33m'
blu='\033[0;34m'
mag='\033[0;35m'
cya='\033[0;36m'
whi='\033[0;37m'
nc='\033[0m'
# Directories #
/build/
/bin/
target/
# OS Files #
.DS_Store
*.class
@w33tmaricich
w33tmaricich / redirect.html
Last active March 21, 2016 14:10
html: redirect to web page
<!-- Place in between head tag… -->
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com">
window.onload = function () {
if (typeof history.pushState === "function") {
history.pushState("jibberish", null, null);
window.onpopstate = function () {
history.pushState('newjibberish', null, null);
// Handle the back (or forward) buttons here
// Will NOT handle refresh, use onbeforeunload for this.
};
}
else {
@w33tmaricich
w33tmaricich / osx_shortcuts.txt
Last active March 21, 2016 14:11
ref: osx keyboard shortcuts
Screen Capture to disk:
⌘ ⇧ 3 Screen to jpeg file on desktop
⌘ ⇧ 4 + Drag: Selection to jpeg file on desktop
⌘ ⇧ 4 + Spacebar: Window (click camera) to jpeg file
Screen Capture to clipboard:
⌘ ⇧ 3 + Ctrl: Screen to clipboard
⌘ ⇧ 4 + Drag + Ctrl: Selection to clipboard
⌘ ⇧ 4 + Spacebar + Ctrl Window (Camera effect)