commit e1e88def86d66277673b2aa37efbe20f6d6b1ce0 Author: Jeremy Wall Date: Wed Oct 2 21:06:34 2019 -0500 Initial import yay!! diff --git a/.Xdefaults b/.Xdefaults new file mode 100644 index 0000000..ed7c6af --- /dev/null +++ b/.Xdefaults @@ -0,0 +1,33 @@ +URxvt*saveLines:12000 +URxvt*foreground:White +URxvt*background:Black +URxvt*font: xft:Bitstream Vera Sans Mono:pixelsize=12 +URxvt*scrollBar:true +URxvt*scrollBar_right:true +URxvt*scrollstyle:rxvt +URxvt.cutchars: "()*,<>[]{}|' +rxvt*saveLines:12000 +rxvt*foreground:White +rxvt*background:Black +rxvt*font: xft:Bitstream Vera Sans Mono:pixelsize=12 +rxvt*scrollBar:true +rxvt*scrollBar_right:true +rxvt*scrollstyle:rxvt +rxvt.cutchars: "()*,<>[]{}|' +Rxvt*saveLines:12000 +Rxvt*foreground:White +Rxvt*background:Black +Rxvt*font: xft:Bitstream Vera Sans Mono:pixelsize=12 +Rxvt*scrollBar:true +Rxvt*scrollBar_right:true +Rxvt*scrollstyle:rxvt +Rxvt.cutchars: "()*,<>[]{}|' +XTerm*saveLines:12000 +XTerm*foreground:White +XTerm*background:Black +XTerm*font: xft:Bitstream Vera Sans Mono:pixelsize=12 +XTerm*scrollBar:true +XTerm*scrollBar_right:true +XTerm*scrollstyle:rxvt +XTerm.cutchars: "()*,<>[]{}|' +remote*termname: xterm diff --git a/.ackrc b/.ackrc new file mode 100644 index 0000000..cc26559 --- /dev/null +++ b/.ackrc @@ -0,0 +1,2 @@ +--type-add=borg=.borg +--type-add=clojure=.clj diff --git a/.bash_profile.backup b/.bash_profile.backup new file mode 100644 index 0000000..6adebd8 --- /dev/null +++ b/.bash_profile.backup @@ -0,0 +1,3 @@ +export AQSISHOME=/Applications/Aqsis.app # Entry managed by Aqsis Renderer +export PATH=$AQSISHOME/Contents/MacOS:$PATH # Entry managed by Aqsis Renderer +source ~/.bashrc diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..265d760 --- /dev/null +++ b/.bashrc @@ -0,0 +1,49 @@ +# .bashrc + +# Source global definitions +if [ -f /etc/bashrc ]; then + . /etc/bashrc +fi + +if [ -f /etc/bash_completion ] && ! shopt -oq posix; then + . /etc/bash_completion +fi + +# color table: +# Black 0;30 +# Blue 0;34 +# Green 0;32 +# Cyan 0;36 +# Red 0;31 +# Purple 0;35 +# Brown 0;33 +# [Note: Replace 0 with 1 for dark color] + +export bash_rc_files=$(find -L ~/.bash_rc.d/ -type f | grep -v '\.swp$' | sort) + +for rc_file in $bash_rc_files; do + #echo "sourcing ${rc_file}" + source $rc_file; +done + +# User specific aliases and functions go here (override system defaults) +if [[ $TERM == "dumb" ]]; then + PS1='\u@\h$ ' +else + PS1='[\e[1;36m$(date +%H:%M)\e[m] [\e[01;32m\u@\h\e[m] (\e[01;32m\]$(pwd)\e[m\])\n\$> ' +fi + +insert_path_element_before /opt/brew/bin +insert_path_element_before ~/bin + +function re_source() { + source ~/.bashrc +} + +export PAGER="less -R" + +export PATH=/Users/jwall/.local/bin/luna-studio:$PATH + +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion diff --git a/.bashrc_home b/.bashrc_home new file mode 100644 index 0000000..7866a8c --- /dev/null +++ b/.bashrc_home @@ -0,0 +1,86 @@ +# ~/.bashrc: executed by bash(1) for non-login shells. +# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) +# for examples + +# If not running interactively, don't do anything +[ -z "$PS1" ] && return + +# don't put duplicate lines in the history. See bash(1) for more options +export HISTCONTROL=ignoredups +# ... and ignore same sucessive entries. +export HISTCONTROL=ignoreboth + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# make less more friendly for non-text input files, see lesspipe(1) +[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)" + +# set variable identifying the chroot you work in (used in the prompt below) +if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) +fi + +# set a fancy prompt (non-color, unless we know we "want" color) +case "$TERM" in +xterm-color) + PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' + ;; +*) + PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' + ;; +esac + +# Comment in the above and uncomment this below for a color prompt +PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] ~~ \[\033[01;32m\]\w\[\033[00m\]\n\$> ' + +# If this is an xterm set the title to user@host:dir +case "$TERM" in +xterm*|rxvt*) + PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"' + ;; +*) + ;; +esac + +# Alias definitions. +# You may want to put all your additions into a separate file like +# ~/.bash_aliases, instead of adding them here directly. +# See /usr/share/doc/bash-doc/examples in the bash-doc package. + +#if [ -f ~/.bash_aliases ]; then +# . ~/.bash_aliases +#fi + +# enable color support of ls and also add handy aliases +if [ "$TERM" != "dumb" ]; then + eval "`dircolors -b`" + alias ls='ls --color=auto' + #alias dir='ls --color=auto --format=vertical' + #alias vdir='ls --color=auto --format=long' +fi + +# some more ls aliases +#alias ll='ls -l' +#alias la='ls -A' +#alias l='ls -CF' + +# enable programmable completion features (you don't need to enable +# this, if it's already enabled in /etc/bash.bashrc and /etc/profile +# sources /etc/bash.bashrc). +if [ -f /etc/bash_completion ]; then + . /etc/bash_completion +fi +#/etc/perl +#/usr/local/lib/perl/5.8.8 +#/usr/local/share/perl/5.8.8 +#/usr/lib/perl5 +#/usr/share/perl5 +#/usr/lib/perl/5.8 +#/usr/share/perl/5.8 +#/usr/local/lib/site_perl + +export PATH=$PATH:~/bin:~/perl/bin +export EDITOR=/usr/bin/vim +export PERL5LIB=~/perl/lib/perl/5.8:~/perl/share/perl/5.8:~/perl/lib/perl/5.8/auto:~/perl/share/perl/5.8/auto:~/perl/lib/perl/5.8.8:~/perl/share/perl/5.8.8:~/perl/lib/perl/5.8.8/auto:~/perl/share/perl/5.8.8/auto:~/perl/lib/perl/5.8.8/site_perl:~/perl/lib/perl/5.8/site_perl:$PERL5LIB diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..ae65b69 --- /dev/null +++ b/.hgignore @@ -0,0 +1,17 @@ +.bash_rc.d/99.local.sh +.cabal/bin +.cabal/config.platform +.cabal/lib +.cabal/logs +.cabal/packages +.cabal/share +.cabal/world +.emacs.d/ac-comphist.dat +.emacs.d/auto-save-list +.emacs.d/elpa +.emacs.d/srecode-map.el +.emacs.d/tramp +.emacs.d/url +.emacs.d/semantic +.emacs.d/session + diff --git a/.hgrc b/.hgrc new file mode 100644 index 0000000..308e915 --- /dev/null +++ b/.hgrc @@ -0,0 +1,57 @@ +%include .hgauth + +[ui] +username = Jeremy Wall (zaphar) +merge = internal:merge + +[alias] +qstatus = status --rev -2 +stash = qnew -e +apply = qpush +modified = status -m +added = status -a +graphlog = log -l 9 --graph +secrets = log -r 'secret()' +drafts = log -r 'draft()' +current = identify -i -n -B +hist = log -f -r 'ancestors(.)' +show = log -r . --template "Revision: {node|short}\n---------\n{desc}\n\n" +showrev = log --template "Revision: {node|short}\n---------\n{desc}\n\n" -r + +[pull] +update=1 + +[qnew] +edit=1 + +[bookmarks] +track.current = True + +[email] +from = Jeremy Wall (zaphar) +method = smtp + +[smtp] +host = smtp.gmail.com +port = 587 +tls = starttls +username = jeremy@marzhillstudios.com + +[extensions] +convert = +hgext.bookmarks = +hgext.convert = +mq = +record = +graphlog = +transplant = +fetch = +histedit = +rebase = +shelve = +purge = +patchbomb = +churn = + +[web] +#cacerts = /etc/hg-dummy-cert.pem diff --git a/.hgtags b/.hgtags new file mode 100644 index 0000000..46bcb54 --- /dev/null +++ b/.hgtags @@ -0,0 +1 @@ +b17db60bd576fa4c3fdb084ba78b85719090c6c9 foo diff --git a/.juliarc.jl b/.juliarc.jl new file mode 100644 index 0000000..69911b6 --- /dev/null +++ b/.juliarc.jl @@ -0,0 +1,82 @@ +LOCAL_LIB_PATH = expanduser("~/lib/julia") + +# My local package paths are in lib/julia +append!(LOAD_PATH, [LOCAL_LIB_PATH]) + +# macro that implements import Module as Alias mostly used as a helper in the +# repl. Not to be used in Packages since this macro is not guaranteed to exist +# elsewhere. +macro imports(mexpr, mod, sexpr) + # enforce our syntax + if mod != :as + error("Expected as modifier for import got $mod") + end + # mexpr must be a symbol + if typeof(mexpr) != Symbol + error("invalid import statement, expected identifier got $mexpr") + end + # sexpr must be a symbol + if typeof(sexpr) != Symbol + error("invalid import statement, expected identifier got $mexpr") + end + # We can't just quote the import syntax so we construct the import + # expression by hand + iexpr = Expr(:import) + iexpr.args = [mexpr] + expr2 = quote + $iexpr + $sexpr = $mexpr + end + # finally we escape the whole thing since we need all the symbols to be + # evaluated/created in the callers scope. + return esc(:($(eval(expr2)))) +end + +containedtypes(m::Module) = whos(m, r"[[:upper:]]") + +# non sampled versions of some statistics functions + +variance(v::Vector) = mean((v - mean(v)).^2) +stddev(v::Vector) = sqrt(variance(v)) + +# multiprocess configuration helpers +function procsetup() + delta = CPU_CORES - nprocs() + if delta > 0 + addprocs(delta) + end +end + +# array utilities +hasprefix(prefix::Vector, len, str) = length(str) >= len && str[1:len] == prefix +hasprefix(prefix::Vector, str) = hasprefix(prefix, length(prefix), str) + +function eagerzip(iters...) + numiters = length(iters) + minlen = minimum(map(length, iters)) + ar = [tuple(map(x->x[1], iters)...)] + for i in 2:minlen + push!(ar, tuple(map(x->x[i], iters)...)) + end + return ar +end + +guid2base64(input) = base64(hex2bytes(replace(input, "-", ""))) + +#Using Codecs +# +#Tobytes(s) = convert(Vector{Uint8}, s) +# +#Base64decode(text::UTF8String) = base64decode(tobytes(text)) +#Base64decode(text::ASCIIString) = base64decode(tobytes(text)) +#Base64decode(text::Vector{Uint8}) = decode(Base64, filter(c -> c != '\n', text)) + + +# all factors not just prime factors. +function factors(n) + f = [one(n)] + for (p,e) in factor(n) + f = reduce(vcat, f, [f*p^j for j in 1:e]) + end + return f +end diff --git a/.profile b/.profile new file mode 100644 index 0000000..22378b0 --- /dev/null +++ b/.profile @@ -0,0 +1,3 @@ +source ~/.bashrc + +export PATH="$HOME/.cargo/bin:$PATH" diff --git a/.screenrc b/.screenrc new file mode 100644 index 0000000..e4ed17e --- /dev/null +++ b/.screenrc @@ -0,0 +1,12 @@ +startup_message off +defscrollback 5000 +termcapinfo xterm ti@:te@ +termcapinfo xterm-color ti@:te@ +hardstatus alwayslastline +hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m/%d/%Y %{W}%c %{g}]' +vbell off +shell /bin/bash +logtstamp on +logtstamp after 1 +logfile flush +term screen-256color diff --git a/.tmux.conf b/.tmux.conf new file mode 100644 index 0000000..d8485ed --- /dev/null +++ b/.tmux.conf @@ -0,0 +1,62 @@ +# global settings +set-option -ga update-environment " GOPATH" + +## mimic the screen prefix key +unbind-key C-b +set-option -g prefix C-a + +## correctly handle utf8 +#setw -g utf8 on +#sest -g utf8 on + +## we like colors +set -g default-terminal "screen-256color" + +## Useful KeyBindings + +### example of some useful key-bindings +#bind-key "~" split-window "exec htop" + +bind-key "R" source-file ~/.tmux.conf +#bind-key "a" select-window -l +#bind-key "C-a" select-window -l + +### vim stile pane navigation +#bind-key -r C-W select-pane -l +bind-key -r j select-pane -t :.- +bind-key -r k select-pane -t :.+ +bind-key -r C-j select-pane -t :.- +bind-key -r C-k select-pane -t :.+ + +#### Tab style pane cycling +bind-key -r Tab select-pane -t :.+ + +### window cycling +bind-key q confirm-before kill-pane +bind-key Q confirm-before kill-window + +## Status bar settings +set -g status-keys vi + +### colors +set -g status-fg green +set -g status-bg black + +### unicode +#set -g status-utf8 on + +### status string +set -g status-justify centre +set -g status-left-length 20 +set -g status-left "#[fg=yellow](#S)" +set -g status-right-length 45 +set -g status-interval 300 + +# Each of these must be exclusive since there is a race condition between them. +## Default +#set -g status-right "#[fg=green][%D %H:%M]" +## Linux +if-shell 'uname | grep Linux' 'set -g status-right "#[fg=cyan]#(cat /proc/loadavg)#[fg=green] [%D %H:%M]"' +## Darwin +if-shell 'uname | grep Darwin' 'set -g status-right "#[fg=cyan]#(sysctl vm.loadavg)#[fg=green] %D %H:%M"' + diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..dfb931b --- /dev/null +++ b/.vimrc @@ -0,0 +1,35 @@ +" genera editing options +set nocompatible +set tabstop=4 +set expandtab +set paste +set nowrap +set autoindent +set linebreak +syntax on +filetype plugin indent on + +" file specific overrides +au BufNewFile,BufRead *Makefile,*.mk set noexpandtab +au BufNewFile,BufRead *.py,*.java set tabstop=2 +au BufNewFile,BufRead *.app set filetype=erlang +au BufNewFile,BufRead .bash_* set filetype=sh +au BufNewFile,BufRead *.erl filetype indent off +au BufNewFile,BufRead *.hrl filetype indent off + +nmap :execute "!make && make test" + +let g:BASH_AuthorName = 'Jeremy Wall' +let g:BASH_AuthorRef = 'jw' +let g:BASH_Email = 'jeremy@marzhillstudios.com' +let g:BASH_Company = 'Marzhillstudios.com' + +let g:clj_want_gorilla = 1 +let g:clj_highlight_builtins = 1 +let g:clj_highlight_contrib = 1 +let g:clj_paren_rainbow = 1 +let vimclojure#NailgunClient = "/Users/jwall/bin/ng" + +let g:erlangFoldSplitFunction=0 + +colorscheme desert256 diff --git a/.xmobarrc b/.xmobarrc new file mode 100644 index 0000000..4d0ab5f --- /dev/null +++ b/.xmobarrc @@ -0,0 +1,14 @@ +Config { font = "-misc-fixed-*-*-*-*-13-*-*-*-*-*-*-*" + , bgColor = "black" + , fgColor = "lightgrey" + , commands = [ Run Network "eth0" ["-L","0","-H","32","--normal","green","--high","red"] 10 + , Run MultiCpu ["-L","15","-H","50","--normal","green","--high","red"] 10 + , Run Memory ["-t","Mem: Used % - Free "] 10 + , Run Swap [] 10 + , Run Date "%a %b %_d %Y %H:%M:%S" "date" 10 + , Run StdinReader + ] + , sepChar = "%" + , alignSep = "}{" + , template = "%StdinReader% }{ %multicpu% | %memory% | %swap% | %eth0% | %date%" + } diff --git a/bootstrap_brew.sh b/bootstrap_brew.sh new file mode 100644 index 0000000..69c83c5 --- /dev/null +++ b/bootstrap_brew.sh @@ -0,0 +1,39 @@ +brew_script=/tmp/brew_install.sh + +curl -fsSL \ + https://raw.githubusercontent.com/Homebrew/install/master/install \ + > $brew_script + +less $brew_script + +read -p 'Execute brew install script? [y|N] ' prompt + +if [ $prompt != "y" ]; then + exit 1; + fi + +/usr/bin/ruby $brew_script + +brew install ansible +brew install autoconf +brew install automake +brew install cmake +brew install erlang +brew install git +brew install gmp +brew install htop-osx +brew install imagemagick +brew install inkscape +brew install irssi +brew install jq +brew install leiningen +brew install mercurial +brew install openssl +brew install p7zip +brew install pkg-config +brew install taglib +brew install tesseract +brew install tmux +brew install watch +brew install xpdf +brew install xz diff --git a/bootstrap_git_repos.sh b/bootstrap_git_repos.sh new file mode 100644 index 0000000..ac569fd --- /dev/null +++ b/bootstrap_git_repos.sh @@ -0,0 +1,12 @@ +mkdir -p ~/sandbox/apps/ +cd ~/sandbox/apps + +git clone https://github.com/witheve/Eve +git clone https://github.com/bazelbuild/bazel.git +git clone https://go.googlesource.com/go +git clone https://github.com/OmniSharp/omnisharp-roslyn.git +git clone https://github.com/urbit/urbit + +cd ~/sandbox/ + +hg clone https://bitbucket.org/zaphar/ansible-playbooks diff --git a/restore.sh b/restore.sh new file mode 100644 index 0000000..be1e6d0 --- /dev/null +++ b/restore.sh @@ -0,0 +1,49 @@ +dot_dir=$(dirname $0) +cd $dot_dir +for f in $(find -L $(pwd) -maxdepth 1 -type f); do + echo "Linking ${f}" + rm -f ${HOME}/$(basename $f); + ln -s $f ${HOME}/$(basename $f); +done; + +dirs=$(pwd)/.bash_rc.d +dirs="$dirs $(pwd)/.emacs.d" +dirs="$dirs $(pwd)/.irssi" +dirs="$dirs $(pwd)/.vim" +dirs="$dirs $(pwd)/.yi" +dirs="$dirs $(pwd)/.cabal" +dirs="$dirs $(pwd)/.xmonad" + +for d in $dirs; do + echo "Linking ${d}" + rm -f ${HOME}/$(basename $d); + ln -s $d ${HOME}/$(basename $d); +done; + +for f in $(find -L $(pwd)/bin -maxdepth 1 -type f); do + echo "Linking ${f}" + rm -f ${HOME}/$(basename $f); + ln -s $f ${HOME}/$(basename $f); +done; + +touch ~/.hgauth +rm -f ~/restore.sh + +# setup my hg cacerts +openssl req -new -x509 + -nodes \ + -extensions v3_ca \ + -keyout /dev/null \ + -out dummycert.pem \ + -subj "C=US/ST=Illinois/L=Chicago/O=Marzhillstudios/CN=jeremy.marzhillstudios.com" \ + -days 3650 +sudo mv dummycert.pem /etc/hg-dummy-cert.pem + +# essential libs + +## python + +mkdir -p ~/sandbox/apps + +mkdir -p ~/lib/py +cd ~/lib/py diff --git a/uuidhelpers.js b/uuidhelpers.js new file mode 100644 index 0000000..0f4f6a3 --- /dev/null +++ b/uuidhelpers.js @@ -0,0 +1,153 @@ +// Javascript helper functions for parsing and displaying UUIDs in the MongoDB shell. +// This is a temporary solution until SERVER-3153 is implemented. +// To create BinData values corresponding to the various driver encodings use: +// var s = "{00112233-4455-6677-8899-aabbccddeeff}"; +// var uuid = UUID(s); // new Standard encoding +// var juuid = JUUID(s); // JavaLegacy encoding +// var csuuid = CSUUID(s); // CSharpLegacy encoding +// var pyuuid = PYUUID(s); // PythonLegacy encoding +// To convert the various BinData values back to human readable UUIDs use: +// uuid.toUUID() => 'UUID("00112233-4455-6677-8899-aabbccddeeff")' +// juuid.ToJUUID() => 'JUUID("00112233-4455-6677-8899-aabbccddeeff")' +// csuuid.ToCSUUID() => 'CSUUID("00112233-4455-6677-8899-aabbccddeeff")' +// pyuuid.ToPYUUID() => 'PYUUID("00112233-4455-6677-8899-aabbccddeeff")' +// With any of the UUID variants you can use toHexUUID to echo the raw BinData with subtype and hex string: +// uuid.toHexUUID() => 'HexData(4, "00112233-4455-6677-8899-aabbccddeeff")' +// juuid.toHexUUID() => 'HexData(3, "77665544-3322-1100-ffee-ddccbbaa9988")' +// csuuid.toHexUUID() => 'HexData(3, "33221100-5544-7766-8899-aabbccddeeff")' +// pyuuid.toHexUUID() => 'HexData(3, "00112233-4455-6677-8899-aabbccddeeff")' + +function HexToBase64(hex) { + var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + var base64 = ""; + var group; + for (var i = 0; i < 30; i += 6) { + group = parseInt(hex.substr(i, 6), 16); + base64 += base64Digits[(group >> 18) & 0x3f]; + base64 += base64Digits[(group >> 12) & 0x3f]; + base64 += base64Digits[(group >> 6) & 0x3f]; + base64 += base64Digits[group & 0x3f]; + } + group = parseInt(hex.substr(30, 2), 16); + base64 += base64Digits[(group >> 2) & 0x3f]; + base64 += base64Digits[(group << 4) & 0x3f]; + base64 += "=="; + return base64; +} + +function Base64ToHex(base64) { + var base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + var hexDigits = "0123456789abcdef"; + var hex = ""; + for (var i = 0; i < 24; ) { + var e1 = base64Digits.indexOf(base64[i++]); + var e2 = base64Digits.indexOf(base64[i++]); + var e3 = base64Digits.indexOf(base64[i++]); + var e4 = base64Digits.indexOf(base64[i++]); + var c1 = (e1 << 2) | (e2 >> 4); + var c2 = ((e2 & 15) << 4) | (e3 >> 2); + var c3 = ((e3 & 3) << 6) | e4; + hex += hexDigits[c1 >> 4]; + hex += hexDigits[c1 & 15]; + if (e3 != 64) { + hex += hexDigits[c2 >> 4]; + hex += hexDigits[c2 & 15]; + } + if (e4 != 64) { + hex += hexDigits[c3 >> 4]; + hex += hexDigits[c3 & 15]; + } + } + return hex; +} + +function UUID(uuid) { + var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters + var base64 = HexToBase64(hex); + return new BinData(4, base64); // new subtype 4 +} + +function JUUID(uuid) { + var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters + var msb = hex.substr(0, 16); + var lsb = hex.substr(16, 16); + msb = msb.substr(14, 2) + msb.substr(12, 2) + msb.substr(10, 2) + msb.substr(8, 2) + msb.substr(6, 2) + msb.substr(4, 2) + msb.substr(2, 2) + msb.substr(0, 2); + lsb = lsb.substr(14, 2) + lsb.substr(12, 2) + lsb.substr(10, 2) + lsb.substr(8, 2) + lsb.substr(6, 2) + lsb.substr(4, 2) + lsb.substr(2, 2) + lsb.substr(0, 2); + hex = msb + lsb; + var base64 = HexToBase64(hex); + return new BinData(3, base64); +} + +function CSUUID(uuid) { + var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters + var a = hex.substr(6, 2) + hex.substr(4, 2) + hex.substr(2, 2) + hex.substr(0, 2); + var b = hex.substr(10, 2) + hex.substr(8, 2); + var c = hex.substr(14, 2) + hex.substr(12, 2); + var d = hex.substr(16, 16); + hex = a + b + c + d; + var base64 = HexToBase64(hex); + return new BinData(3, base64); +} + +function PYUUID(uuid) { + var hex = uuid.replace(/[{}-]/g, ""); // remove extra characters + var base64 = HexToBase64(hex); + return new BinData(3, base64); +} + +BinData.prototype.toUUID = function () { + var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs in older versions of the shell + var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12); + return 'UUID("' + uuid + '")'; +} + +BinData.prototype.toJUUID = function () { + var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs in older versions of the shell + var msb = hex.substr(0, 16); + var lsb = hex.substr(16, 16); + msb = msb.substr(14, 2) + msb.substr(12, 2) + msb.substr(10, 2) + msb.substr(8, 2) + msb.substr(6, 2) + msb.substr(4, 2) + msb.substr(2, 2) + msb.substr(0, 2); + lsb = lsb.substr(14, 2) + lsb.substr(12, 2) + lsb.substr(10, 2) + lsb.substr(8, 2) + lsb.substr(6, 2) + lsb.substr(4, 2) + lsb.substr(2, 2) + lsb.substr(0, 2); + hex = msb + lsb; + var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12); + return 'JUUID("' + uuid + '")'; +} + +BinData.prototype.toCSUUID = function () { + var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs in older versions of the shell + var a = hex.substr(6, 2) + hex.substr(4, 2) + hex.substr(2, 2) + hex.substr(0, 2); + var b = hex.substr(10, 2) + hex.substr(8, 2); + var c = hex.substr(14, 2) + hex.substr(12, 2); + var d = hex.substr(16, 16); + hex = a + b + c + d; + var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12); + return 'CSUUID("' + uuid + '")'; +} + +BinData.prototype.toPYUUID = function () { + var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs + var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12); + return 'PYUUID("' + uuid + '")'; +} + + +BinData.prototype.toHexUUID = function () { + var hex = Base64ToHex(this.base64()); // don't use BinData's hex function because it has bugs + var uuid = hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20, 12); + return 'HexData(' + this.subtype() + ', "' + uuid + '")'; +} + +function TestUUIDHelperFunctions() { + var s = "{00112233-4455-6677-8899-aabbccddeeff}"; + var uuid = UUID(s); + var juuid = JUUID(s); + var csuuid = CSUUID(s); + var pyuuid = PYUUID(s); + print(uuid.toUUID()); + print(juuid.toJUUID()); + print(csuuid.toCSUUID()); + print(pyuuid.toPYUUID()); + print(uuid.toHexUUID()); + print(juuid.toHexUUID()); + print(csuuid.toHexUUID()); + print(pyuuid.toHexUUID()); +}