Send key-strokes Ctrl+Alt+Del through nested RDP sessions

Tags

, , , ,

Credit belongs to https://superuser.com/a/871037/136936

  • Ctrl+Alt+Del won’t work with nested RDP(remote desktop protocol) sessions
  • Ctrl+Alt+End won’t work with nested RDP sessions
  • The only way to make it work is to run “osk.exe”(On-Screen Keyboard) through admin command line and Hold the Ctrl and Alt key from your current physical keyboard then use mouse to click the Del key from OSK UI keyboard

Since this is the third time I need to search this special treatment, mark it down. 🙂

Actually this is pretty useful if you’d like to reset active directory password inside a VM of VM of VM…

Compare two lists of objects by specific properties

Tags

, ,

Credit goes: http://stackoverflow.com/questions/19790211/comparing-two-lists-according-to-specific-properties

.Net Except with IEqualityComparer

// define the Animal class
public class Animal
{
	public Guid Id { get; set; }
	public string AnimalName { get; set; }
	public bool HasTail { get; set; }
}

And then have the following, expect that these two list should be equal to each other, but actually not

var id = Guid.NewGuid();
var animalList1 = new List<Animal>{new Animal { Id=id, AnimalName="cat", HasTail=true}};
var animalList2 = new List<Animal>{new Animal { Id=id, AnimalName="cat", HasTail=true}};

var isSame = !animalList1.Except(animalList2).Any() // expect to be true, but it's false;

In this case, need to implement it’s own IEqualityComparer

public class AnimalComparer : IEqualityComparer<Animal>
{
    ///
<summary>
    /// Implement the Equals methods
    /// </summary>

    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns></returns>
    public bool Equals(Animal x, Animal y)
    {
        return x.Id.Equals(y.Id) && x.AnimalName.Equals(y.AnimalName) && x.HasTail == y.HasTail;
    }

    ///
<summary>
    /// Implement its own GetHashCode method
    /// </summary>

    /// <param name="x"></param>
    /// <returns></returns>
    public int GetHashCode(Animal x)
    {
        unchecked
        {
            int hash = 17;
            hash = hash * 23 + x.Id.GetHashCode();
            hash = hash * 23 + x.AnimalName.GetHashCode();
            hash = hash * 23 + x.HasTail.GetHashCode();
            return hash;
        }
    }
}

And now if compare these two lists by using its own comparer, it will succeed

var isSame = !animalList1.Except(animalList2, new AnimalComparer()).Any(); // Now will be true

Fastest way to insert 1 million rows

Tags

,

Here is the fastest way to insert 1 million rows to a table in SQL Server

Credit goes this post: Generate and Insert 1 million rows into simple table

WITH
L0 AS (SELECT c FROM (SELECT 1 UNION ALL SELECT 1) AS D(c)), -- 2^1
L1 AS (SELECT 1 AS c FROM L0 AS A CROSS JOIN L0 AS B), -- 2^2
L2 AS (SELECT 1 AS c FROM L1 AS A CROSS JOIN L1 AS B), -- 2^4
L3 AS (SELECT 1 AS c FROM L2 AS A CROSS JOIN L2 AS B), -- 2^8
L4 AS (SELECT 1 AS c FROM L3 AS A CROSS JOIN L3 AS B), -- 2^16
L5 AS (SELECT 1 AS c FROM L4 AS A CROSS JOIN L4 AS B), -- 2^32
Nums AS (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS k FROM L5)

insert into yourtable
select k as IdColumn, 'whatever' as otherColumnName
from nums
where k <= 1000000

Get table or view name by search column name keyword

Tags

Here is the script:

SELECT c.object_id,
 CASE
     WHEN OBJECTPROPERTY(c.object_id, 'isTable') = 1
     THEN 'Yes' ELSE 'No' END AS IsTable,
 CASE
     WHEN OBJECTPROPERTY(c.object_id, 'isView')  = 1
     THEN 'Yes' ELSE 'No' END AS IsView,
 OBJECT_SCHEMA_NAME(c.object_id) AS SchemaName,
 OBJECT_NAME(c.object_id) AS TableName,
 c.name AS ColumnName
 FROM sys.columns c
 WHERE c.name LIKE '%MyColumnName%'

