Friday, August 26, 2016

Revert strip in Hg Mercurial

So you are using Mercurial version control system and Tortoise Hg as its windows GUI tool. And after you made changes you accidentally clicked "Modify History -> Strip",



So strip command  removed all your changes! Don't worry, there is a way to recover from this action and bring those changes back. Follow these steps:

1. For every strip action, the changes are backed up automatically to the "REPO/.hg/strip-backup". Open the backup folder and copy the latest modified file name.



2. Open Hg terminal by clicking Repository->Terminal.



3. Run this command: hg pull $(hg root)/.hg/strip-backup/$(backup file name)


    Voila! Here comes the changes back:








Friday, April 8, 2016

How To Clear Wifi Password






If you have trouble with changing wifi password and cannot find and option to forget or clear an old wifi password on windows 8, here is a simple solution:

1. Open command prompt screen by pressing windows + r and type "cmd" enter.
2. run this command (profilename is the name of the wifi):
    netsh wlan delete profile name='profilename'

Thats all! Now when you try to connect it will ask your key again.

Sunday, August 3, 2014

How To Host Your Domain in Azure VPS

Let's say we have a domain name www.damaturk.com and we want to host it in Azure VPS (Virtual Private Server). The steps are as follows:

1. Remote desktop to the Azure VPS.
Navigate to https://manage.windowsazure.com click Virtual Machines, click connect.



2. Open IIS Manager. Assuming that your web site related files are copied under C:\inetpub\wwwroot, add your web site under sites.


3. Right click on your site and click edit bindings.
Click Add, enter your domain name and choose the internal ip from the combo box, at the end you should have two rows one with www prefix and one without.


4. Open Azure management portal again, click your virtual machine and click Endpoints. Add a new end point with port 80.


5. Go to your domain registrar site, open Manage DNS or something similar to add or change A record.
Enter (A) records as seen below:



Thursday, June 21, 2012

T-SQL Reading Image Type into Varchar From Database


declare @hexbin varbinary(max);
declare @vbin varbinary(max);
declare @hexstring1 varchar(8000)


-- convert varbinary to hexstring
select @hexbin = Data1 from Table1;
select @hexstring1 = '0x' + cast('' as xml).value('xs:hexBinary(sql:variable("@hexbin") )', 'varchar(max)');

-- replace '000' to '0' three '0's mean enter character
select @hexstring1 = replace(@hexstring1, '000', '0')

-- convert hexstring to varbinary
select @vbin = cast('' as xml).value('xs:hexBinary( substring(sql:variable("@hexstring1"), sql:column("t.pos")) )', 'varbinary(max)')
from (select case substring(@hexstring1, 1, 2) when '0x' then 3 else 0 end) as t(pos)

-- cast varbinary as varchar
print cast(@vbin as varchar)

Thursday, October 15, 2009

Useful T-SQL (MSSQL 2000, SQLEXPRESS, MSDE) Queries

Most of database jobs in the MSSQL2000 or MSSQL2005 world are done with Enterprise Manager or SQL Server Management Studio Express respectively. In some occasions where those tools are corrupted or even doesn't exist (especially if you are using MSDE) you have to use T-SQL queries.

Most useful T-SQL queries;


  • How to CREATE a new database;
CREATE DATABASE DB1
ON
( NAME = DB1_dat,
FILENAME = 'C:\DB1_dat.MDF' )
LOG ON
( NAME = DB1_log,
FILENAME = 'C:\DB1_log.LDF' )
COLLATE SQL_Latin1_General_CP1254_CI_AS
  • How to BACKUP a database;
BACKUP DATABASE DB1
TO DISK = 'C:\DB1.Bak'

  • How to RESTORE a database from a backup file;
RESTORE DATABASE DB1
FROM DISK = 'c:\DB1.bak'
  • How to DETACH a database
sp_detach_db DB1
  • How to ATTACH a database
EXEC sp_attach_db @dbname = N'DB1',
@filename1 = N'c:\DB1_dat.mdf',
@filename2 = N'c:\DB1_log.ldf'




  • "is dependent on column 'Description'." error:

ALTER TABLE Table1
DROP COLUMN Depth

Note: if you get such errors like;
-The object 'DF__Table1__Descript__5C37ACAD' is dependent on column 'Description'.
-The object 'CK__Table1__Height__5D2BD0E6' is dependent on column 'Height'.
-The object 'PK__Table1__5B438874' is dependent on column 'RowId'.

Let's explain the errors. The first error is raised while trying to drop column name "Description" from the table. The error states that there is an object dependent to this column. Note that the name of the object starts with "DF_" which tells that this is a "Default Constraint" defined for the column. So we have to drop this constraint object first, to avoid the error. We can do that with the following query;

ALTER TABLE Table1
DROP CONSTRAINT
DF__Table1__Descript__5C37ACAD

The rest of the errors are respectively for the objects Check Constraint for the column "Height" and a Primary Key Constraint for the column "RowId". We can handle the errors running the DROP CONSTRAINT commands for each constraint.


  • How to CREATE INDEX for a table
nonclustered index
CREATE NONCLUSTERED INDEX Idx_Depth
ON Table1 (Depth)

clustered index
CREATE CLUSTERED INDEX Idx_Depth2
ON Table1 (Depth)



  • How to make a Case Sensitive Search;
If a database is created with default collation and the default database collation is case insensitive then the search for varchar columns will be case insensitive. To get the result we want, we can force the query to use another collation which is case sensitive.
SELECT * FROM Table1 WHERE description COLLATE Latin1_General_CS_AS = 'avalue'




  • How To Shrink Database Log File

We first find the logical names;
Select name,* from sysfiles










name field gives us the logical name information. Using the logical names we run the sql below;
DBCC SHRINKFILE(Northwind_log, 1)
BACKUP LOG Northwind WITH TRUNCATE_ONLY
DBCC SHRINKFILE(Northwind_log, 1)