Saturday, August 16, 2014

Download Torrent File From Magnet Uri

As the name suggets its a simple desktop app that takes "Magnet-Uri" as input & download the "Torrent" file associated with it. I created this because I use multiple PC & I hate searching for same TORRENT file multiple times, thats why I created this.

Check it Out: https://github.com/KhanZeeshan/MagetUri_TorrentFile

Wednesday, May 21, 2014

WCF problem with POSTs using ssl (https)

I recently faced a problem in one of my WCF projects with HTTPS data packet size, you can change the data packet size only for HTTP binding in WCF but not for HTTPS binding, if you want to know how to do change HTTP binding click here. To send large data on HTTPS you just have to add the following line in your HTTP binding tag then that setting will work for HTTPS too.

<security mode="Transport"> 
Just an FYI after adding this line in your webconfig file you are forcing user to use HTTPS now for that specific binding.

Wednesday, January 22, 2014

SQL Azure Bacpac - Local Restore

If you need to export a SQL Azure database and then import it into a local SQL 2008 R2 server (Note I am also using Visual Studio 2010). Microsoft certainly went out of their way to make this a painful task, however, I was able to do it by doing the following:

Goto this link http://msdn.microsoft.com/en-us/jj650014 and install the SQL Server Data Tools for Visual Studio 2010

This will install on your local drive. In my case here is where it put it: C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin

Browse to this via the command line or powershell

You are going to want to execute the SqlPackage.exe

