How to view the HTML source of a page in Chrome for Android

Save the following JavaScript as a bookmark (ie. bookmarklet):
javascript:window.open('view-source:' + location.href)

To use it, load the website of your choice, then start typing the name of the bookmarklet in the address bar and click it once the full name appears (via autocomplete).

The problem with Android and MTP

It's no news that USB mass storage support got stripped from Android (I'm not quite sure ... either in 3.* or in 4.* versions). This change introduced a number of advantages over the old way, but at the same time a quite serious and longstanding bug surfaced with it: sometimes (or whenever ...) you change something in the filesystem on your phone, the change will not be reflected on your computer when you connect the phone via USB. The problem is obvious, the solution is apparently not. This bug has been annoying users for years and is still not fixed. Since Google focuses on developing the "next big thing" Smile, many serious bugs take a very long time to get fixed. Obviously these bugs affect only a minority of the Android userbase ... but it's usually the more advanced (or geeky) smartphone owners who "pay the price".

Filenames and Pathnames in Shell: How to do it correctly

A pretty interesting writeup. A must-read if you don't know how to handle filenames with control characters (eg. newline) in them correctly. David wrote another (even longer Smile ) article on how to fix the problem of handling filenames by changing standards, operating systems and/or tools.

My choice from the proposed solutions is this one:
find . -print0 | while IFS="" read -r -d "" file; do
  COMMAND "$file"
done

How to print/verify the signatures (and/or certificates) of an Android package (APK file)

First extract the contents of the APK. This is easy since an APK is essentially a ZIP archive. If you don't know any better way, you can always rename the APK to a ZIP extension and extract it's contents the same way you'd extract a ZIP. On a Unix/Linux box you can use unzip:
mkdir Example
cd Example
unzip ../Example.apk

How to emulate Unix’ getent with MacOSX’s dscl

I've used dscl before, but since I use it at most once a year, I already forgot about it. It's time to write it down ... maybe it'll stick in my mind for longer this way. Smile
To look up a user by UID:
dscl . -search /Users UniqueID [uid number]
To read a users properties/attributes (like HOME dir, shell, etc.):
dscl . -read /Users/[username]

Some Best Practices for Web App Authentication

I probably couldn't have written it any better, so it's worth to be shared. Smile

How to block HTTP requests based on HTTP header fields using iptables

The trick is to:
  • filter the right TCP packet (not just process all packets going to/from the webserver's port ... that'd be a serious waste of CPU power) ... in this task the "Recent" match module can be of great help
  • use the "String" match module to seach the first couple of bytes of the targeted packet for a string match

The htp.p procedure in Oracle RDBMS does not work (well) with multibyte charactersets

A long time ago I wrote my own framework for PL/SQL projects and one of the first things I did was to create a proper alternative to the builtin htp package. The Oracle supplied variant has lots of limitations and a few bugs/problems too. Since I worked for years on systems that had only English speaking users, I never faced the problem of htp.p (or htp.prn or htp.print) with multibyte characterset databases/strings. The code snippet written by amber.jah demonstrates the problem quite well.

Cloning an OEM Windows 7 installation

First of all: Microsoft's licensing does not permit this. The "Unsupported Sysprep scenarios" document tells you this clearly:

Microsoft does not support the use of Sysprep to create a new image of a system that was originally created by using a custom OEM installation image or by using OEM installation media. Microsoft only supports such an image if the image was created by the OEM manufacturer. For more information see the following licensing brief on Reimaging Rights.

Don't get fooled by the "supports" or "is supported" terms in the above paragraph. The the referenced "Reimaging Rights" document they make a clear statement:

OEM Specific Information:
  • Organizations do not have the right to reimage by using OEM media.
  • An OEM image can only be preloaded on a PC by the OEM during manufacturing. An image can be individually recovered by the organization (or a service provider they choose) by using the Recovery Media. The OEM recovery media should match the product version originally preinstalled on the system; no other image may be used to restore the system to its original state.

However there's a method to clone an OEM Windows 7 instance and change the product key afterwards. But legally you're on your own.

How to make filenames NTFS compatible

Let's assume you've a bunch of files (in a directory tree) on a linux/unix system and you'd like to copy them over to a Windows NTFS filesystem. The latter allows a lot less characters in filenames (and directory names), then linux/unix. The following code goes through the entire tree (starting with the current working directory) and removes all invalid characters from directory entries. Note that it relies on a few non-standard extensions (eg. not all find implementations have a -print0 option.

find . -depth -mindepth 1 -print0 | while IFS="" read -r -d "" entry; do if [ -f "${entry}" ]; then b="$(basename "${entry}")"; n="$(echo "${b}" | tr -d '\001-\037/\\:*?"<>|')"; if [ "${b}" != "${n}" ]; then d="$(dirname "${entry}")"; [ -f "${d}/${b}" ] && mv "${entry}" "${d}/${n}"; fi; fi; done

P.S.: I used David's writeup on how to process directory entries correctly and the Wikipedia article on NTFS for the list of valid characters.

P.S.2: Beware that simply removing invalid characters might result in data loss since several filenames can be converted to the same string this way. Eg. both the filename "my test?file.txt" and the filename "my test:file.txt" will be converted to "my testfile.txt" and only one will be kept. If you really need to cover such special cases, you could replace invalid characters with a number (instead of simply removing the invalid characters) and increment this number after each processed file (ie. directory entry). This way you could be sure that no file is lost during the process.

Syndicate content