View JSON in Internet Explorer 7-11

[Origin]: http://developers.de/blogs/holger_vetter/archive/2013/12/13/view-json-in-internet-explorer-7-11.aspx

Hello guys,

you all know the problem, want to debug an application with IE and IE always wants to download the JSON file.

The other browsers like Chrome or Firefox are doing a better job here.

If you want that IE shows the JSON file without downloading it, here is a registry fix for it.

Create a new text document and insert this (Link: http://pastebin.com/B0BXG0N6):

Windows Registry Editor Version 5.00;
; Tell IE 7,8,9,10,11 to open JSON documents in the browser on Windows XP and later.
; 25336920-03F9-11cf-8FD0-00AA00686F13 is the CLSID for the "Browse in place" .
;
[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00

[HKEY_CLASSES_ROOT\MIME\Database\Content Type\text/json]
"CLSID"="{25336920-03F9-11cf-8FD0-00AA00686F13}"
"Encoding"=hex:08,00,00,00

Now rename the document to {FileName}.reg and save.

Run it and confirm the dialog.

Now JSON files will be shown directly in IE, without downloading.

*Thanks to Coding 101 from http://www.codeproject.com/Tips/216175/View-JSON-in-Internet-Explorer for the Script

Debugging JavaScript Using Google Chrome

[Origin]: http://www.c-sharpcorner.com/UploadFile/3d39b4/debugging-javascript-using-google-chrome/

We are working with data and data are storing in JavaScript variables. We need to see what value is passed to the function and how the value is manipulated and what result the value is producing so we need to debug the JavaScript function to trace a variable value line by line. In the previous article I explained how to debug a JavaScript function using Visual Studio and Internet Explorer; that article is:

Debugging JavaScript Code Using VS and IE

So now we go through step-by-step to debug a JavaScript function using Google Chrome.

Create UI Design and Develop Functionality for Addition

We create a UI Design that takes two values and calculates the addition of these two values on a button click.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type ="text/javascript">
        function AddNumber()
        {
            var result = document.getElementById("<%=lblResult.ClientID %>");
            var firstNumber = document.getElementById("<%=txtFirstNumber.ClientID %>").value;
            var secondNumber = document.getElementById("<%=txtSecondNumber.ClientID %>").value;
            var addition = parseInt( firstNumber) + parseInt(secondNumber);
            result.innerHTML = "Addition is :" + addition;
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Enter First Number : <asp:TextBox ID="txtFirstNumber" runat="server"></asp:TextBox><br />
    Enter Second Number : <asp:TextBox ID="txtSecondNumber" runat="server"></asp:TextBox><br />
    <asp:Button ID="btnAdd" runat="server" Text="Addition" OnClientClick="javascript:return AddNumber();" /><br/>
    <asp:Label ID="lblResult" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>

Value Input Window

image1.png

Add Debugger in the JavaScript function so the cursor can hit here whenever the function is called.

image2.png

Setting and Debug In Google Chrome

Go to “Tools” then click on “JavaScript console”.

image3.png
image4.png

Run the application and insert values into the input fields then click on the “Addition” button. The cursor will then reach the debugger in the source tab under the JavaScript console window.

image5.png

In this function we declare several variables and on starting, these variables are #ff0000; check the Scope Variables panel in the Right Pane.

image6.png

Click on F10 and move forward line by line, then check the value of the variables using a mouse move on that variable.

image7.png

We can also check data in the scope variables window.

image8.png

We can also check for an error in the JavaScript code. For example we don’t define a variable and use that variable. I have a variable firstNumber and use the myfirstNumber variable to parse in an int type but instead firstNumber is undefined.

image9.png

We can insert a breakpoint by double-clicking on line number or using right-click of the mouse, then click on “Add breakpoint item”. When we use a breakpoint we don’t need to define the debugger in the JavaScript function and the cursor will hit the breakpoint directly.

image10.png

We have the Breakpoints window where the line with the breakpoint checkbox checked will be shown.

image11.png

separate files (HTML5,CSS & JS)

Origin: https://stackoverflow.com/questions/12151708/separate-files-html5-css-js

Just declare references to your CSS & JS from within your HTML. For performance reasons, it’s good to put the CSS reference in the head, and the JS reference at the end of the file just before closing out the tag. That way, your page will load and will look correct right off the bat and won’t be blocked downloading the JavaScript. The JS will be the last thing to load. Here’s an example of the HTML markup:

<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyles.css" />
</head>

<body>
...

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="myscript.js"></script>

</body>
</html>
share

How do you auto format code in Visual Studio?

Origin: https://stackoverflow.com/questions/5755942/how-do-you-auto-format-code-in-visual-studio

To format a selection: Ctrl+K, Ctrl+F

To format a document: Ctrl+K, Ctrl+D

See the pre-defined keyboard shortcuts. (These two are Edit.FormatSelection and Edit.FormatDocument.)

shareimprove this answer

New text document shortcut missing from the right click option

Origin: https://answers.microsoft.com/en-us/windows/forum/windows_7-desktop/new-text-document-shortcut-missing-from-the-right/022309a6-cd08-41df-8e55-95e83397ae73

Pat Mok replied on November 5, 2009See post history

Check that this key exists HKEY_CLASSES_ROOT\.txt\ShellNew\NullFile

If it doesn`t exist,create it.Just right click in the right hand pane of the ShellNew key,
and select New/String value,then type: NullFile

How to Access Your Ubuntu Bash Files in Windows (and Your Windows System Drive in Bash)

Origin: https://www.howtogeek.com/261383/how-to-access-your-ubuntu-bash-files-in-windows-and-your-windows-system-drive-in-bash/

By Chris Hoffman on July 6th, 2016

Windows 10’s “Bash on Ubuntu on Windows” environment contains a few different components. The first time you run the bash.exe program, it will download and install an entire Ubuntu user space environment. You can access these files in File Explorer or other Windows programs, if you know where to look.

You can also access your Windows system drive–and any other drives on your computer–from within the Ubuntu Bash shell. This allows you to work with your normal Windows files using Linux command-line utilities.

Where the Ubuntu Bash Shell Files Are Stored in Windows

Note that each Windows user account that uses Bash will have its own separate Bash environment and files under its own user directory.

To access these files, you’ll first need to show hidden folders in File Explorer. Open a File Explorer window and click View > Options > Change Folder and Search Options.

In the Folder Options window that appears, select View > Show Hidden Files, Folders, and Drives.

Navigate to the following directory to find these folders:

C:\Users\USERNAME\AppData\Local\lxss

The Ubuntu system files are stored at:

C:\Users\USERNAME\AppData\Local\Lxss\rootfs

Your Ubuntu user account’s home folder is stored at:

C:\Users\USERNAME\AppData\Local\Lxss\home\USERNAME

The root account’s home folder is stored at:

C:\Users\USERNAME\AppData\Local\Lxss\root

Where Your Windows System Drive Appears in Bash

The Ubuntu Bash shell environment makes your full Windows system drive available so you can work with the same files in both environments. However, the Bash environment doesn’t just dump you in your C:\ drive. Instead, it places you in /, or the root directory you’d have on Linux. If you perform an ls command to view the contents of the directory, you’ll just see the Ubuntu directories that provide the Linux environment.

Your Windows system drive and other connected drives are exposed in the /mnt/ directory here, where other drives are traditionally made available in the Linux directory structure. Specifically, you’ll find the C: drive at the following in the Bash environment:

/mnt/c

To change to this directory with the “cd” command, run the following command:

cd /mnt/c

If you have a D: drive, you’ll find it located at /mnt/d, and so on.

For example, to access a file stored at C:\Users\Chris\Downloads\File.txt, you’d need to use the path /mnt/c/Users/Chris/Downloads/File.txt in the Bash environment.

Note that, when accessing Windows system files, your Bash shell environment has the permissions it was launched with. If you launched it normally from the shortcut, it will have the same file access permissions your Windows user account does.

For example, if you want to access the C:\Users\Administrator folder, you’d need to right-click the Bash shell shortcut and select “Run as Administrator” to launch the Bash shell with Windows Administrator privileges.

This works just like the Command Prompt, which needs to be launched as Administrator if you need write access to Administrator-only files, or write access to system files. You can’t just use “sudo” in the Bash environment.

What is the exact difference between Windows-1252(1/3/4) and ISO-8859-1?

Origin:https://stackoverflow.com/questions/19109899/what-is-the-exact-difference-between-windows-12521-3-4-and-iso-8859-1

We are hosting PHP apps on a Debian based LAMP installation. Everything is quite ok – performance, administrative and management wise. However being a somewhat new devs (we’re still in high-school) we’ve run into some problems with the character encoding for Western Charsets.

After doing a lot of researches I have come to the conclusion that the information online is somewhat confusing. It’s talking about Windows-1252 being ANSI and totally ISO-8859-1 compatible.

So anyway, What is the difference between Windows-1252(1/3/4) and ISO-8859-1? And where does ANSI come into this anyway?

What encoding should we use on our Debian servers (and workstations) in order to ensure that clients get all information in the intended way and that we don’t lose any chars on the way?

shareimprove this question

I’d like to answer this in a more web-like manner and in order to answer it so we need a little history. Joel Spolsky has written a very good introductionary article on the absolute minimum every dev should know on Unicode Character Encoding. Bear with me here because this is going to be somewhat of a looong answer. 🙂

As a history I’ll point to some quotes from there: (Thank you very much Joel! 🙂 )

The only characters that mattered were good old unaccented English letters, and we had a code for them called ASCII which was able to represent every character using a number between 32 and 127. Space was 32, the letter “A” was 65, etc. This could conveniently be stored in 7 bits. Most computers in those days were using 8-bit bytes, so not only could you store every possible ASCII character, but you had a whole bit to spare, which, if you were wicked, you could use for your own devious purposes.

And all was good, assuming you were an English speaker. Because bytes have room for up to eight bits, lots of people got to thinking, “gosh, we can use the codes 128-255 for our own purposes.” The trouble was, lots of people had this idea at the same time, and they had their own ideas of what should go where in the space from 128 to 255.

So now “OEM character sets” were distributed with PCs and these were still all different and incompatible. And to our contemporary amazement – it was all fine! They didn’t have the Internet back than and people rarely exchanged files between systems with different locales.

Joel goes on saying:

In fact as soon as people started buying PCs outside of America all kinds of different OEM character sets were dreamed up, which all used the top 128 characters for their own purposes. Eventually this OEM free-for-all got codified in the ANSI standard. In the ANSI standard, everybody agreed on what to do below 128, which was pretty much the same as ASCII, but there were lots of different ways to handle the characters from 128 and on up, depending on where you lived. These different systems were called code pages.

And this is how the “Windows Code pages” were born, eventually. They were actually “parented” by the DOS code pages. And then Unicode was born! 🙂 and UTF-8 is “another system for storing your string of Unicode code points” and actually “every code point from 0-127 is stored in a single byte” and is the same as ASCII. I will not go into anymore specifics of Unicode and UTF-8, but you should read up on the BOM, Endianness and Character Encoding as a general.

@Jukka K. Korpela is “right-on the money” saying that most-probably you are referring to Windows-1252.

On “the ANSI conspiracy”, Microsoft actually admits the miss-labeling in a glossary of terms:

The so-called Windows character set (WinLatin1, or Windows code page 1252, to be exact) uses some of those positions for printable characters. Thus, the Windows character set is NOT identical with ISO 8859-1. The Windows character set is often called “ANSI character set”, but this is SERIOUSLY MISLEADING. It has NOT been approved by ANSI.

So, ANSI when refering to Windows character sets is not ANSI-certified! 🙂

As Jukka pointed out (credits go to you for the nice answer )

Windows-1252 ISO Latin 1, also known as ISO-8859-1 as a character encoding, so that the code range 0x80 to 0x9F is reserved for control characters in ISO-8859-1 (so-called C1 Controls), wheres in Windows-1252, some of the codes there are assigned to printable characters (mostly punctuation characters), others are left undefined.

However my personal opinion and technical understanding is that both Windows-1252 and ISO-8859-1 ARE NOT WEB ENCODINGS! 🙂 So:

  • For web pages please use UTF-8 as encoding for the content So store data as UTF-8 and “spit it out” with the HTTP Header: Content-Type: text/html; charset=utf-8.

    There is also a thing called the HTML content-type meta-tag: <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    Now, what browsers actually do when they encounter this tag is that they start from the beginning of the HTML document again so that they could reinterpret the document in the declared encoding. This should happen only if there is no ‘Content-type’ header.

  • Use other specific encodings if the users of your system need files generated from it. For example some western users may need Excel generated files, or CSVs in Windows-1252. If this is the case, encode text in that locale and then store it on the fs and serve it as a download-able file.
  • There is another thing to be aware of in the design of HTTP: The content-encoding distribution mechanism should work like this.

    I. The client requests a web page in a specific content-types and encodings via: the ‘Accept’ and ‘Accept-Charset’ request headers.

    II. Then the server (or web application) returns the content trans-coded to that encoding and character set.

This is NOT THE CASE in most modern web apps. What actually happens it that web applications serve (force the client) content as UTF-8. And this works because browsers interpret received documents based on the response headers and not on what they actually expected.

We should all go Unicode, so please, please, please use UTF-8 to distribute your content wherever possible and most of all applicable. Or else the elders of the Internet will haunt you! 🙂

P.S. Some more nice articles on using MS Windows characters in Web Pages can be found here and here.

shareimprove this answer