Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
ARC=`uname -m`
if [[ `echo $ARC | egrep 'i[3456]86'` ]]; then
ARC=i386
else
ARC=x86_64
fi
# NOMACHINE NX binary packages
@xtman
xtman / update-java-alternatives.sh
Created September 19, 2013 01:00
A script to detect the installed Oracle JDK 7 and set alternatives to use the ones from the latest Oracle JDK 7. Tested on CentOS 6.4.
#!/bin/bash
## locate the JDK
JDK=$(basename $(ls -l -d /usr/java/jdk1.* | awk '{print $NF}' | tail -n 1))
[[ -z $JDK ]] && echo "No Oracle JDK 7 installed in /usr/java" 1>&2 && exit 1
## java
alternatives --install /usr/bin/java java /usr/java/${JDK}/jre/bin/java 20000
alternatives --set java /usr/java/${JDK}/jre/bin/java
@xtman
xtman / ssh-tunnel-start
Created September 6, 2013 17:11
A shell script to establish a ssh tunnel using ssh command.
#!/bin/sh
LOCAL_HOST="localhost"
LOCAL_PORT=""
GATEWAY_USER=""
GATEWAY_HOST=""
GATEWAY_PORT=22
TARGET_HOST=""
@xtman
xtman / rm-ms-office-2011.sh
Created April 17, 2013 01:17
The script to remove MS office for Mac 2011
#!/bin/sh
osascript -e 'tell application "Microsoft Database Daemon" to quit'
rm -R '/Applications/Microsoft Communicator.app/'
rm -R '/Applications/Microsoft Messenger.app/'
rm -R '/Applications/Microsoft Office 2011/'
rm -R '/Applications/Remote Desktop Connection.app/'
rm -R '/Library/Application Support/Microsoft/'
rm -R '/Library/Automator/*Excel*'
rm -R '/Library/Automator/*Office*'
rm -R '/Library/Automator/*Outlook*'
@xtman
xtman / example.tcl
Created March 6, 2013 02:39
The examples demonstrates how to replace a string in TCL
# replace apple with orange
puts [string map {"apple" "orange"} "I like apple."]
# remove . in the string 3.8.001, prints 38001
puts [string map {. ""} 3.8.001]
# more about string map, see http://wiki.tcl.tk/10170
@xtman
xtman / example.tcl
Last active December 14, 2015 11:39
The example shows how to get the last and first element of list in TCL.
set mylist "1 2 3 4 5"
# prints the last element of mylist: 5
puts [lindex $mylist end]
# prints the first element of mylist: 1
puts [lindex $mylist 0]
@xtman
xtman / example.html
Created March 4, 2013 09:30
The html code includes javascript to check if Java Runtime is installed in your browser.
<div id="my_output_div"></div>
<script src="http://java.com/js/deployJava.js"></script>
<script type="text/javascript">
var html = '<ul>';
html += '<li><b>Installed JREs:</b>' + deployJava.getJREs() + '</li>';
html += '<li><b>Version Check (&gt;= 1.6.0?):</b>' + deployJava.versionCheck('1.6.0+') + '</li>';
html += '<li><button onClick="deployJava.installLatestJRE();">Install latest JRE</button></li>';
var div = document.getElementById('my_output_div');
div.innerHTML=html;
</script>
@xtman
xtman / GWTExample.java
Created March 4, 2013 04:02
GWT: open relative url in a new window
public class GWTExample {
public static void openRelativeURL(String path, String name) {
String url = GWT.getHostPageBaseURL() + path;
com.google.gwt.user.client.Window.open(url, name, null);
}
public static void main(String[] args){
openRelativeURL("about.html");
}
@xtman
xtman / GWTExample.java
Last active December 14, 2015 11:29
Open a URL in a new window in Google Web Toolkit.
public class GWTExample {
public static void openUrlInNewWindow(String url, String name) {
// Open a new browser window
com.google.gwt.user.client.Window.open(url, name, "menubar=no,location=false,resizable=yes,scrollbars=yes,status=no,dependent=true");
}
}
@xtman
xtman / matlab.sh
Created February 26, 2013 01:07
A wrapper shell script that executes a matlab script or command.
#!/bin/sh
#
# Locate matlab binary executable file.
#
MATLAB=$(which matlab)
if [ -z ${MATLAB} ]; then
if [ -n ${MATLAB_HOME} ]; then
MATLAB=${MATLAB_HOME}/bin/matlab