Thursday, January 24, 2019

Windows Putty Reverse Tunnel/ OpenSSH Gotchas


OpenSSH Install
  • The configuration is stored in C:\ProgramData\SSH folder
  • Need to comment out #Match Group Administrators section
  • The ".ssh" folder must be validated for each user properly. Sometimes, if you create ".ssh", windows will create ",ssh" (comma instead of dot)
  • .ssh folder should only have permissions for SYSTEM, user and administrators. No other users at all
  • Make sure both SSH service and Authentication Agent services are running
PC behind firewall:

  1. Install Putty on the NUC
  2. In Putty, create a new session
    1. Host:
    2. In category on left, select Connection
      1. Under seconds between keepalives - set to 30
      2. Check Enable TCP Keepalives
    3. In category on left, select Connection > SSH > Auth
      1. Click on browse the select the key file
    4. In category on left, select Connection > SSH > Tunnels
      1. Source Port: 9999 (remember this)
      2. Destination: localhost:3389
      3. Change from Local to Remote
      4. Change from Auto to IPv4
      5. Click on Add
    5. In category on left, select session
    6. Under Save sessions, give a name "home-rdp-reverse"
    7. Click on Open to verify that the SSH session opens
  3. Create a batch file such as remote-link.bat with plink to run in a loop. plink is a putty utility where you can provide putty saved session name to execute. Something like:
    1. plink "home-rdp-reverse"
  4. Run this batch file to ensure that the connection is established properly without any issues
  5. Add batch file to startup so that it runs as soon as machine is started
  6. Restart the machine and verify
  7. Note: The port 9999 above is unique for this particular install. Each install will require its own source port which we can manage separately
Connected remotely:

  1. Open Putty on your machine and create a new session
    1. Repeat step 2.1 from above
    2. Repeat step 2.2 from above
    3. In category on left, select Connections > SSH > Tunnels
      1. Source Port: 5002
      2. Destination: localhost:9999 (this is the port for specific PC we want to RDP)
      3. Keep Local
      4. Change from Auto to IPv4
      5. Click on Add
    4. In category on left, select session
    5. Under Save sessions, give a name such as "college-server-rdp"
    6. Click on Open to verify that the SSH session opens
    7. Open Remote Desktop Connection client
    8. Connect to localhost:5002 (source port from above)
    9. Enter credentials applicable to machine in the college
Reference/ Help: https://vincetocco.com/how-to-setup-a-reverse-tunnel-with-putty/

Tuesday, June 30, 2015

Commit hook on Windows for Git

Configuration must be set in the config file on server. Sample:

        mailinglist = programming@xyz.com
commitlist = programming@xyz.com
mailer = smtp
environment = generic
smtpserver = mail.xyz.com
smtpserverusername = noreply@xyz.com
smtpserverpassword = d
smtpusername = noreply@xyz.com
smtpuser = noreply@xyz
smtppass = d
from = noreply@xyz.com

post-receive may look something like:

#!/bin/sh
echo PWD is $PWD
\\python27\\python hooks/git_multimail.py

Friday, June 07, 2013

TortoiseSVN settings to use DiffMerge

Diff Viewer: C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe /t1=Original /t2=Mine %base %mine

Merge: C:\Program Files\SourceGear\Common\DiffMerge\sgdm.exe /t1=Theirs /t2=Base /t3=Mine /r=%merged %theirs %base %mine

Friday, March 01, 2013

Sencha Touch 2: Weird Issue

We were adding some components to Viewport without adding an itemId. In that case, "show" event was firing multiple times (one for each time the component was added - not ignoring the removed components).

Friday, June 24, 2011

SQL Server: Top (variable) vs TOP n

For past week or so, we have been struggling with performance issues in one of our applications using SQL Server. Some of the queries are quite complex and SQL Query Optimizer spends almost 1500-2000 ms in Parse and Compile whereas execution takes about 500ms. We tried our best to reduce compile time but we couldn't so we left it to a later date.

Now, the biggest problem remaining was that the SQL Query Plan wasn't getting re-used. In the application, users can use pagination and on every page change, query was getting compiled repeatedly. What I found was a bit strange. The way our code called was something like:

SELECT TOP 10 * FROM vwCustomerList
SELECT TOP 20 * FROM vwCustomerList
...

So, we were a bit stumped. Just our of curiosity, I changed the queries to:

SELECT TOP (@Top) FROM vwCustomerList

And passed @Top as the parameter. Now, suddenly the query plans were reused and application was back to good speed.

The good thing was almost all the queries from our application are executed through the same set of libraries and hence I was able to modify code at just one place and all the queries benefit from this performance boost!

Friday, October 23, 2009

