Showing posts with label General. Show all posts
Showing posts with label General. Show all posts

Thursday, April 04, 2013

Firefox 20 Feature - Click To Play

If you, my friend, are annoyed by zillions of flash advertisements running on your browser for which you haven't subscribed, have a look at the latest version of Firefox 20. It has a hidden lovable feature called "Click To Play". If enabled, it will deactivate all Flash (and Java) plugins except the one which you select to activate in a page. I've a netbook ('cheap laptop') which cannot handle the army of flash advertisements so I chose to activate this hidden Click_To_Play feature on my recently updated Firefox.

How to Enable Click_To_Play:

  1. Open a new firefox tab and type "about:config" in address bar.
  2. Click on button which says "I will be careful" etc..
  3. Now search for Click_To_Play in "Search" box.
  4. Double click preference named "plugins.click_to_play". It will change value of the preference to 'true'.
  5. You are done. Go to any web site and click only the plugin which you know you want to activate.  
Happy Browsing and don't let the Flash ads bite!

Tuesday, September 11, 2012

Extract BINK to PNG Sequence (with transparency)


BINK movies are widely  used in games because they provide transparency in the video from long back. Sometime you have to reverse engineer the BINK file and get the PNGs out of (not JPEG but PNG with  transparency) the movie. I've used FFMpeg to get PNGs out of BINK (.bik format) file as followed.

1. Download latest ffmpeg static build from http://ffmpeg.zeranoe.com/builds/
2. Extract the .7z build to any folder.
3. Give this command to convert “my.bik” to “output” folder and %d is sequence number in output image.  %d will auto increment by one, you have to just give %d in the command.
ffmpeg.exe -i D:\my.bik D:\output\my_%d.png
Note that this is a general command which applies to any type of movie format supported by ffmpeg. There are hell lot of more things you can with ffmpeg. For example, your popular VLC is built using ffmpeg library :) 

Monday, June 21, 2010

Solve “You are not allowed to upload ‘FileName’. the requested file type: 'FileType’” problem on Vanilla Forum 1.x

Issue:

You get this exception when you try to upload any file in your Vanilla Forum (Version 1) using any Attachment extension :
You are not allowed to upload ‘FileName’. the requested file type: 'FileType’

Resolution 1:

Add specified type as allowed type. Steps to do so follow here:

  1. Note the 'FileType’ in the error message.
  2. Go to extensions\Attachments\default.php file in your Vanilla forum’s directory.
  3. Add appropriate entry in Context->Configuration['ATTACHMENTS_ALLOWED_FILETYPES'] list.
  4. Note that it’s also important that you give correct extensions for the mime type you are allowing as both, 'FilteType’ (i.e. mime type) and file extensions are corss checked in Framework code of vanilla forum.
  5. Save the file and test.

Resolution 2:

Remove check for allowed types. Note that this is not very safe for public forum but it’s ‘ok’ for internal forum with known and responsible user. Steps to do so follow here:

  1. Go to “library\Framework\Framework.Class.Uploader.php”  file.
  2. Find this line of code “if (!array_key_exists($FileType, $this->AllowedFileTypes))”  and comment this ‘if’ and ‘else’ of it. Yes you need to comment if AND else.
  3. Save the file and test.

Thursday, January 21, 2010

.NET Namespace Naming Convention with Team Name in it

I hated naming conventions from collage time and nothing is much different today. Saying that, I also must accept that I secretly liked Microsoft's guidelines about naming conventions as it gives more freedom and meaningful restrictions than others (specially Sun Java). Let's leave other naming conventions and concentrate on namespace's maming convention of your assembly and classes.

Why namespace naming is important?
A namespace gives first hand impression on what the class and its method must be doing. With that, a class should get a unique identification based on its namespace. Carelessly crafted names are misleading advertisement which repulses intended audience or create confusion.

How Microsoft Tells us to name a namespace?
CompanyName.TechnologyName[.Feature][.Design]
is what Namespace Naming Guidelines tells. Example being Microsoft.Build.Tasks