Microsoft SQL Server – Search specified column or table in all database at a DB Server

Tags

,

In a development environment normally there are multiple databases installed at one DB Server, and there is a system store procedure called: “sp_msforeachdb” can help us to search a specified column or table easily in these different databases(or other tasks need to be done in different DBs), and here are the sample script:

Search a specified column name in all database at a DB Server

-- Search a specified column name in all database at a DB Server
sp_msforeachdb
'SELECT
''[''+ "?" +''].[''+SCHEMA_NAME(schema_id)+''].[''+t.name+'']''
as "Full table name",
"?" AS DBName,
SCHEMA_NAME(schema_id) AS Schema_Name,
t.name AS Table_Name,
col.name AS Column_Name
FROM [?].sys.tables AS t
INNER JOIN [?].sys.columns col ON t.OBJECT_ID = col.OBJECT_ID
WHERE col.name like ''%ColumnName_search_keyword%''
ORDER BY schema_name, table_name; '

Search a specified table name in all databases at a DB Server

-- Search a specified table name in all databases at a DB Server
sp_msforeachdb
'SELECT
''[''+ "?" +''].[''+SCHEMA_NAME(schema_id)+''].[''+t.name+'']''
as "Full Table Name",
"?" AS DBName,
SCHEMA_NAME(schema_id) AS Schema_Name,
t.name AS Table_Name
FROM [?].sys.tables AS t
WHERE t.name like ''%tablename_search_keyword%'';'

GitHub Tips

Tags

, ,

  1. Config GitHub with Putty/Pageant
    1. Install Putty from here, run PuTTY.exe and create a new SSH session to “github.com’ and save it
    2. run putty.exe -> In the “host name” field type . In the “Saved Sessions” field, give it the name and click “Save” -> Click on the “Open” button and accept the server cert.(Very important step to accept the server cert)
    3. Run PUTTYGEN.EXE generate a pair of public/priviate key pair, put your email to key comment field, copy the public key content to a text file(like ‘yourpublickey.txt’), save the private key to a text file(like ‘yourprivatekey.ppk’) at the same folder(like: c:\ssh)
    4. Click Conversation menu and choose Export OpenSSH key as “%userprofile%\.ssh\id_rsa“, save the public key as “%userprofile%\.ssh\id_rsa.pub
    5. Create a shortcut of Pageant.exe with parameter like this: ‘C:\Putty\PAGEANT.EXE c:\ssh\yourprivatekey.ppk’
    6. Run the Pageant.exe shortcut, load the ‘yourprivatekey.ppk’ file, the pageant should be run successfully with a system tray icon
    7. Install git from here, in my case, with the following configuration choices:
      • Select components window: choose all defaults
      • Adjusting your PATH environment window: Run Git and included Unix tools from the Windows Command Prompt(which by using all cygwin tools)
      • Choosing the SSH executable window: Use (tortoise) Plink and indicate the PLINK.EXE path
      • Configuring the line ending conversions window: Checkout as-is, commit as-is
    8. Sign up a new account at github.com or sign in with your existing account, add ssh-key by using the content of ‘yourpublickey.txt’
    9. Now open ‘git bash'(Which installed at step E), and you should be able to run all git commands now
  2. GitHub Tips
    1. Review last commit in current branch
      1. git show -1
      2. git log -1

Very useful windows shortcuts which can run from command line or explorer

Tags

Run commands