Setting up Windows 2008 – Some of the steps

  1. SQL Server 2008: Ensure that port is opened in firewall and TCP IP settings are specified in Surface area configuration
  2. Install FTP 7.5 separately
  3. With classic ASP, error reporting is turned off by default. Enable in Web Server
  4. CDO is not installed by default. Download and install and  don’t forget to give permissions to NETWORK SERVICE account.
  5. SMTP/ IMAP/ POP3/ FTP require ports to be opened in firewall
  6. For PHP also, turn on detailed error logs by
    %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/httpErrors -errorMode:Detailed

Thursday, August 06, 2009

Checking space used by SQL Tables and reorganizing those

SET NOCOUNT ON
/*DATABASE TABLE SPY SCRIPT
Micheal Soelter
1/24/03
DESCRIPTION
Returns TABLE Size Information
SORTING USAGE
@Sort bit VALUES
0 = Alphabetically BY TABLE name
1 = Sorted BY total space used by TABLE
*/
DECLARE @cmdstr varchar(100)
DECLARE @Sort bit
SELECT @Sort = 1 /* Edit this value FOR sorting options */
/* DO NOT EDIT ANY CODE BELOW THIS LINE */
--Create Temporary Table
CREATE TABLE #TempTable
( [Table_Name] varchar(50),
Row_Count int,
Table_Size varchar(50),
Data_Space_Used varchar(50),
Index_Space_Used varchar(50),
Unused_Space varchar(50)
)
--Create Stored Procedure String
SELECT @cmdstr = 'sp_msforeachtable ''sp_spaceused "?"'''
--Populate Tempoary Table
INSERT INTO #TempTable EXEC(@cmdstr)
--Determine sorting method
IF @Sort = 0


BEGIN
--Retrieve Table Data and Sort Alphabet
-- ically
SELECT * FROM #TempTable ORDER BY Table_Name
END

ELSE


BEGIN
/*Retrieve TABLE Data AND Sort BY the size OF the Table*/
SELECT * FROM #TempTable ORDER BY CAST(SUBSTRING(Table_Size,1,CHARINDEX(' ',Table_Size,1)) AS INT) DESC
END

DECLARE @TableName varchar(100)
DECLARE TestCursor CURSOR FOR SELECT Table_Name FROM #TempTable FAST_FORWARD
OPEN TestCursor
FETCH NEXT FROM TestCursor INTO @TableName
WHILE @@FETCH_STATUS = 0 BEGIN
DBCC CLEANTABLE(0, @TableName)
FETCH NEXT FROM TestCursor INTO @TableName
END
CLOSE TestCursor
DEALLOCATE TestCursor

--Delete Temporay Table
DROP TABLE #TempTable

Saturday, August 02, 2008

Updates about me

Recently one of my friend suggested me to split my blog into Hindi and English version. Although his idea was good considering the fact that audience is different but my question is - isn't blog like a personal diary? How many people are really treating it like that? Anyways, regardless of that, I've created a new blog durlabhjain.blogspot.com where I'll be posting my Hindi entries and this blog will continue to be more about my technical/ professional learnings...

Monday, July 28, 2008

वक्त!

अकेला था, अकेला हूँ, अकेला ही जाऊँगा,
करता फ़िर रहा जो इकठ्ठा कहाँ ले जाऊँगा
सब यहीं पर था, यहीं पर है, यहीं रह जायेगा,
शायद ही किसी को मेरा नाम याद रह पायेगा!
मगर फ़िर भी इच्छा यही है की इस को, उस को, और न जाने किस किस को अपना कह सकूं मैं,
इसी इकठ्ठा करने की एक अजीब सी कशिश में, क्यूँ न ख़ुद को खुश रख सकूँ मैं!
पैसे का क्या वोह तो आज अगर मेरी जेब में तो कल किसी और की जेब में जायेगा,
अरे मन इतना समझ ले की यह जो वक्त बीत रहा है ये न फ़िर वापस आयेगा!!

दो पंक्तियाँ

ना पूछो मुझसे की ये मुझको हुआ क्या है
जानना है मुझको की बता ए वक्त तुझमे छुपा क्या है?
क्यों यूँ तिल तिल कर के खोलता है परत दर परत,
क्यों यूँ हमेशा आस देता है तू पल पल, की होगी सुबह जल्दी से
बस इस बदलने की आस में यूँ बिताता हूँ में अब हर एक पल
शायद आज से अच्छा ही होगा जो आने वाला है कल!
समय के इस फेर में मैं भूल सा गया हूँ की आज की भी कितनी महत्ता है
जरा सी देख की मुश्किल यह दिल कुछ ऐसे बहकता है
संभाले नही संभलता, आंसू आ ही जाते हैं बस आँखें साथ नहीं देतीं
कब का छूट गया होता साथ इस जिंदगी का जो उम्मीद मेरा दामन थाम नही लेती!
अब जब थामा है हाथ तो बीच मझधार में मुझे छोड़ ना देना
मेरा जो कल अच्छा होने का सपना है वो तोड़ ना देना

