string word = "cab"; string sorted = string.Concat(word.OrderBy(c => c));
Category Archive: Code
Jan 06
How can I get information about digital signatures of all files in the folder?
The following PowerShell code snippet allows you to get information about digital signatures of all files in a specific folder: Get-ChildItem *.* | foreach-object {Get-AuthenticodeSignature $_} All you have to do is start PowerShell, go to the folder you want to check and run the command.
Oct 12
How can I delete records from MS SQL Server database using Python?
The following code will delete all records from table in database on server. import win32com.client connectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=database;Data Source=server;" query = "delete from table;" con = win32com.client.Dispatch(‘ADODB.Connection’) con.Open(connectionString) con.Execute(query) con.Close( ) Note: This code works on Windows only. You will also need to install excellent Python for Windows extensions (pywin32) by …
Sep 28
How can I restart Windows service with Python?
First you need to install excellent Python for Windows extensions (pywin32) by Mark Hammond from http://sourceforge.net/projects/pywin32/. Then you can use the following code (that will restart the Print Spooler service). import win32serviceutil serviceName = "spooler" win32serviceutil.RestartService(serviceName) Note: this code was tested with Python 2.7 and version 216 of the pywin32 extensions.
Feb 03
How can I get application’s directory in a WPF application?
string appPath = AppDomain.CurrentDomain.BaseDirectory;
Jan 26
Cannot convert lambda expression to type ‘string’ because it is not a delegate type
When you get the “Cannot convert lambda expression to type ‘string’ because it is not a delegate type” error in Visual Studio 2010, all you have to do is add using System.Linq; to the top of the source file.
Dec 06
How can I tell if Silverlight application is running out of browser?
Application.Current.IsRunningOutOfBrowser indicates whether application was launched as an out-of-browser application. Application.Current.HasElevatedPermissions indicates if application is running as an out-of-browser application with elevated permissions. Elevated permissions give you direct access to clipboard, user folder and COM enabled applications.
Oct 22
Code Kata
A code kata is an exercise in programming which helps hone your skills through practice and repetition. Here is a list of some of code katas I found: How to Become a Better Programmer Project Euler: Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to …
Nov 06
How can I navigate to a web page in Silverlight?
The following code opens web site in a new window without menu, toolbars and status bar: string url = "http://www.primozic.net/blog/"; System.Windows.Browser.HtmlPage.Window.Navigate( new Uri(url), "_blank", "toolbar=no,location=no,status=no,menubar=no,resizable=yes"); Note: It seams that for some reason Navigate method does not work in Google Chrome. I’ve tried it in version 3.0.195.32.
Oct 21
How can I close browser window from Silverlight?
You can do that by invoking JavaScript code. Calling just window.Close() does not work in Chrome. The following code also bypasses IE prompt for confirmation. System.Windows.Browser.HtmlPage.Window.Eval("window.open(”, ‘_self’, ”);window.close();");