Calc – Calculator
Cfgwiz32 – ISDN Configuration Wizard
Charmap – Character Map
Chkdisk – Repair damaged files
Cleanmgr – Cleans up hard drives
Clipbrd – Windows Clipboard viewer
Cmd – Opens a new Command Window (cmd.exe)
Control – Displays Control Panel
Dcomcnfg – DCOM user security
Debug – Assembly language programming tool
Defrag – Defragmentation tool
Drwatson – Records programs crash & snapshots
Dxdiag – DirectX Diagnostic Utility
Explorer – Windows Explorer
Fontview – Graphical font viewer
Ftp – ftp.exe program
Hostname – Returns Computer’s name
Ipconfig – Displays IP configuration for all network adapters
Jview – Microsoft Command-line Loader for Java classes
MMC – Microsoft Management Console
Msconfig – Configuration to edit startup files
Msinfo32 – Microsoft System Information Utility
Nbtstat – Displays stats and current connections using NetBios over TCP/IP
Netstat – Displays all active network connections
Nslookup – Returns your local DNS server
Odbcad32 – ODBC Data Source Administrator
Ping – Sends data to a specified host/IP
Regedit – registry Editor
Regsvr32 – register/de-register DLL/OCX/ActiveX
Regwiz – Reistration wizard
Sfc /scannow – Sytem File Checker
Sndrec32 – Sound Recorder
Sndvol32 – Volume control for soundcard
Sysedit – Edit system startup files (config.sys, autoexec.bat, win.ini, etc.)
Systeminfo – display various system information in text console
Taskmgr – Task manager
Telnet – Telnet program
Taskkill – kill processes using command line interface
Tskill – reduced version of Taskkill from Windows XP Home
Tracert – Traces and displays all paths required to reach an internet host
Winchat – simple chat program for Windows networks
Winipcfg – Displays IP configuration

Management Consoles

certmgr.msc – Certificate Manager
ciadv.msc – Indexing Service
compmgmt.msc – Computer management
devmgmt.msc – Device Manager
dfrg.msc – Defragment
diskmgmt.msc – Disk Management
fsmgmt.msc – Folder Sharing Management
eventvwr.msc – Event Viewer
gpedit.msc – Group Policy -XP Pro only
iis.msc – Internet Information Services
lusrmgr.msc – Local Users and Groups
mscorcfg.msc – Net configurations
ntmsmgr.msc – Removable Storage
perfmon.msc – Performance Manager
secpol.msc – Local Security Policy
services.msc – System Services
wmimgmt.msc – Windows Management

Control Panel Shortcuts

access.cpl – Accessibility Options
hdwwiz.cpl – Add New Hardware Wizard
appwiz.cpl – dd/Remove Programs
timedate.cpl – Date and Time Properties
desk.cpl – Display Properties
inetcpl.cpl – Internet Properties
joy.cpl – Joystick Properties
main.cpl keboard – Keyboard Properties
main.cpl – Mouse Properties
ncpa.cpl – Network Connections
ncpl.cpl – Network Properties
telephon.cpl – Phone and Modem options
powercfg.cpl – Power Management
intl.cpl – Regional settings
mmsys.cpl sounds – Sound Properties
mmsys.cpl – Sounds and Audio Device Properties
sysdm.cpl – System Properties
nusrmgr.cpl – User settings
firewall.cpl – Firewall Settings (sp2)
wscui.cpl – Security Center (sp2)

Windows Environment Commands

%ALLUSERSPROFILE% – Open the All User’s Profile
%HomeDrive% – Opens your home drive e.g. C:\
%UserProfile% – Opens you User’s Profile
%temp% Opens – temporary file Folder
%systemroot% – Opens Windows folder

Wupdmgr – Takes you to Microsoft Windows Update

If Microsoft Office installed:

winword – Microsoft Word
excel – Microsoft Excel
powerpnt – Microsoft PowerPoint
msaccess – Microsoft Access
outlook – Microsoft Outlook
ois – Microsoft Picture Manager

Credit belongs to: this post from superuser

Microsoft Pairwise Testing Tool: PICT

Tags

, , ,

When a massive conditions combined together and impossible to test all combinations, there is a testing method called pairwise testing(also known as All-pairs testing) we can use to test these possible combinations in a certain way.

In order to test all-paired combinations, we need to have a tool to generate the test data, by far my favorite tool is Microsoft PICT command line tool, and here is an article introduced the concept very clearly

This is a light-weight all pairs generating tool and it’s pretty easy to use, only for windows platform though.