Thursday, December 24, 2015

C# vs TypeScript in Visual Studio 2015

Recently, I have coded JavaScript Analysis projects of equivalent functions in both C# and TypeScript in Visual Studio 2015. C Sharp is definitely the winner. Let me explain.


Shortcoming of Typescript compare to C#


1. When usage of myStatement is detected but not imported, Visual Studio will help you import: 
var myStatement1=require("ast/myStatement")
it is incorrect, and need to manually correct back to
var myStatement=require("./ast/myStatement")
C# does not have this problem.

2. Refactoring of class won't affect the naming of usage of class in the other files
e.g., by refactoring the naming myStatement to myStatement1,
it will change from
var myStatement=require("./ast/myStatement")
to
var myStatement=require("./ast/myStatement1")
in classes uses myStatement1, still myStatement is using, C# does not have this problem

3. The Test Explorer needs to parse for a long time, C# is fast.

4. The compiler scanning each typescript file takes quite for a while during starting while C# is very fast

5. C# has windows form for fast UI prototype

6. The Typescript UI sometimes just hang, C# does not have this problem

7. The solution Explorer sometimes left with a big gap after cleaning the js and js.map file, C# does not have this problem

8. Many datastructure are lack off, and difficult to see the contents like Dictionary (from https://github.com/basarat/typescript-collections) in debugging mode. C# does not have this problem

9. The typing in typescript is lazy type, and there is no real class constraint. When you want to use it as a class for OO language like C#, you might create some hidden bugs that you might not aware. You can use C# without such problems.

Shortcoming of C# compare to TypeScript


1. Need to go through Edge.js for running node.js indirectly.

2. Lack of understanding of JavaScript by always coding in C# (Fortunately I have coded quite sometimes in typescript).

3. Actually there is no real shortcoming of C#, it enables fast development without concerning on those superficial stuff, and put real concern in logic.

Monday, November 9, 2015

Meteor Install Path on Windows

It is on
<Your User folder>/AppData/Local/.meteor

But if your problem is you cannot start meteor on Windows in Command Prompt, holds on. You do not need to set the environment with that path. Just RESTART your windows will do. Trust me.

Friday, October 30, 2015

Parsing JavaScript with Esprima vs ANTLR

My original thought is that, the compilation for ANTLR 4 Esmascript (I am using C# target)
(https://github.com/antlr/grammars-v4/blob/master/ecmascript/ECMAScript.g4)
should be faster than Esprima
(http://esprima.org/)

It turns out that it is not.

I use jQuery.Mobile 1.4.2 to experiment:
ANTLR 4 makes use of 1 minute,
while
Esprima only makes use of 100 milliseconds.

Esprima is much faster than ANTLR 4.

Not only I have observed this, I have found some complaints of the speed of ANTLR 4 for JavaScript by other people:
https://groups.google.com/forum/#!msg/antlr-discussion/AUN7BLSDIzo/KG5MQ95Us9gJ

If you are gonna decide which to use, I am here to save your time: choose Esprima.

Saturday, August 22, 2015

Produce problems for yourself

Netflix has moving their application to the cloud, leveraging the hardwards in Amazon EC2.
They adopt an architecture call micro service architecture, which breaks normal components in to microservices. These microservices work together to achieve a task.

Microservice could be failed - maybe due to network congestion or simply unavailable. To proactively deal with failure of microservices, they make use of Chaos Monkey in Amazon EC2 that could purposely turn off the microservices. This helps them to see their resilients against failure.

I feel this is a good approach. Rather than waiting for problems, PRODUCE problems for yourself. This allows yourself to have time for fixing or preparing it. Nicely done!

Thursday, August 20, 2015

Where is my quora credit?

Well, recently, quora has not discontinued the usage of credit. They have switched to another reward system which is introduced as follows.

====

How the new Ask to Answer system will work:
Ask to Answer requests will no longer cost credits. Anyone can send an Ask to Answer request to anyone else. Ask to Answer requests will be prioritized based on both quality and volume. High priority requests will go directly to the intended recipient and other requests will be aggregated. Prioritization will be based on a number of factors, including: 
  1. How many requests the target writer receives and subsequently answers over a period of time.
  2. Whether the specific question is tagged with a topic that the writer has expertise in and/or which is listed in the writer's Knows About profile section.
  3. Whether the request is sent from a person that the writer follows and/or interacts with regularly.
Regarding notifications about Ask to Answer requests:
  • For high priority requests: As before, for each of these requests, you will get individual notifications:
===

Find here for more details.

Sunday, June 7, 2015

BB Flashback setting for Youtube Video

Click on Tools>Options in Tools Options

Display (One Time Setting)
Checked the following options:
"Switched off windows graphics effects"
"Disable the "show window contents while dragging option"
"Change resolution when recording" (1280x720)

Use the following options when Exporting Video:
1. Choose AVI
2. Under XviD MPEG-4 Codec, Choose COnfigure [Can download it here:https://www.xvid.com/download/]
3. Click on "Target quantizer"
4. Type 1500 as bit rate (original is 700)
This is one time setting, after setting, if you choose export, just export it without extra changes.

Saturday, April 25, 2015

How to vectorize your signature with Inkscape

It’s often useful to add your signature to a Word document instead of manually signing the actual paper with one of those pen thingies. Of course, the easiest method is to just sign a piece of paper, scan it, and insert it as an image. It’s simple to do, but because the scanned image is a bitmap it often looks rubbishy and pixellated when you print it or save it as a PDF.
The solution is to create a vector signature that is guaranteed to look fantastic at every scale. There are lots of methods out there. Here’s mine – it uses free software and is quick to do.
1. Sign a piece of white unlined paper. Choose your best, most representative signature, and scan it (400 dpi or so is usually good enough). Here I’m using the signature of a famous personage that I found online, rather than my own embarrassing scrawl.
2. Change the image to grayscale, and adjust the levels – Auto Levels usually does the trick. You can use Photoshop if you have it, but I use GIMP (GNU Image Manipulation Program), which is free and awesome. Get it from www.gimp.org/downloads. Save the signature as a JPG at high quality (95 or so). It should now look more like this:

3.  Open in the file Inkscape (the open source SVG graphics editor). You can download it from inkscape.org/download – it’s also free and awesome.


4. Resize the page to fit your signature (File menu -> Document Properties -> Fit page to selection):




5. Create a vector version of the signature by using the Trace Bitmap function from the Path menu. You can play around with the settings to fine-tune things, but I find I get good results using a single scan, the brightness cutoff method, thresholds at 0.880 and 0.970, and a 2 colour output. Press OK.


6. Your vector image is now sitting on top of your bitmap image, which you no longer need. Delete it by selecting it, moving it to the side, and pressing the delete key.



7. Resize the page to fit your new vector signature (File menu -> Document Properties -> Fit page to selection).


8. Now save it! From the File menu, choose -> Save As -> Enhanced Metafile (.emf).  There are lots of different vector filetypes you can use (.svg for example), but .emf is a good format for inserting into Word.
Then just insert your signature into Word as a picture, making sure the scale is appropriate (this might involve printing it out a few times to check). Make the image sit “in front of text” if you want to allow it to slightly overlie the typed text.
So that’s it! The result looks very professional, prints really well (it looks jet black on a laser printer!), and withstands infinite zooming when it’s in a PDF:





Wednesday, March 4, 2015

Writing Clean Code

I accumulated some reference

1. Put good comments on SVN, like what you want to test.  Retain those code that might be used again in the svn, and delete it from your code to keep it clean.
2. When you want to try a new function, a good way is to create a new class. Not create a new function in the class, that will make the class looks too bloat.
3. When the function is working, congrats keep it for the paper. If not, just delete it (note that the version still contain in SVN).
4. People says read code vs write code, times is 10 vs 1. Can't agree on that more. When you create a new class, try a new algorithm, try to record your idea somewhere (written in comment, if too complex a video). so that you can recall it. When you define a function, comments on its purpose and so on.
5. When trying a parameter, define it at a centre place. Cleaning the parameters once in a while.
6. Should have a rule on variable naming. And be consistent on it.
7. Test-driven development will save you lots of time finding bugs, and recreate the same test case. Write unit-test forefront.
8. Define some common libraries when you are coding, and find yourself code the same thing over and over again. Replace all codes with the libraries code for easiness of maintainence.


Wednesday, February 25, 2015

Ubuntu Packages - How to install gmpy on python

Know about Ubuntu Nickname
It depends on your Version on your Ubuntu, here some version of Ubuntu with their Nickname
Ubuntu 14.10 (Utopic)
Ubuntu 14.04.2 LTS (Trusty)
Ubuntu 12.04.5 LTS (Precise)
Ubuntu 10.04.4 LTS (Lucid)
You can find a more complete reference here
http://releases.ubuntu.com/

Check Ubuntu Version
To check your Ubuntu version
 lsb_release -a

Download your installer according to your Version
I am using precise, so I install it from here
http://packages.ubuntu.com/precise/math/python-gmpy

Search your package here [There is a search engine down the page]:
http://packages.ubuntu.com/

Install the installer
To install a deb package
sudo dpkg -i DEB_PACKAGE
http://askubuntu.com/questions/40779/how-do-i-install-a-deb-file-via-the-command-line

Wednesday, February 11, 2015

Getting Access Denied when accessing application data folder in Windows 7

Problem:
C:\Users\<ME AS ADMINSTRATOR>\AppData\Local\Application Data is not accessible

Those are junction points : hidden, protected operating system files that are not meant to be accessed by users.
Each one points to a user-accessible folder:

Real path is as follows:

Application Data - C:\Users\{user name}\AppData\Roaming
Cookies - C:\Users\{user name}\AppData\Roaming\Microsoft\Windows\Cookies
History - C:\Users\{user name}\AppData\Local\Microsoft\Windows\History
Local Settings - C:\Users\{user name}\AppData\Local
My Documents - C:\Users\{user name}\Documents
NetHood - C:\Users\{user name}\AppData\Roaming\Microsoft\Windows\Network Shortcuts
PrintHood - C:\Users\{user name}\AppData\Roaming\Microsoft\Windows\Printer Shortcuts
Recent - C:\Users\{user name}\AppData\Roaming\Microsoft\Windows\Recent
SendTo - C:\Users\{user name}\AppData\Roaming\Microsoft\Windows\SendTo
Start Menu - C:\Users\{user name}\AppData\Roaming\Microsoft\Windows\Start Menu
Templates - C:\Users\{user name}\AppData\Roaming
Temporary Internet Files - C:\Users\{user name}\AppData\Local\Microsoft\Windows\Temporary Internet Files

Laptop wake up from sleep after closing the lip

I am using Toshiba Laptop with Windows 7.

Use tips from
http://www.howtogeek.com/122954/how-to-prevent-your-computer-from-waking-up-accidentally/

I turn off
Network adapters/Intel(R) Ethernet Connection I218-LM
Mice and other pointing devices/HID-compliant Mouse

[You could test whether you computer will be turned on with those devices after that]

Saturday, January 10, 2015

How Rainbow Table Works





Objective: 
Given a hash, get back the hash key.
Naive Way: 
1. Too much space - Have all mappings between plaintext and hash key (almost impossible - too large space)
2. Too much time - Trying one by one plaintext and try mapping
Rainbow Table:
Compromise between Space and Time


1.       Find the correct chain – Using the last column
2.       Getting the plain text – Using the first column
3.       1 failed or 2 failed, try again
What if we use R rather than R1,R2,R3?