Is it long enough?
Organizations, with help of smart programmers, are now taking little more effort to refactor the code to extract common code which can be reused across teams. It is not impossible (infact it's more frequent) to have multiple implementation approach of a 'similar' feature by different team. For example team 'TreamA' and 'TeamB' in organization 'MyOrg' might have taken differnt approach to develop a media content viewer optimized for their own scenarios. If the organization want to share these media viewers across many teams to use, 'unique identification' functionality of namespace stands violated as media viewer class from both the team will look like,
MyOrg.Media.Viewer
This would not have occured if the namespace of viewers were named "MyOrg.Media.TreamA.Viewer" and "MyOrg.Media.TreamB.Viewer" beforehand.

So?
I believe we should giving implementing team name in name as ending part of namespace. So my format would be
CompanyName.TechnologyName[.Feature][.TeamOrGroupName][.Design]

Tuesday, December 29, 2009

How to Fix Error 1606: Could not access network location

This error often comes while installing some software.
Scenario A: You are getting error 1606 saying "Could not access network location [Some environment variable with % in it]..." then these links may help you solve the issue.
http://support.microsoft.com/default.aspx/kb/330766
and
http://support.microsoft.com/kb/256986/


Scenario B: You are getting error 1606 saying it cannot access internet location. But you can download same file using internet explorer,
1. Try hitting 'Retry' button. You may be in luck.
2. Not solved yet? Most probably you are behind proxy server. To solve this issue, go to Control Panel -> Internet Options -> Connections -> LAN Settings. What do you see? Is "Automatic Detect Setting" checked? If yes then uncheck it and see if your installation works. If it still doesn't work, contact your network administrator and manually provide proxy IP and Port in the LAN Settings of Internet Options.

Still not working? Please find solution and put your solution here :)

Tuesday, June 16, 2009

Caching Problem with XMLHttpRequest

Using XMLHttpReuest is fun. But if you have just started the fun, you should know this.
IE has a known issue which caches the data if request is same. It's real mystery for me why Microsoft ended up with such default behavior for functionality which is responsible to load dynamic data. But as we have to live with it, here is a small hack which will turn off the caching for that page. You need to add this two lines in your HTML Head tag.

< meta equiv="Pragma" content="no-cache"/>
< meta http-equiv="Expires" content="-1" />

Solution Source: http://en.wikipedia.org/wiki/XMLHttpRequest#Workaround

Sunday, March 01, 2009

Software Performance Consideration while Coding