Open up this link to see a list of all the parameter options for SqlPackage.exe (http://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx)

Here is my command line that I needed to execute to import a .bacpac file into my local SQL 2008 R2 server:

.\SqlPackage.exe /a:Import /sf:C:\mydatabasefile.bacpac /tdn:NorthWind /tsn:BINGBONG

/tdn is the name of the database you want your bacpac file to restore to. /tsn is the name of your SQL server.

You can see all these parameter descriptions on the link from #5.

Tuesday, September 3, 2013

HTC One - NFC Issue

If you want to Send Data through NFC from any smart phone to HTC One make sure sender phone is higher than the HTC One, make sure the camera of your sender phone is almost at the top white line of HTC One.

*No need to enable Bluetooth or anything, just enable NFC in both phone.

Tuesday, August 13, 2013

You don't have any devices - Google Play website

Go to Settings > Apps > All > Scroll Down And Select Google Play Store > Force stop and clear data.
Also do the same for "Google Play Services" (Just for the safe side)
Then open the play store again on your device and accept the terms and conditions.

Wait 15 minutes or 30 minutes or 1 hour, you will see your device. 

Monday, June 24, 2013

Enable AirPrint on Windows (32/64Bit) with iOS 5+ Support

Solution # 1

Instructions:
After extraction you should have three files:
- "AirPrint_Installer.exe"
- "AirPrint iOS 5 FIX - 32Bit.reg"
- "AirPrint iOS 5 FIX - 64Bit.reg"

1. Run "AirPrint_Installer.exe" and then click on "Install AirPrint Service".

2. Run the "AirPrint iOS 5 FIX - 32Bit.reg" or "AirPrint iOS 5 FIX - 64Bit.reg" to install the iOS 5 fix (Choose the correct file for you operating system, 32 Bit or 64 Bit Windows).

3. Go back to "AirPrint_Installer.exe", make sure "Service Startup" is set to "Auto" and click "Start".

4. Restart computer.

If there is a locked icon next to the printer on the iOS device enable the guest account in windows (Control Panel > User Accounts > Manage Another Account > Turn the Guest Account on). Then in the "AirPrint_Installer.exe" choose to use Guest Account Auth and tick the "Enable Guest Account" box. Then click "Update". You will then need to restart. If you want windows to automatically log you in on startup, type "netplwiz" into the start menu search box, hit enter. Uncheck the box that says “Users must enter a user name and password to use this computer”, and then hit Apply. You’ll see a username and password box. Enter in the appropriate information here and hit OK..


Solution # 2
Enable the guest account on the windows 7 machine.
Restart the Airprint service.

Wednesday, May 22, 2013

Android - Creating a Navigation Drawer

Following Link explains in detail how a drawer navigation can be added to an android application using the new guidelines & pattern explained in Google I/O 2013.

http://gmariotti.blogspot.com/2013/05/creating-navigation-drawer.html

PS;
For Devices having OS Honeycomb or greater.

Thursday, February 21, 2013

C# - Run Only One Instance of An Application/Singleton Application

Place the following code in Main function of Program.cs class


[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

bool createdNew = true;
using (Mutex mutex = new Mutex(true, Application.ProductName, out createdNew))
{
        if (createdNew)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        else
        {
            Process current = Process.GetCurrentProcess();
            foreach (Process process in Process.GetProcessesByName(current.ProcessName))
            {
                 if (process.Id != current.Id)
                 {
                      SetForegroundWindow(process.MainWindowHandle);
                      break;
                 }
             }
         }
}

Monday, January 7, 2013

Android - Get Device's Unique Identifier(UID)

String deviceId = Secure.getString(this.getContentResolver(),
                Secure.ANDROID_ID);
returns the Android ID as an unique 64-bit hex string.

Saturday, December 15, 2012

Android - Place Tab at the bottom


Here's the simplest, most robust, and scalable solution to get tabs on the bottom of the screen.
  1. In your vertical LinearLayout, put the FrameLayout above the TabWidget
  2. Set layout_height to wrap_content on both FrameLayout and TabWidget
  3. Set FrameLayout's android:layout_weight="1"
  4. Set TabWidget's android:layout_weight="0" (0 is default, but for emphasis, readability, etc)
  5. Set TabWidget's android:layout_marginBottom="-4dp" (to remove the bottom divider)

Thursday, September 20, 2012

A Small Collection of SQL Azure Queries


-- Get version information
SELECT @@VERSION AS [SQL Version Info];

-- SQL Azure Builds 
-- Build            Description
-- 10.25.9200        RTM Service Update 1
-- 10.25.9268        RTM Service Update 2
-- 10.25.9331        RTM Service Update 3
-- 10.25.9386        RTM Service Update 4
-- 10.25.9445        RTM Service Update 5
-- 10.25.9501        RTM Service Update "5a" (Nov 3, 2010)


-- You must be connected to master database
-- to run these queries

-- Get bandwidth usage by database by hour (for billing)
SELECT database_name, direction, class, time_period, 
       quantity AS [KB Transferred], [time]
FROM sys.bandwidth_usage
ORDER BY [time] DESC;

-- Get overall cost by SKU in dollars
SELECT SKU, SUM    (CASE WHEN USAGE.SKU = N'Web'
                            THEN (Quantity * 9.99/31)
                       WHEN USAGE.SKU = N'Business'
                          THEN (Quantity * 99.99/31)
                 END ) AS [CostInDollars]
FROM sys.Database_Usage AS USAGE
WHERE DATEPART(yy, TIME) = DATEPART(yy, GetUTCDate())
AND DATEPART(mm, TIME) = DATEPART(mm, GetUTCDate())
GROUP BY SKU;


-- Get Bandwidth cost by direction and type
SELECT USAGE.Time_Period, USAGE.Direction,
            CASE WHEN USAGE.Direction = N'Egress'
                    THEN 0.15 * USAGE.BandwidthInKB/(1024 * 1024)
                     WHEN USAGE.DIRECTION = N'Ingress'
                    THEN 0.10 * USAGE.BandwidthInKB/(1024 * 1024)
            END AS [CostInDollars]
FROM (SELECT Time_Period, Direction, SUM(Quantity) AS [BandwidthInKB]
       FROM sys.Bandwidth_Usage
       WHERE  DATEPART(yy, TIME) = DATEPART(yy, GetUTCDate())
       AND    DATEPART(mm, TIME) = DATEPART(mm, GetUTCDate())
       AND class = N'External'
       GROUP BY Time_Period, Direction) AS USAGE;


-- Get number of databases by SKU for this SQL Azure account (for billing)
SELECT sku, quantity, [time]
FROM sys.database_usage
ORDER BY [time] DESC;

-- Get firewall rules (must be connected to master)
SELECT id, name, start_ip_address, end_ip_address, 
create_date, modify_date 
FROM sys.firewall_rules
ORDER BY id;

-- List all logins on "instance" (must be connected to master)
SELECT name, principal_id, [sid], type_desc, 
       is_disabled, create_date, default_database_name
FROM sys.sql_logins
ORDER BY name;

-- List all databases (must be connected to master)
SELECT name, database_id, create_date, [compatibility_level]
FROM sys.databases;


-- Must connect to a user database 
-- in order to run these queries

-- Get max allowed size of database (use your database name)
SELECT CONVERT(BIGINT, DATABASEPROPERTYEX('ngservices' , 'MaxSizeInBytes'))/1073741824.0  AS [MaxSizeInGB];

-- Get current size of database
SELECT (SUM(reserved_page_count) * 8192)/1048576.0 AS [Database Size in MB]
FROM sys.dm_db_partition_stats;

-- Switch to Business Edition ($99.99/month)
ALTER DATABASE AdventureWorksLT2008R2 
MODIFY (EDITION = 'BUSINESS', MAXSIZE = 10GB);

-- Refresh SQL Azure Portal web page to see change

-- Switch to Web Edition ($9.99/month)
ALTER DATABASE AdventureWorksLT2008R2 
MODIFY (EDITION = 'WEB', MAXSIZE = 1GB);



-- Get row counts for tables in current database
SELECT OBJECT_NAME(object_id) AS [ObjectName], row_count, object_id, index_id 
FROM sys.dm_db_partition_stats
WHERE index_id < 2
ORDER BY row_count DESC;

-- Monitor connections in current database
SELECT s.session_id, s.login_name, e.connection_id,
      s.last_request_end_time, s.cpu_time, 
      e.connect_time
FROM sys.dm_exec_sessions AS s
INNER JOIN sys.dm_exec_connections AS e
ON s.session_id = e.session_id
ORDER BY s.login_name;


-- Get session count by host name
SELECT [host_name], COUNT(*) AS [SessionCount] 
FROM sys.dm_exec_sessions AS s
GROUP BY [host_name]
ORDER BY [host_name]; 


-- Top Cached Plans By Execution Count
SELECT q.[text], hcpu.total_worker_time, 
       hcpu.execution_count, hcpu.plan_handle
FROM 
    (SELECT TOP (50) qs.* 
     FROM sys.dm_exec_query_stats AS qs 
     ORDER BY qs.total_worker_time DESC) AS hcpu 
     CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS q 
ORDER BY hcpu.execution_count DESC;


-- Top Cached Plans By total worker time (CPU)
SELECT q.[text], hcpu.total_worker_time, 
       hcpu.execution_count, hcpu.plan_handle
FROM 
    (SELECT TOP (50) qs.* 
     FROM sys.dm_exec_query_stats AS qs 
     ORDER BY qs.total_worker_time DESC) AS hcpu 
     CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS q 
ORDER BY hcpu.total_worker_time DESC;

-- Find top Avg CPU time queries
SELECT TOP (25) MIN(query_stats.statement_text) AS [Statement Text], 
SUM(query_stats.total_worker_time) / SUM(query_stats.execution_count) AS [Avg CPU Time],
query_stats.query_hash AS [Query Hash]
FROM (SELECT QS.*, SUBSTRING(ST.[text], (QS.statement_start_offset/2) + 1,
    ((CASE statement_end_offset 
        WHEN -1 THEN DATALENGTH(st.[text])
        ELSE QS.statement_end_offset END 
            - QS.statement_start_offset)/2) + 1) AS statement_text
     FROM sys.dm_exec_query_stats AS QS
     CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) AS ST) AS query_stats
GROUP BY query_stats.query_hash
ORDER BY [Avg CPU Time] DESC;


-- Top Cached Plans By total logical reads (Memory)
SELECT q.[text], hcpu.total_logical_reads, 
       hcpu.execution_count, hcpu.plan_handle
FROM 
    (SELECT TOP (50) qs.* 
     FROM sys.dm_exec_query_stats AS qs 
     ORDER BY qs.total_worker_time DESC) AS hcpu 
     CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS q 
ORDER BY hcpu.total_logical_reads DESC;


-- Top Cached Plans By total elapsed time
SELECT q.[text], hcpu.total_elapsed_time, 
       hcpu.execution_count, hcpu.plan_handle
FROM 
    (SELECT TOP (50) qs.* 
     FROM sys.dm_exec_query_stats AS qs 
     ORDER BY qs.total_worker_time DESC) AS hcpu 
     CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS q 
ORDER BY hcpu.total_elapsed_time DESC;

-- This works in SQL Azure
EXEC sp_updatestats;

-- This works in SQL Azure
UPDATE STATISTICS CurrentPostMeta  -- This is a table name

-- DMVs that were added in SQL Azure Service Update 1
SELECT * FROM sys.dm_exec_connections; 
SELECT * FROM sys.dm_exec_requests; 
SELECT * FROM sys.dm_exec_sessions; 
SELECT * FROM sys.dm_tran_database_transactions;  
SELECT * FROM sys.dm_tran_active_transactions;

-- Other DMFs
SELECT * FROM sys.dm_exec_query_plan       -- needs a plan_handle
SELECT * FROM sys.dm_exec_sql_text           -- needs a plan_handle
SELECT * FROM sys.dm_exec_text_query_plan  -- needs a plan_handle, stmt_start_offset, stmt_end_offset
-- Get Occupied Size of Tables
select sys.objects.name, sum(reserved_page_count) * 8.0 / 1024 as MB
from sys.dm_db_partition_stats, 
     sys.objects 
where sys.dm_db_partition_stats.object_id = sys.objects.object_id 
group by sys.objects.name order by MB Desc