#!/bin/bash if [ $# -eq 2 ] then username=$1 groupname=$2 homedir=/home/$username elif [ $# -eq 3 ] then username=$1 groupname=$2 homedir=$3 else echo "wrong usage." echo "$0 username groupname [homedir]" exit 1 fi echo "Creating group $groupname" egrep -i "^$groupname" /etc/group &> /dev/null || groupadd $groupname echo "Creating user $username with homedir $homedir" id -u $username &> /dev/null || useradd -d $homedir -g $groupname -m $username
Javascript – avoid page reload
document.onkeydown = function(e) {
console.log(e);
if (e.keyCode == 116 || (e.ctrlKey && e.keyCode == 82)) {
console.log("avoid reload");
return false;
}
}
Javascript – Column Grouping
<script type="text/javascript">
function toggle(clazz)
{
var count = 0;
var hide = false;
dojo.query("."+clazz).forEach(function(node) {
console.log(node);
if (node.style.display == "inline-block") {
node.style.display = "none";
document.getElementById("toggleBtn").innerHTML = "+";
hide = true;
} else {
node.style.display = "inline-block";
document.getElementById("toggleBtn").innerHTML = "-";
}
count++;
});
if (hide) {
document.getElementById("plus").colSpan = "" + (parseInt(document.getElementById("plus").colSpan) - count);
} else {
document.getElementById("plus").colSpan = "" + (parseInt(document.getElementById("plus").colSpan) + count);
}
}
</script>
<table border="1">
<thead>
<tr>
<td> </td>
<td id="plus" colspan="4"><span id="toggleBtn" style="cursor: pointer" onclick="toggle('hideBlock')">-</span></td>
</tr>
<tr>
<td>First col</td>
<td class="hideBlock">Sec col</td>
<td class="hideBlock">third col</td>
<td class="hideBlock">forth col</td>
<td>fifth col</td>
</tr>
</thead>
<tr>
<td>First col</td>
<td class="hideBlock">Sec col</td>
<td class="hideBlock">third col</td>
<td class="hideBlock">forth col</td>
<td>fifth col</td>
</tr>
<tr>
<td>First col</td>
<td class="hideBlock">Sec col</td>
<td class="hideBlock">third col</td>
<td class="hideBlock">forth col</td>
<td>fifth col</td>
</tr>
</table>
Javascript – Table filtering
<script type="text/javascript">
function search(clazz, elem) { var searchValue = elem.value.toLowerCase(); dojo.query("#myData ."+clazz).forEach(function(node) { console.log(elem.value); if (elem.value == "") { var tr = node.parentNode; tr.style.display = "table-row"; } else if (node.innerHTML.toLowerCase().indexOf(searchValue) > -1) {
var tr = node.parentNode;
tr.style.display = "table-row";
} else {
var tr =node.parentNode;
tr.style.display = "none";
}
});
}
</script><table id="myData">
<thead>
<tr>
<th>isbn</th>
<th>title<br/><input type="text" onkeyup="search('name', this)"/></th>
<th>author<br/><input type="text" onkeyup="search('nummer', this)"/></th>
<th>title2</th>
<th>author2</th>
</tr>
</thead>
<tbody>
<tr>
<td>First col</td>
<td class="name readonly">Sec col</td>
<td class="nummer readonly">third col</td>
<td class="hideBlock">forth col</td>
<td>fifth col</td>
</tr>
<tr>
<td>First col</td>
<td class="name readonly">row2 col</td>
<td class="nummer readonly">row2 col</td>
<td class="hideBlock">forth col</td>
<td>fifth col</td>
</tr>
</tbody>
</table>
Javascript Auto Suggest
Searching for a simple auto suggest input field, I found:
http://www.javascriptsearch.com/tutorials/Advanced/tutorials/AUTOSUGGEST1.html
http://www.javascriptsearch.com/tutorials/Advanced/tutorials/AUTOSUGGEST2-1.html
Minor improvements added, results to download:
The Auto Suggest Controller can be used:
<script type="text/javascript">
var suggestControl;
window.onload = function () {
suggestControl = new AutoSuggestControl($TXT_FIELD_ID, new SuggestionProvider());
}
</script>
The AutoSuggestControl accepts a third optional parameter to configure the behaviour:
{typeAheadEnabled: $BOOLEAN, suggestDropDownEnabled: $BOOLEAN, minValueLength: $INTEGER
Each of this parameters is optional.
The default configuration:
typeAheadEnabled: false
suggestDropDownEnabled: true
minValueLength: 0
The AutoSuggest Controller to use
Base CSS
Base Data Provider to implement
US States Suggestion Provider
Test Provider with 15000 entries
Javascript Alert
if (tzu == undefined) {
var tzu = {};
}
tzu.alert = function(txt) {
txt = txt.replace(/Ü/g, "%DC");
txt = txt.replace(/ü/g, "%FC");
txt = txt.replace(/Ö/g, "%D6");
txt = txt.replace(/ö/g, "%F6");
txt = txt.replace(/Ä/g, "%C4");
txt = txt.replace(/ä/g, "%E4");
txt = txt.replace(/ß/g, "%DF");
txt = txt.replace(/n/g, "%0A");
alert(unescape(txt));
}