dracoblue.net

Launching Acrobat-Reader with Relative Filenames

Today I noticed once again, that texmaker only supports the following command to launch the newly generated .pdf file.

"C:/Program Files/Adobe/Reader 8.0/Reader/AcroRd32.exe" %.pdf

Actually AcrobatReader does not like that, since he won't find the .pdf file, since it is not a absolute path.

To fix that problem I wrote a small .bat-file called run_in_current_dir.bat and put that in my home directory. Contents:

%1 %CD%\%2

Now I put in the line for automatic pdf display the following:

c:\users\jan\run_in_current_dir.bat "C:/Program Files/Adobe/Reader 8.0/Reader/AcroRd32.exe" %.pdf

Hope that helps anyone else expiriencing problems with relative filenames and acrobat reader.

In Articles, LaTeX, open source by DracoBlue @ 2008-07-16 | 94 Words

preg_match multiple lines

If you try to use preg_match on strings, which do have multiple lines you run into the problems that they actually won't match at all.

This can be easily fixed by adding s-modifier, so:

/\[(code)\](.*?)\[\/code\]/

becomes to

/\[(code)\](.*?)\[\/code\]/s

and works like a charm!

In open source, php by DracoBlue @ 2008-07-04 | 43 Words

tcsh

tcsh does some strange things, if you are using variables (in the example h in a one line while loop.

set h = 1; echo $h; while ( $h != 0 ) ; echo "Input please" ; set h = $< ; echo $h ; end ;
while? end
Input please
4
4
1
Input please
5
5
1

In dracoblue.net by DracoBlue @ 2008-07-03 | 59 Words

UrlEncode and Decode in JavaScript

While using the default JavaScript functions escape/unescape to (un)escape strings for url parameters, you'll run into issues, since JavaScript threats + as valid character and so on.

At PHPBuilder-Forums I found an

implementation, which does not work, since it only replaces the first + and leaves all other unchanged. That is very much wrong.

A fixed, and working implementation for urlencode can be found here:

function urlencode(str) {
 str = escape(str);
 str = str.replace(/\\+/g,'%2B');
 str = str.replace(/\\%20/g,'+');
 str = str.replace(/\\*/g,'%2A');
 str = str.replace(/\\//g,'%2F');
 str = str.replace(/\\@/g,'%40');
 return str;
}

In JavaScript, open source by DracoBlue @ 2008-06-11 | 90 Words

JavaScript new Exception(name,message)

Today I noticed that JavaScript doesn't provide an easy way to make/raise custom exceptions? while still providing an useful stacktrace.

Here is a code snippet used for the

GTA:T JavaScript interface to find the fitting stacktrace for a custom JavaScript Exception.

function Exception(name,msg) {
	try {
		throw new Error("")
	} catch (e) {
		e.stack = e.stack.split("@"+e.fileName+":").join(":");
		full_stack = e.stack.split("\\n");
		stack = [];
		stack[0] = "Exception: "+name+"(\""+msg+"\")"
		for (var i=2;i<full_stack.length-3;i++) {
			entry = full_stack[i];
			entry_detailed = entry.split(":");
			entry_detailed[1] = entry_detailed[1] - 4; // THIS is to
			// mark, that we'll "move" the source 4 lines higher,
			// ... because it's eval code executed. Remove that for
			// clear values.
			if (i==2) lineNumber = entry_detailed[1];
			stack[i] = entry_detailed.join(":");
		}
		return {
			name:name,
			message:msg,
			stack:stack.join("\\n"),
			lineNumber:lineNumber
		};
	}
}

You may use it that way:

try {
    function a() {
        throw new Exception("MyException","No permission!")
    }
    function b() {
        a()
    }
    b()
} catch (e) {
    alert(e.name+": "+e.message);
}
// Tested in Firefox
/* e:
Object {
  [name] => MyException
  [message] => No permission!
  [stack] => Exception: MyException("No permission!")
             a():3
             b():6
             execute():10
  [lineNumber] => 3
}*/

In HTML, JavaScript, open source by DracoBlue @ 2008-06-05 | 182 Words

Page 34 - Page 35 - Page 36