Skip to content

Instantly share code, notes, and snippets.

@umair-me
umair-me / slow_mouse_pi.bash
Last active February 15, 2019 09:12
Fix for slow mouse on Raspberry Pi
Type into Command line:
sudo nano /boot/cmdline.txt
add onto the end of the line “usbhid.mousepoll=0” without quotes (note if still slow on 0 try 1)
save the file (ctrl+o)
then: sudo reboot
Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF
Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH
Keys are generic ones. These are the same from MSDN account.
Product Key : -6Q8QF
Validity : Valid
Product ID : 00369-90000-00000-AA703
Advanced ID : XXXXX-03699-000-000000-00-1032-9200.0000-0672017
@umair-me
umair-me / ram_usage.sql
Created February 5, 2018 14:10
List the MB of RAM used by each database
SELECT
MemoryUsage.DatabaseName,
SUM(MBUsed)
FROM
(
SELECT DB_NAME(t.dbid) AS DatabaseName, SUM(size_in_bytes/(1024*1024)) AS MBUsed
FROM sys.dm_exec_cached_plans AS p
CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t
WHERE t.dbid < 32767
GROUP BY t.dbid
@umair-me
umair-me / restore_stuck_database.sql
Created November 15, 2017 11:44
Restore a stuck database in "Restoring Mode"
RESTORE DATABASE <database name> WITH RECOVERY
@umair-me
umair-me / shrink.sql
Created October 31, 2017 16:02
Shrink database
-- change the database > properties > options > recovery model to "simple" in database
-- or use this ALTER DATABASE testdb SET RECOVERY SIMPLE;
USE {DatabaseName}
DBCC SHRINKFILE ('{Log file logical name}')
@umair-me
umair-me / action_name_expression_func
Last active August 18, 2016 13:07
Action Name strings to Expression Func - get the method name by using a better way instead of hard-coding strings names for actions
Expression<Func<ProductController, ActionResult>> add = (p => p.Add(null));
Expression<Func<ProductController, ActionResult>> edit = (p => p.Edit(null));
var action = (Id == 0) ? add : edit;
string actionMethodName = ((MethodCallExpression)action.Body).Method.Name;
@umair-me
umair-me / web.config
Created April 19, 2016 13:03
Redirect a site using web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="https://[HTTPSSITEURL]$S$Q" exactDestination="true" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
@umair-me
umair-me / list_all_columns.sql
Created April 6, 2016 10:43
List all columns in tables and views
SELECT
SO.NAME AS "Table Name"
, SC.NAME AS "Column Name"
, SM.TEXT AS "Default Value"
FROM
dbo.sysobjects SO
INNER JOIN
dbo.syscolumns SC
ON
SO.id = SC.id
@umair-me
umair-me / get_table_details.sql
Created January 19, 2016 16:09
Query to list number of records and table size in each table in a database
SELECT
t.NAME AS TableName,
i.name as indexName,
p.[Rows],
sum(a.total_pages) as TotalPages,
sum(a.used_pages) as UsedPages,
sum(a.data_pages) as DataPages,
(sum(a.total_pages) * 8) / 1024 as TotalSpaceMB,
(sum(a.used_pages) * 8) / 1024 as UsedSpaceMB,
(sum(a.data_pages) * 8) / 1024 as DataSpaceMB
@umair-me
umair-me / datareader_to_string
Created October 14, 2015 09:03
SQL DataReader to CSV string
public static List<string> ToCSV(IDataReader dataReader, bool includeHeaderAsFirstRow, string separator)
{
List<string> csvRows = new List<string>();
StringBuilder sb = null;
if (includeHeaderAsFirstRow)
{
sb = new StringBuilder();
for (int index = 0; index < dataReader.FieldCount; index++)
{