Parsing URL hash/fragment identifier with JavaScript

Here it is, modified from this query string parser: function getHashParams() { var hashParams = {}; var e, a = /\+/g, // Regex for replacing addition symbol with a space r = /([^&;=]+)=?([^&;]*)/g, d = function (s) { return decodeURIComponent(s.replace(a, ” “)); }, q = window.location.hash.substring(1); while (e = r.exec(q)) hashParams[d(e[1])] = d(e[2]); return hashParams; … Read more

Convert HTML to data:text/html link using JavaScript

Characteristics of a data-URI A data-URI with MIME-type text/html has to be in one of these formats: data:text/html,<HTML HERE> data:text/html;charset=UTF-8,<HTML HERE> Base-64 encoding is not necessary. If your code contains non-ASCII characters, such as éé, charset=UTF-8 has to be added. The following characters have to be escaped: # – Firefox and Opera interpret this character … Read more

Easy way to parse a url in C++ cross platform?

There is a library that’s proposed for Boost inclusion and allows you to parse HTTP URI’s easily. It uses Boost.Spirit and is also released under the Boost Software License. The library is cpp-netlib which you can find the documentation for at http://cpp-netlib.github.com/ — you can download the latest release from http://github.com/cpp-netlib/cpp-netlib/downloads . The relevant type … Read more

Parsing JSON from URL

First you need to download the URL (as text): private static String readUrl(String urlString) throws Exception { BufferedReader reader = null; try { URL url = new URL(urlString); reader = new BufferedReader(new InputStreamReader(url.openStream())); StringBuffer buffer = new StringBuffer(); int read; char[] chars = new char[1024]; while ((read = reader.read(chars)) != -1) buffer.append(chars, 0, read); return … Read more

What are the safe characters for making URLs?

To quote section 2.3 of RFC 3986: Characters that are allowed in a URI, but do not have a reserved purpose, are called unreserved. These include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde. ALPHA DIGIT “-” / “.” / “_” / “~” Note that RFC 3986 lists fewer reserved punctuation marks … Read more

How to access resources in JAR file?

I see two problems with your code: getClass().getResourceAsStream(imgLocation); This assumes that the image file is in the same folder as the .class file of the class this code is from, not in a separate resources folder. Try this instead: getClass().getClassLoader().getResourceAsStream(“resources/”+imgLocation); Another problem: byte abyte0[] = new byte[imageStream.available()]; The method InputStream.available() does not return the total … Read more