Archive
HowTo: Use WSL2 with Docker Desktop instead of Hyper-V backend
At installation guide of Docker Desktop one reads:
Containers and images created with Docker Desktop are shared between all user accounts on machines where it is installed. This is because all Windows accounts use the same VM to build and run containers. Note that it is not possible to share containers and images between user accounts when using the Docker Desktop WSL 2 backend.
That note on WSL2 is written in a negative tone, but is probably a plus security-wise. Anyway their WSL2 based engine provides better performance that then legacy Hyper-V backend Docker Desktop was only providing in the past, so one should opt for that.
Apart from the instructions in the installation guide mentioned above, a quick way to check if it is set to use the WSL2 based engine is via the context menu from taskbar tray icon of Docker Desktop to go to Settings and in General section check the value of “Use the WSL 2 based engine”.
HowTo: make raw_input & input work the same in both Python 2 and 3
Was just trying to make a Python 2 script work in Python 3 and at first it seemed I just needed a small change to add missing parentheses to the argument of a couple of print statements.
But then another issue came up, it wasn’t understanding the command raw_input(somePrompt) that was occuring at various places in that file to input text from the console.
Various solutions were proposed at
https://stackoverflow.com/questions/954834/how-do-i-use-raw-input-in-python-3/62825723
but I think I came up with a cleaner looking solution that works in both Python2 and Python3, that should allow one to use either raw_input or input in both Python2 and Python3 with the semantics of Python2’s raw_input (aka the semantics of Python3’s input).
# raw_input isn't defined in Python3.x, whereas input wasn't behaving
# like raw_input in Python 2.x. This should make both input and raw_input
# work in Python 2.x/3.x like the raw_input from Python 2.x
try: input = raw_input
except NameError: raw_input = input
In practice this came up from ideas at other answers on that SO thread. It tries to define input as raw_input which should fail in Python3.x since raw_input is undefined. In that case it will catch a NameError exception and do the reverse, aka define raw_input as input. However in Python2 the first command should execute fine, overriding the insecure input of Python2.x to work the same as raw_input (not trying to interpret input strings that is). Actually that is what Python 3.x input does.
Wonder why they didn’t declare it like that in the first place though, breaking compilation of Python2 programs. After all semantically only Python2 programs that were using the old insecure input would have an issue, not those that were using raw_input which is the semantics Python3 promotes with its newer input.
HowTo: Use DISM and SFC tools to check+fix your Windows installation
If you’re having issues with your Windows 7 or newer, you should consider whether its installation has become corrupted (due to malicious software or hard drive errors).
After doing a disk check (say by right clicking the appropriate drive under my computer and selecting Properties, then Tools tab and Error checking) and a complete virus scan (on Win10 you can click the shield icon of Windows defender in the taskbar tray and at scanning options choose to do a full scan – or if you have installed some third-party antivirus double-click its icon in the taskbar tray and when its GUI opens up opt to do a full scan), then try the following steps to repair your Windows installation:
1. Press WIN+R to open Run dialog
2. Type in:
CMD
Hold down CTRL+SHIFT keys and click OK to open the command line window in Administrator mode (do press Yes at the User Account Control prompt)
A (usually) black text-based console window will open up and you’ll be greated with something like:
Microsoft Windows [Version 10.0.18363.720]
(c) 2019 Microsoft Corporation. All rights reserved.
and then a prompt like:
C:\Windows\system32>
3. Type in the following and press the ENTER key:
DISM.exe /Online /Cleanup-image /Scanhealth
and press ENTER to execute the DISM tool with the option to check the windows image health and wait patiently for it to complete
Deployment Image Servicing and Management tool
Version: 10.0.18362.1Image Version: 10.0.18363.720
[==========================100.0%==========================] The component store is repairable.
The operation completed successfully.
4. In case you see a message that the component store is repairable, then when greeted with the C:\Windows\system32> prompt again, type in the following and press ENTER:
DISM.exe /Online /Cleanup-image /RestoreHealth
to repair the Windows image:
Deployment Image Servicing and Management tool
Version: 10.0.18362.1Image Version: 10.0.18363.720
[==========================100.0%==========================] The restore operation completed successfully.
The operation completed successfully.
If RestoreHealth fails and you’re on Windows 10, then you should checkout this article:
https://www.tenforums.com/tutorials/16397-repair-install-windows-10-place-upgrade.html
on how to do an in place upgrade of Windows 10, opting to keep your settings and apps
5. If all goes well you’ll see that the restore operation completed successfully and you’ll be taken again to the command-line prompt C:\Windows\system32>
Now that the windows image is checked and fine, you should check your Windows installation against that image, giving the following command and pressing ENTER:
sfc /scannow
Beginning system scan. This process will take some time.
Beginning verification phase of system scan.
Verification 100% complete.Windows Resource Protection found corrupt files and successfully repaired them.
For online repairs, details are included in the CBS log file located at
windir\Logs\CBS\CBS.log. For example C:\Windows\Logs\CBS\CBS.log. For offline
repairs, details are included in the log file provided by the /OFFLOGFILE flag.
After any automatic repairs you should see the prompt C:\Windows\system32> again. Now repeat the same step till you see no more errors found and repaired.
sfc /scannow
Beginning system scan. This process will take some time.
Beginning verification phase of system scan.
Verification 100% complete.Windows Resource Protection did not find any integrity violations.
When back at the C:\Windows\system32> prompt with no errors found and repaired, just close the console window or type in the following and press ENTER:
exit
Twitter #bot or not? Posing as Automation/AI specialist & Python guru
I just came across this strange thing on twitter:
Received a notification that some “Virginia A. Osborn” liked a tweet of mine that was a) in Greek b) totally of a subset of Greek residents interest, highly unlikely it would have meant anything to a person with a foreign name. Then I saw that twitter account started following me immediately after that action.
It smelled bot to me, so I took a look at that account’s profile. She seems to have joined twitter long ago (back in 2010), so I should have probably checked her very first tweets to see what that account was about (wonder if there is an archive of what the profile details were saying back then in case that was a dormant bot).
It seems that account has quite some followers and several people that post AI-related stuff that I follow, plus it didn’t seem to post unrelated stuff:
However, I decided to look her name up on Google. I didn’t find much. So I used Google Image Search to look up her profile photo and bingo, it came up at a stock photo collection, together with other shots of that model posing on the same business-related stock photo theme: https://www.istockphoto.com/search/stack/694124043?assettype=image
So, is this a personna account of some real person or are bots ruling twitter (wonder what the ratio of real persons to bots is currently) and preparing for a future bot-a-gedon? (similar to infected zombie machines that is – wonder if such accounts are already pushing malware links or something).
Of course there’s always the chance that person did a deal with some photographer to pose for him and then used one of those photos in their profile, but I find it highly unlikely.
Fix: How to remove Trovigo.com, SearchProtect, restore Internet Options
Trovigo.com is an unwanted search engine hijacker that renders Internet Options of Windows / Internet Explorer inaccessible. To restore them on an older Windows XP installation, one way that I’ve found to work is to update Internet Explorer to a newer version, aka IE 8 (say via the embedded Windows Update facility or Microsoft Update website – http://update.microsoft.com)
The software is also probably related to a software (at least on the machine I was fixing) called "Search Protect", that is running a service and two other processes that one launches, that tries to stop you from killing it and from changing search engine option in the web browser. To remove that you can use Process Explorer from http://www.sysinternals.com:
-
Right-click the SearchProtect service and select Suspend (do the same for the two other processes it uses) to freeze it (breaks into the process with the debugger).
-
Right click the service node (that has the other two processes shown as children under it in the process tree) and select "Kill process tree".
-
Go to %ProgramFiles% (usually C:\Program Files) using Windows Explorer address bar (or type this in Start/Run… dialog and press OK) and remove the folder "SearchProtect"
-
Use free software like CCleaner (http://www.piriform.com) free edition (it has a tool to edit startup entries) or the really powerful Autoruns one to remove the now broken (since you deleted the software at step #3 references in various Windows settings that try to launch the SearchProtect software (Autoruns shows in yellow startup references to missing files, can right click and delete those entries).
HowTo: Remove invalid filename characters in .NET
In ClipFlair Studio I use DotNetZip (Ionic.Zip) library for storing components (like the activity and its nested child components) to ZIP archives (.clipflair or .clipflair.zip files). Inside the ZIP archive its child components have their own .clipflair.zip file and so on (so that you could even nest activities at any depth) which construct their filename based on the component’s Title and ID (a GUID)
However, when the component Title used characters like " (double-quote) which are not allowed in filenames, then although Ionic.Zip created the archive with the double-quotes in the nested .clipflair.zip filenames, when trying to load those ZipEntries into a memory stream it failed. Obviously I had to filter those invalid filename characters (I opted to remove them to make those ZipEntry filenames a bit more readable/smaller).
So I added one more extension method for string type at StringExtensions static class (Utils.Silverlight project), based on info gathered from the links from related stackoverflow question. To calculated version of a string s without invalid file name characters, one can do s.ReplaceInvalidFileNameChars() or optionally pass a replacement token parameter (a string) to insert at the position of each char removed.
public static string ReplaceInvalidFileNameChars(this string s,
string replacement = "") { return Regex.Replace(s, "[" + Regex.Escape(new String(System.IO.Path.GetInvalidPathChars())) + "]", replacement, //can even use a replacement string of any length RegexOptions.IgnoreCase); //not using System.IO.Path.InvalidPathChars (deprecated insecure API) }
For more info on Regular Expressions see http://www.regular-expressions.info/ and http://msdn.microsoft.com/en-us/library/hs600312.aspx
BTW, note that to convert the char[] returned by System.IO.Path.GetInvalidPathChars() to string we use new String(System.IO.Path.GetInvalidPathChars()).
It’s unfortunate that one can’t use ToString() method of char[] (using Visual Studio to go to definition of char[].ToString() takes us to Object.ToString() which means the array types don’t overload the virtual ToString() method of Object class to return something useful).
Another thing to note is that we don’t use System.IO.Path.InvalidPathChars field which is deprecated for security reasons, but use System.IO.Path.GetInvalidPathChars() method instead. MSDN explains the security issue, so better avoid that insecure API to be safe:
Do not use InvalidPathChars if you think your code might execute in the same application domain as untrusted code. InvalidPathChars is an array, so its elements can be overwritten. If untrusted code overwrites elements of InvalidPathChars, it might cause your code to malfunction in ways that could be exploited.
IIS FTP login fails after Windows platform update for Server 2008 R2
I had recently enabled FTP access to the ClipFlair Gallery to easy its maintenance during development and after the Windows Server 2008 R2 platform update last night (together with release for Internet Explorer 10), the FTP login stopped working.
To fix it, from a command prompt with administrator rights (Start/Find, type Command and right click the Command Prompt item found to open as administrator), give the command:
netsh advfirewall set global StatefulFtp disable
It’s easy to copy-paste it from here and right-click on the command prompt title bar, then select Edit>Paste (no shortcut key for that unfortunately), then press the ENTER key and it should reply “Ok”.
Had done this before, but seems the platform update re-enabled filtering for Stateful FTP (also note that at http://www.iis.net/learn/publish/using-the-ftp-service/configuring-ftp-firewall-settings-in-iis-7 it seems to erroneously say that you need to use “enble” instead of “disable” when not using SSL).
Gotcha: Image component not loading remote URLs during debugging
At ClipFlair’s Image component I use the following XAML to make it show an image from a URL that its ViewModel holds at a property named “Source”, of type Uri (URI = Uniform or Universal Resource Identifier in W3C parlance, something like a superset of the old classic URLs).
<Image Name="imgContent"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Source="{Binding Source, Mode=OneWay}"
Stretch="{Binding Stretch, Mode=OneWay}"
>
I’ve had issues in the past with that component not loading an image, a tricky issue was when I had used Mode=TwoWay when data-binding to Source property – that was disastrous, since the Source property expects an ImageSource and just “plays it clever” internally, also accepting a conversion from a Uri. So when doing reverse binding too, you’d end up getting a null value at respective the ViewModel property.
So when it recently started not showing the test image (from a remote URL) that I had been using, I started wondering if it was some regression of that older bug, but couldn’t find some change in the respective code, plus in the Visual Studio XAML designer the component would load and display the remote image fine.
It turned out to be an issue with Silverlight’s security policy regarding cross-site access. The Image control is supposed to be able to load images from any remote URL (without the remote web server needing to have a ClientAccessPolicy.xml file for example to allow it, as is the case with the WebClient class), however I had recently found out that if at your Silverlight project you have selected at the “Debug” tab the “Dynamically generate a test page” option, the Image control wouldn’t load remote images.
What I didn’t know was that even the “Out-of-browser application option there won’t let the Image control load remote images if you don’t select the web project that goes with your Silverlight project (supposing you have them in the same Visual Studio solution), but you happen to select your Silverlight project instead from the dropdown list.
I had changed that option without thinking it might cause an issue while doing other changes in the project. That’s why one should try to do a minimal set of related changes only and test again thoroughly each time (if only they had the time available to do it), so that they can spot such issues early and be able to relate newly introduced bugs to the recent small set of changes, helping to track down the exact change that caused the unwanted behaviour.
Can’t step-through Silverlight file dialogs with Visual Studio debugger
While stepping through “ShowDialog()” method of OpenFileDialog with Visual Studio 2010 debugger, at the Silverlight code pictured below (for loading a ClipFlair window’s stored options), I got a “Dialogs must be user-initiated” exception. Same behaviour will be shown with SaveFileDialog too, every time you try to step through the “ShowDialog()” method.
This is because of Silverlight’s security model, which doesn’t allow source code to programmatically show a file dialog when an app is running in its default security sandbox (app is not signed with certificate and user hasn’t given consent for it to run in elevated rights mode), unless that code is called from an event handler that handles some user action on the UI (e.g. some button has been clicked by the user).
Obviously, when stepping through with the debugger it loses the user-initiated-action context somehow and considers the debugger as the initiator of the action, thus not allowing the file dialog to be shown when you try to step-through the “ShowDialog()” method of OpenFileDialog or SaveFileDialog.
The only solution I can suggest is to put a breakpoint right after the “ShowDialog()” returns (e.g. at “using” statement in the code below). If you place a breakpoint at any source code row above or at the “ShowDialog” inside the event handler method (“btnLoad_Click” in the code below) it will fail when the debugger tries to go through the “ShowDialog” method, even if you press “Run” after that breakpoint fires to continue.
HowTo: Check your web browser and plugins for needed updates
Qualys BrowserCheck will perform a security analysis of your browser and its plugins to identify any security issues. You can install it at https://browsercheck.qualys.com/
Another useful quick online tool (needs no installation) for checking that you do have the latest in web browser technology is Browse Happy, at http://www.BrowseHappy.com