Commits

Eric Knibbe committed 3d294a3 Draft

new bash script, updated JS

Comments (0)

Files changed (4)

 .. title:: Eric's bits of code
 
+==============================
+ ericfromcanada.bitbucket.org
+==============================
+
 Various pieces of code I've written, in case someone else finds them useful.
 
 `Browse all files <https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/src/>`_
 
-`keyputter.sh <https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/bash/keyputter.sh>`_
-  Handy if you have a bunch of servers you need to install your SSH key onto.
-  
+AppleScript
+-----------
+
 `close Safari Web Inspector script <https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/applescript/close%20Safari%20Web%20Inspector.applescript>`_
   Before Safari 6, the Web Inspector shortcut would only open it. Attach 
   this AppleScript to another shortcut to make it closeable.
   
+bash
+----
+
+`keyputter.sh <https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/bash/keyputter.sh>`_
+  Handy if you have a bunch of servers you need to install your SSH key onto.
+
+`svn-user-htdigest.sh <https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/bash/svn-user-htdigest.sh>`_
+  Use this to generate an htdigest file of users from an svnserve passwd file.
+  Useful if you have a Trac installation using HTTPAuth and you need to grant
+  your SVN users access.
+  
+BBEdit
+------
+
+`reST codeless language module <https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/bbedit/reStructuredText.plist>`_
+  Language module for BBEdit and TextWrangler which highlights elements 
+  in reStructuredText files and lists section titles in the function pop-up
+  menu. Recognizes both standard reST directives and Sphinx additions.
+
+JavaScript
+----------
+  
 `touch-menus-plus.js <https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/javascript/touch-menus-plus.js>`_
   Makes navigation links with drop-down menus usable on iOS by only enabling
   the link if its submenu is visible. This is only required if JavaScript is
   
   `See it in action <http://www.treefrog.ca/>`_
 
-`reST codeless language module <https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/bbedit/reStructuredText.plist>`_
-  Language module for BBEdit and TextWrangler which highlights elements 
-  in reStructuredText files and lists section titles in the function pop-up
-  menu. Recognizes both standard reST directives and Sphinx additions.
+Python
+------
 
 `restview (improved) <https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/python/restview/>`_
   My branch of the excellent restview_, a tool for previewing reST documents

bash/svn-user-htdigest.sh

+#!/bin/bash
+
+cp /dev/null user.htdigest
+for i in $(cat /svn/repos/reponame/conf/passwd | cut -d '#' -f 1 | awk '/= / { print $1":trac:"$3 }')
+do 
+	echo -e $(echo $i | cut -d ":" -f 1-2):$(echo -n $i | md5sum | cut -d " " -f 1) >> user.htdigest
+done
 </style>
 </head>
 <body>
-<div class="document">
-
+<div class="document" id="ericfromcanada-bitbucket-org">
+<h1 class="title">ericfromcanada.bitbucket.org</h1>
 
 <p>Various pieces of code I've written, in case someone else finds them useful.</p>
 <p><a class="reference external" href="https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/src/">Browse all files</a></p>
+<div class="section" id="applescript">
+<h1>AppleScript</h1>
+<dl class="docutils">
+<dt><a class="reference external" href="https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/applescript/close%20Safari%20Web%20Inspector.applescript">close Safari Web Inspector script</a></dt>
+<dd>Before Safari 6, the Web Inspector shortcut would only open it. Attach
+this AppleScript to another shortcut to make it closeable.</dd>
+</dl>
+</div>
+<div class="section" id="bash">
+<h1>bash</h1>
 <dl class="docutils">
 <dt><a class="reference external" href="https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/bash/keyputter.sh">keyputter.sh</a></dt>
 <dd>Handy if you have a bunch of servers you need to install your SSH key onto.</dd>
-<dt><a class="reference external" href="https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/applescript/close%20Safari%20Web%20Inspector.applescript">close Safari Web Inspector script</a></dt>
-<dd>Before Safari 6, the Web Inspector shortcut would only open it. Attach
-this AppleScript to another shortcut to make it closeable.</dd>
+<dt><a class="reference external" href="https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/bash/svn-user-htdigest.sh">svn-user-htdigest.sh</a></dt>
+<dd>Use this to generate an htdigest file of users from an svnserve passwd file.
+Useful if you have a Trac installation using HTTPAuth and you need to grant
+your SVN users access.</dd>
+</dl>
+</div>
+<div class="section" id="bbedit">
+<h1>BBEdit</h1>
+<dl class="docutils">
+<dt><a class="reference external" href="https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/bbedit/reStructuredText.plist">reST codeless language module</a></dt>
+<dd>Language module for BBEdit and TextWrangler which highlights elements
+in reStructuredText files and lists section titles in the function pop-up
+menu. Recognizes both standard reST directives and Sphinx additions.</dd>
+</dl>
+</div>
+<div class="section" id="javascript">
+<h1>JavaScript</h1>
+<dl class="docutils">
 <dt><a class="reference external" href="https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/javascript/touch-menus-plus.js">touch-menus-plus.js</a></dt>
 <dd><p class="first">Makes navigation links with drop-down menus usable on iOS by only enabling
 the link if its submenu is visible. This is only required if JavaScript is
 reveal are displayed.</p>
 <p class="last"><a class="reference external" href="http://www.treefrog.ca/">See it in action</a></p>
 </dd>