Some tips when you write a code (an excerpt from Eric Lippert's Blog):
  • Set meaningful, measurable, customer-focused goals.
  • Write the code to be as clear and correct as possible.
  • Carefully measure your performance against your goals.
  • Did you meet your goal? Great! Don't waste any time on performance analysis. Spend your valuable time on features, documentation, bug fixing, robustness, security, whatever.
  • If you did not meet your goal, use tools to discover what the worst-performing fixable thing is, and fix it.

It tells how to walk on a blur trade-off between ‘correct’ and ‘preferment’ code. Success in the industry depends upon lot other factor and people just want workable code. Unnecessarily fast code doesn’t create any value of customer and time taken to think about or writing code is merely a waste in this hurry-burry software industry. Popularity of framework like .NET and Java are greatest example of it. Even the master, Donald Knuth, has said:
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."

Thursday, December 11, 2008

Database Indexes: tips

Database Indexes are sometime tricky. But it's easy to fall into traps by following simple advices. Here are some common tips (specific to t-sql and it may or may not apply to other RDBMS) listed here:

Sample Database Table:

Customer_Id
Primary Key, Clustered Index, Numeric
Customer_Name
Part of multi-column index on "Customer_Name, Customer_Mobile, Customer_Location", Varchar
Customer_Mobile
Indexed, Varchar
Customer_Location
Part of multi-column index on "Customer_Name, Customer_Location"

1. Index is not used, when columns is in function
Example of Bad:
Select * from customer
where IsNull(Customer_Name,'!true') = IsNull(@CustomerName, '!true')

Good query:
Select * from customer
where Customer_Name= @CustomerName
OR (Customer_Name is null AND @CustomerName is null)
2. On DataType mismatch,
Example of Bad:
Select * from customer
where Customer_Mobile = 9900114477

Select * from customer
where Customer_Id = '2'

Good query:

Select * from customer
where Customer_Mobile = '9900114477'

Select * from customer
where Customer_Id = 2
3. Using Like on Wrong End:
Example of Bad:

Select * from customer
where Customer_Name LIKE '%ram'

Good Option:

If you are gonna use put % always at first, use reverse Indexing
4. : Multi-column Index is created with wrong sequence of columns
Example of Bad: 
Select * from Customer 
Where Customer_Name = 'CN' and Customer_Location = 'CL'
Good Option:
On Index is on columns: 
1. Customer_Name
2. Customer_Mobile 
3. Customer_Location
Which is only used when one of these is in your where clause:
1. Customer_Name
2. Customer_Name and Customer_Mobile 
3. All three, Customer_Name, Customer_Mobile and Customer_Location
So only option is to modify Index Or Add new index on Customer_Location 

Sunday, November 30, 2008

Powershell Advocacy for consuming .NET Programs

Powershell is more than a shell. Programs initially not written to be used using shell can also be involved into Powershell script, or cmdlets. Example is my “Get List of File Associated with multiple Changesets” which could also be written in a simple c# program, that too in more user kissing manner with GUI. But compromising on user interface brings more advantages which a developer loves to have for its program, especially for the ones used by developers. Here is why:

  1. Faster to write: A power shell script written in 4-5 line in above example may take around 20-100 lines or so to write in C# program. Once you are familiar with the syntax of cmdlet scripting, I think development is very much faster.
  2. Faster to modify: If you want to change output in any manner, it’s damn easy to understand the script and change it.
  3. Easy to Run: Once u have Powershell setup, it’s just like running ipconfig or ping!! 
  4. Easy to extend the output: Output formatting provided inside Powershell is a great deal. Also, easy to write output in files and so easy to use your favorite text editor (mine is scintilla based SciTe). 
  5. Easy to Reuse: Pipe and reuse the script which u already wrote for some purpose. Or just use script inside script.

Tuesday, October 07, 2008

Secure Your Wireless Internet

Note: Tips applicable for home networking only.
Here are some tips to secure your Internet sharing using Wi-Fi, securing not just for namesake but for real.

Tips for Securing router:
1. Make sure you change user name & password of your router. Remember, any obvious password or password that can be cracked by simple brute force techniques.
2. Restrict “Remote Access” of your router by which people can access your router without being part of your network.
3. You will get many option for Wi-Fi security out of which WEP (Wired Equivalent Privacy) being default. Don’t go on name, WEP is the security which only dumb cannot crack. Use any of WPA (Wi-Fi Protected Access). WPA can also be cracked if the password is weak.
4. Last but not least, don’t lure hackers. Switch off your modem and router when not in use.

Suggestion for strong password:
I know this need not to be a part of this discussion but if you use weak password, no security can help you. A good brute force with proper dictionary can crack these easily.
Do:
1. Mixture of Capital and Small letter, special character
2. Password length should be at least 8 character
3. For longer password, use 256 bit encryption technique
4. You are lucky if you are from non-English speaking country as you can have words which does not exist in common world list for bruit force attack. Use these words freely.
5. Try to have less used letter i.e. ‘x’ or ‘f’ or ‘q’ etc

Don’t:
1. Part of a password with complete English word. e.g. say no to ‘EightNineTen’
2. Password having any (key) sequence e.g. say no to ‘xxx1234’ or ‘xxx!@#$’ or ‘asdf’
3. Password having any obvious personal information e.g. say not to password with birth year
4. Password having repeating words i.e. say no to “IndiaIndia11”

Wednesday, September 17, 2008

not-my get-tfs

#This is very popular file you may get at many places. Change $serverName's default value

param(
[string] $serverName = 'http://tfs-server:port/'
)

begin
{
# load the required dll
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")

$propertiesToAdd = (
('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'),
('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'),
('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'),
('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService')
)
}

process
{
# fetch the TFS instance, but add some useful properties to make life easier
# Make sure to "promote" it to a psobject now to make later modification easier
[psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
foreach ($entry in $propertiesToAdd) {
$scriptBlock = '
[System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null
$this.GetService([{1}])
' -f $entry[1],$entry[2]
$tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock)
}
return $tfs
}

Tuesday, September 02, 2008

Vertical Text Selection

You may need to do sometime vertical selection. For example, in example below, I want to select and remove all “SolidX”.


I need to do vertical selection for this. Selecting text vertically not commonly used but an excellent functionality provided by all serious text editors.

This is how to do it (Windows specific): Hold ALT and SHIFT key and select the text vertically and horizontally. It is not important whether you select first vertically or horizontally but you MUST press and hold ALT key before SHIFT key.

You can do this on all modern Code editors, good text editors like Scintilla based SciTE, TextPad etc. Once you know about vertical text selection selection, you will find its use at more places than what you can think about when unaware.

Friday, August 29, 2008

Blog Popularity

This blog is near to cross 500 unique visitor per month :) finger crossed

Thursday, August 14, 2008

Change-Set Rollback using TFS Power Tool (tfpt.exe)

Have you made a booboo by checking in something which you shouldn’t have? If you are using TFS and TFS Power Tools (tfpt in short) installed on your system, you are still good to roll the s#%t back.
Here are the steps that you will need to follow:
1. Install TFS Power Tool. This is recommended as it provides a lot of goodies without which you may see hell some day.

2. ‘Shelve’ all changes, as you will have to ‘undo’ all your changes.

3. Open cmd prompt. Make sure your $path environment variable is configured to find tfpt.exe

4. Change directory to the workspace

5. Give this command: rollback /changeset:{Change-Set Number}
(For example rollback /changeset:39356)

6. It will take latest of all your workspace. This is what I don’t like as it doesn’t work otherwise. It takes some but works…

7. After above step, tfpt has taken older version and all those file will be ready to be check-in with older viersion.. Check-in those and take a tea.

Tip [02/24/2009]: Step 6 may kill you if you are storing huge amount of data into TFS. I advice you to create a new workspace with only required files downloaded. For Example, if your all changes are in '$codebase/folder/subfolder/" then create workspace for $codebase/folder/subfolder/ mapped to local directory C:\for_rollback\ Due to this, step 6 will become very fast.

Powertool help and website: http://msdn.microsoft.com/en-us/tfs2008/bb980963.aspx

Friday, March 14, 2008

Thursday, January 17, 2008

Customizing Visual Studio Compare and Merge Utility

Are you missing your favorite file compare utility because TFS ships diffmerge utility? No doubt the it has solid merge utility but compare only shows horizontal comparison and leaves us without any clue about what’s changed in the highlighted (until we manually find the change in highlighted line).

I have many time tired gvim to compare 2 files. Here is a trick by which you can put your ‘favorite utility’ on fire.

Go to Visual Studio -> Tools -> Option -> Source Control -> Visual Studio TFS. Click on ‘Configure User Tools…”. Here you can configure your ‘Compare’ and ‘Merge’ tools separately.

This is my configuration:

Extension: .cs
Operation: Compare
Command: C:\Program Files\Vim\vim71\gvim.exe (you have to fully qualify the path. Specific for GVim, add C:\Program Files\Vim\vim71 to your $Path)
Arguments: -dR %1 %2

Also, you can pass various arguments for existing diffmerge utility. Here is example to pass ‘ignorespace’ argument.

Extension: .cs
Operation: Merge
Command: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\diffmerge.exe
Arguments: /ignorespace /merge %1 %2 %3 %4 %6 %7

Although /ignorespace is not a recommended but you may want that to do in some specific case.

See complete tutorial here... http://blogs.msdn.com/jmanning/articles/535573.aspx

Friday, January 11, 2008

“generator” element in .hbm file

Recently I was stuck in a peculiar problem where I couldn’t insert a new record in a table using NHibernate. It came out to be the .hbm file which was giving problem. Because our DO generators are written so well, we looked for the bug there at last.

NHibernate class generator always creates class thinking that the primary key will be ‘auto-generated’. But that table doesn’t have auto-generated primary key. And so the “generator” element was incorrectly set to ‘native’ (i.e. auto-generated) for that table.

About “generator” element:

If the value of this is set to ‘native’, the key is auto-generated. Set ‘specified’ to set the primary key yourself in code. See link below for description of all values that generator can have. Note that ‘specified’ is the default in case “generator” element is absent in hbm file.

Link: http://www.roseindia.net/hibernate/hibernateidgeneratorelement.shtml

Wednesday, January 09, 2008

Throw Exception

You might have figured out ‘Find 10 difference’ column in from your favorite news paper. Here comes it again with finding one difference that affects your code:

try
{
}

catch (Exception)
{

throw;
}

and

try
{
}

catch (Exception ex)
{
throw ex;
}

Answer: In case of ‘rethrowing’ exception, 1st case would still save the stack trace. Re-throwing the same exception in 2nd case will result into losing your stack trace.

Thursday, July 19, 2007

Regex with Named Groups

Suppose you want to remove a middle name from name you can use “replace” method in your favorite language/editor in this way..
You Regulare Expression: (?(\w+))\s*(?(\w+))\s*(?(\w+))\s*

Replace with: ${ FirstName } ${ LastName }

Some days before when I needed help about this, googling didn’t help much. If you come across any good link about this, don’t forget to put a comment here.

(This may be a bad example but I am using it just for simplicity and the sole objective of this blog is to understand 'named group' or 'variable')

[Updates]
Tutorial Link:
http://www.regular-expressions.info/named.html

Thursday, July 05, 2007

AndAnd and only And

From my little experience itself, I’ve seen various ‘demonic’ forms of condition that we put into ‘if’ (or ‘while’ loop). Sometime the combinations of ‘And’, ‘Or’ and ‘Not’s will scare hell out of you. But here is a classic case: Suppose you are applying ‘And’ condition and (in c# at least) you have used ‘&’ (which is bitwise operator) instead of ‘&&’. In most of the case this won’t give any problem unless you do something like this,

If( a != null & a.Count > 0)
{ do_something; }

It will catch you and exception will be thrown saying you want something which doesn’t exist.

NOTE: ‘&&’ is totally safe for above example as && will evaluate the second condition only when the first is true.