Saturday, July 12, 2008

Hyperlink Column in ASP.NET

By default, hyperlink column doesn't allow using Javascript. For this, I inherited from BoundField to have more control.


Public Class HyperlinkBoundField
Inherits BoundField
Public NavigateUrlFormatString As String
Public NoLinkValue As String

Public Sub New()
MyBase.New()
End Sub

Public Sub New(ByVal field As BoundField, ByVal noLinkValue As String, ByVal urlFormat As String)
Me.DataField = field.DataField
Me.HeaderText = field.HeaderText
Me.HeaderImageUrl = field.HeaderImageUrl
Me.SortExpression = field.SortExpression
Me.NoLinkValue = noLinkValue
Me.NavigateUrlFormatString = urlFormat
End Sub

Protected Overrides Function FormatDataValue(ByVal dataValue As Object, ByVal encode As Boolean) As String
Dim value As String = MyBase.FormatDataValue(dataValue, encode)
If String.IsNullOrEmpty(value) OrElse value = NoLinkValue Then
Return value
Else
Return String.Format(NavigateUrlFormatString, value)
End If
End Function
End Class

Saturday, May 10, 2008

ASP.NET - I'm starting to loose love for it!!

I have been swearing by Microsoft Technologies since CA took over Clipper and then dumped it!!! Clipper used to by a bread and butter language for me until 1995 (2 years after CA dumped it). At that time, I had a terrible time on deciding which way to go. Delphi was quite popular and was quite similar to Pascal and then there was VB! I decided that considering Microsoft's might, Microsoft won't easily dump its product. Anyways, Microsoft left its VB coders way behind after VB 6.0. VB.NET was similar but strikingly different as was. It was a new learning but ok - a gradual change. But then there was a promise of platform independence and I was lured by it! Web was getting more and more popular and developing applications in VB.NET seemed to be much faster/ easier than ASP. At-least it was more structured and much more testable with lots of compile time checks. Initially it looked like that continuously increasing build times even for small changes were a small sacrifice in face of structure. However, as I went deeper and deeper it seems that even trivial tasks are not that easy because of Microsoft's decision to take the web development to event driven applications. Numerous times it has happened that it has become difficult to understand what is happening during which event (in the framework) and without a tool such as reflector, it would have been impossible to resolve lots of issues we had in many of the applications. Some of the recent issues I've faced are:
  • URL Rewriting: Ok. It might not really be a .NET thing and IIS thing but unfortunately .NET doesn't run on Apache. Features that apache's mod_rewrite has been providing for so long are still difficult to achieve in IIS.
  • SetMaxAge for caching: Unfortunately, whatever value I set, it sets it to Zero. Refer to http://msmvps.com/blogs/omar/archive/2006/08/02/cache-control-header-cannot-be-set-properly-in-asp-net-2-0-a-solution.aspx
  • Removing a cookie from Cache: I thought it would be easy enough!!! Just set expiry of the cookie to a past date and you should be fine! In fact, I needed to remove all the cookies starting with "custom". The way I went ahead is...