-<dt><a class="reference external" href="https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/bbedit/reStructuredText.plist">reST codeless language module</a></dt>
-<dd>Language module for BBEdit and TextWrangler which highlights elements
-in reStructuredText files and lists section titles in the function pop-up
-menu. Recognizes both standard reST directives and Sphinx additions.</dd>
+</dl>
+</div>
+<div class="section" id="python">
+<h1>Python</h1>
+<dl class="docutils">
 <dt><a class="reference external" href="https://bitbucket.org/EricFromCanada/ericfromcanada.bitbucket.org/raw/default/python/restview/">restview (improved)</a></dt>
 <dd>My branch of the excellent <a class="reference external" href="http://mg.pov.lt/restview/">restview</a>, a tool for previewing reST documents
 in a web browser, with some improvements I made to the CSS, syntax highlighting,
 </dl>
 <p>Find me on <a class="reference external" href="https://twitter.com/EricFromCanada">Twitter</a>.</p>
 </div>
+</div>
 </body>
 </html>

javascript/touch-menus-plus.js

 // by a <div> containing the submenu.
 // This script must be loaded after the menu markup.
 
-// Change this to your menu's id value
-menuId = 'nav';
+// Change this to your menu's "id" value
+var menuId = 'nav';
 
-if(RegExp(" Mobile\\b").test(navigator.userAgent) && RegExp(" AppleWebKit/").test(navigator.userAgent)) {
+function handle_touchstart(item) {
+	return function () {
+		var itemAnchor = item.getElementsByTagName('a')[0],
+				itemSub = item.getElementsByTagName('div')[0],
+				currentSubmenuStyle = window.getComputedStyle(itemSub, '');
+		if ((currentSubmenuStyle.getPropertyValue('display') !== itemSub.defaultDisplay) ||
+				(currentSubmenuStyle.getPropertyValue('left') !== itemSub.defaultLeft) ||
+				(currentSubmenuStyle.getPropertyValue('overflow') !== itemSub.defaultOverflow) ||
+				(currentSubmenuStyle.getPropertyValue('right') !== itemSub.defaultRight) ||
+				(currentSubmenuStyle.getPropertyValue('visibility') !== itemSub.defaultVisibility)) {
+			itemAnchor.href = itemAnchor.getAttribute('type');
+		}
+	};
+}
+
+if (navigator.userAgent.match(/iPhone|iPod|iPad/i)) {
 	var menuItems = document.getElementById(menuId).getElementsByTagName('li');
-	for (var item = menuItems[0]; item != null; item = item.nextSibling) {
+	var item = null;
+	for (item = menuItems[0]; item !== null; item = item.nextSibling) {
 		if (item.nodeName === "LI") {
-			var itemChildren = item.childNodes;
-			var itemAnchors = new Array();
-			var itemSubs = new Array();
-			for (var itemChild = itemChildren[0]; itemChild != null; itemChild = itemChild.nextSibling) {
+			var itemChild, itemAnchor, itemSub = null;
+			for (itemChild = item.childNodes[0]; itemChild !== null; itemChild = itemChild.nextSibling) {
 				if (itemChild.nodeName === "A") {
-					itemAnchors.push(itemChild);
+					itemAnchor = itemChild;
 				} else if (itemChild.nodeName === "DIV") {
-					itemSubs.push(itemChild);
+					itemSub = itemChild;
 				}
-			}
-			if (itemAnchors.length > 0 && itemSubs.length > 0) {
-				itemAnchors[0].type = itemAnchors[0].getAttribute('href');
-				itemAnchors[0].href = '#';
-				var defaultSubmenuStyle = getComputedStyle(itemSubs[0], '');
-				itemSubs[0].defaultDisplay = defaultSubmenuStyle.getPropertyValue('display');
-				itemSubs[0].defaultLeft = defaultSubmenuStyle.getPropertyValue('left');
-				itemSubs[0].defaultOverflow = defaultSubmenuStyle.getPropertyValue('overflow');
-				itemSubs[0].defaultRight = defaultSubmenuStyle.getPropertyValue('right');
-				itemSubs[0].defaultVisibility = defaultSubmenuStyle.getPropertyValue('visibility');
-				item.ontouchstart = function(){
-					var itemAnchor = this.getElementsByTagName('a')[0];
-					var itemSub = this.getElementsByTagName('div')[0];
-					var currentSubmenuStyle = getComputedStyle(itemSub, '');
-					if ((currentSubmenuStyle.getPropertyValue('display') !== itemSub.defaultDisplay) ||
-							(currentSubmenuStyle.getPropertyValue('left') !== itemSub.defaultLeft) ||
-							(currentSubmenuStyle.getPropertyValue('overflow') !== itemSub.defaultOverflow) ||
-							(currentSubmenuStyle.getPropertyValue('right') !== itemSub.defaultRight) ||
-							(currentSubmenuStyle.getPropertyValue('visibility') !== itemSub.defaultVisibility)) {
-						itemAnchor.href = itemAnchor.getAttribute('type');
-						itemAnchors[0].type = '';
-					}
-				};
+				if (itemAnchor !== null && itemSub !== null) {
+					var defaultSubmenuStyle = window.getComputedStyle(itemSub, '');
+					itemAnchor.type = itemAnchor.getAttribute('href');
+					itemAnchor.href = '#';
+					itemSub.defaultDisplay = defaultSubmenuStyle.getPropertyValue('display');
+					itemSub.defaultLeft = defaultSubmenuStyle.getPropertyValue('left');
+					itemSub.defaultOverflow = defaultSubmenuStyle.getPropertyValue('overflow');
+					itemSub.defaultRight = defaultSubmenuStyle.getPropertyValue('right');
+					itemSub.defaultVisibility = defaultSubmenuStyle.getPropertyValue('visibility');
+					item.ontouchstart = handle_touchstart(item);
+					break;
+				}
 			}
 		}
 	}