Skip to content

Instantly share code, notes, and snippets.

@xtman
xtman / genpassword.sh
Created March 4, 2012 23:11
Shell Script to generate a random string as password
# Works on Linux and Mac OS
cat /dev/urandom | strings | grep -m 1 -oEi '[a-zA-Z0-9_^!#]{8}'
@xtman
xtman / stderr_stdout_redirection.sh
Created March 8, 2012 00:51
stderr and stdout redirections
# redirect stdout to a file
cat 1.txt > r.txt
# redirect stderr to a file
grep "error" 1.log 2> r.txt
# redirect stdout to a stderr
grep * 1>&2
# redirect stderr to a stdout
@xtman
xtman / chk_flashback
Created April 8, 2012 01:51
A shell script to detect if your Mac have Flashback Trojan infected
#!/bin/bash
SafariInfected=0
echo -n "Checking Safari... "
if [[ -z `defaults read /Applications/Safari.app/Contents/Info LSEnvironment 2>&1 | grep "does not exist"` ]]; then
SafariInfected=1
echo "INFECTED."
else
echo "NOT INFECTED."
fi
@xtman
xtman / duration
Created August 21, 2012 01:31
Calculate the duration of mr studies in Bruker's nmr directory.
#!/bin/bash
function adjust() {
local cwd=$(pwd)
local sd=$1
local total=$2
local mtime1=0
local mtime2=0
local gap=0
cd ${sd}
for ssd in $(ls -t -r -d */)
@xtman
xtman / duration-single
Created August 21, 2012 01:33
Calculate the duration of the specified mr study directory.
#!/bin/bash
function adjust() {
local cwd=$(pwd)
local sd=$1
local total=$2
local mtime1=0
local mtime2=0
local gap=0
cd ${sd}
@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
@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 / 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 / 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>