HttpCookieCollection cookies = Request.Cookies;
for(int i=0; i<cookies.Count; i++) {
HttpCookie cookie = cookies[i];
if(cookie.Name.StartsWith("custom") {
cookie.Expiry = DateTime.Now.AddYears(-1);
}
}

  • seems cool? No. turns out that if you modify cookies in Request, it doesn't help. You have a Response.Cookies collection as well. Unless you add a cookie to Response collection, it won't be sent to client and hence client will not know you changed the cookie. Anyways, I added a couple of statements to add cookies in Response collection. Then, another problem. When you add a cookie to Response collection, it gets added to Request collection as well!!! Another issue. So, as many people suggest, I had to take another variable cookieCount before the loop to avoid an endless loop! What a waste of time for simple Cookie manipulation that was so easy in languages such as PHP, ASP etc. etc.
There are lot more things that I'm discovering on daily basis. However, then my biggest worry is about MVC architecture that's becoming a lot more popular in ASP.NET again leaving me wondering how long will Microsoft continue to support the original ASP.NET Page Model? I doubt it'll take long before Microsoft will have to decide the model it wants to support!!

All this has been forcing me to re-think my strategy and look back at PHP, ASP or Ruby on Rails to get sanity back to development as most of the front-ends have actually moved to HTML and JS and these languages just handle the server side manipulation. Wait for a few more days and you might see me changing my framework to PHP!!!

Saturday, May 03, 2008

दीवाना हमें बताती हैं!

दिखाती हैं नखरे, दिखाती हैं अदाएँ,
लड़कों को अपने पीछे घुमाएँ
मगर आयें पीछे तो दूर भगाती हैं
दीवानी ख़ुद हैं और हमें दीवाना बताती हैं!
पहने कपड़े सेक्सी सेक्सी, फिर स्टाइल में चलती हैं
दिखाने को importance अपनी, हर पल अदाएँ बदलती हैं
देख के अदाएँ सीटी बजायें हम जो, लफंगा हमें बताती हैं
दीवानी ख़ुद हैं और हमें दीवाना बताती हैं!
पहनें sandle हील की ऊँचे, ख़ुद नागिन सी लहरायें,
देख के सेक्सी पतली टांगें लम्बी, जो कोई पीछे आए,
कभी कभी तो पब्लिक में ही, पब्लिक से पिटवाती हैं,
दीवानी ख़ुद हैं और हमें दीवाना बताती हैं!
काले काले नैना इनके, नजरें हैं मतवाली,
लगे इन्ही में है दुनिया सारी, जब तक न बने ये घरवाली,
फिर घरवाली बन के सुबह शाम ये, हमको यूँ सताती हैं,
जान बूझ के फंस जाते हैं हम, ये ऐसा हमें घुमाती हैं,
दीवाना बनाती हैं ख़ुद हमें और दीवाना हमें बताती हैं
और जब लिख दें ये जब ब्लॉग पर तो हम पर खूब चिल्लाती हैं,
दीवानी ख़ुद है और हमें दीवाना बताती हैं!

Tuesday, February 19, 2008

SQLite - A cool database engine

Since last year or so, I've been exploring SQLite as a database engine for couple of small apps for personal use. I must say, I'm impressed by this little engine so much that I sometimes curse myself... why didn't I find it earlier :)

Saturday, January 12, 2008

Partition/ Data Protection and other tools I use

Personal data storage is always a tricky issue. For example, on my computer I usually store my accounts data, code that I wouldn't like to expose. In fact, for few of my old clients, I give them the source code in an encrypted mode so that it is their responsibility to backup/ save and they can get it modified by other programmers also if they wish to. In the past, I have used tools like:

  • RAR/ PKZIP with Password: A bad choice but the only choice in DOS days. Ultimately, we had to de-compress to work and then again compress. This was a manual process and error-prone resulting in leakages sometimes. So, I moved on with better tools:
  • BestCrypt: With advent This could create a protected file that can be mounted like a volume. However, the cost/ licensing of the tool prohibited me from installing the tool on the client sites. So, I primarily used it on my laptop and just copied the volume on their machines. But this was easier and provided good level of protection.

And now:

  • TrueCrypt: Recently, during a visit to one of my client, I found that they were using TrueCrypt! That was interesting. I had never heard of this tool. I searched and found that it was FREE!! Offered everything I wanted and I can install it for my clients too. Reviews are great. That means, this is the tool of my choice now.

Then there is another issue. With so many sites, partitions and areas where we need to put in password the risk is - how do I record passwords so that I don't forget!! One of the easier route is - keep the password same but that's risky. In addition, many tools/ sites have different restrictions on password strength, length, combination, expiry etc. So this is not a good strategy. I want to keep strong passwords for any sites where I can shop (like Amazon, PayPal) and banks. So, I started using KeePass - another freeware that I can use to generate and store my passwords without the hassle of remembering every password.

Now, as of today, here is a list some tools I use:

  • Protection: KeePass, TrueCrypt
  • Version Control: VisualSVN Server (Subversion), TortoiseSVN, Perforce Diff/ Merge (For better diff and merge functionality)
  • AntiVirus: Nod32 - found it to be quite fast. With other antivirus such as Kaspersky, McAfeee etc., my Visual Studio project compilation times were quite high. Even AVG was good in the past but its reliability score isn't that good.
  • FTP: FileZilla
  • CD/DVD Emulator: Daemon Tools
  • CD/DVD Writer: InfraRecorder
  • Media Player: Media Player Classic from K-Lite Codec Pack
  • Remote Access: TeamViewer
  • Web Conferencing: Yugma
  • Messengers: Google Talk, Trillian, Skype  - I hate multiple clients but have to use them :(
  • Browser: Mozilla Firefox with Firebug
  • PDF Reader: FoxIt Reader - thank got - no more Acrobat reader
  • RSS Feed Reader: JetBrains Omea Reader (Though I'll be looking at NewGator products as well now as they went free)
  • Compression: WinRAR
  • Other Development Tools: Reflector, MyGeneration (Code Generator)
  • Blog Writing: Windows Live Writer (for now)

Apart from these, I just use Visual Studio 2008, SQL Server 2005 (Developer Edition), Microsoft Office and sometimes Internet Explorer! I'm always looking for leaner, faster alternatives.