Skip to main content

Strip out numeric or non-numeric characters in string with ASP.NET C#

If you’re working with ASP.NET C# and you’re looking for something that could strip out numeric or non-numeric characters from a string, you might find these helper methods useful enough.

I wrote these methods to give an additional answer to this StackOverflow question, mostly because the accepted one didn’t handle null values: the behaviour of each one of them is well-documented within the <summary>  text, hence there’s nothing to explain here.

If you like them, feel free to leave a comment!

 

 

Catchable fatal error: Object of class WP_Error could not be converted to string – How to Fix

On 11 June 2017 this website experienced a serious downtime that was caused by a very odd error occurred within the WordPress database. If you’ve stumbled upon this post, chances are you might be affected by the same issue.

The issue looked like a standard HTTP 500 – Application Error that blocked any non-cached page. As usual, the first thing I did to read the actual error was to enable the WP_DEBUG and WP_DEBUG_LOG switches within the wp-config.php file, which – as you most certainly know – is located inside the WordPress installation root folder:

As we can read in the above comments, the first of these switches shows the error within the HTTP response, while the latter writes it into a dedicated debug.log file.

Anyway, this is the actual error:

Catchable fatal error: Object of class WP_Error could not be converted to string in C:\inetpub\ryadel.com\wp-includes\rewrite.php on line 326

Sadly, the given info were not enough to shred much light. I briefly took a look to the rewrite.php source code, finding the following function (line 326 is the highlighted one):

(more…)

 

Mantis BugTracker – How to change a bug date and time (with all related notes, history and info) with a bunch MySQL scripts

If you found this post you most certainly know Mantis BugTracker, also known as MantisBT, the award-winner open-source bug tracking platform built with PHP and MySQL. If you use it a lot, you likely already know that the software doesn’t allow you to change the date and/or the time of basically anything it tracks, such as: bug entries, notes, comments, status changes. Even if you’re the platform administrator, there’s no chance you can do that relying to the built-in commands.

This behaviour shouldn’t sound surprising at all: the main purpose of issue-tracking software is to track the user activity, including those performed by the system administrators. Altough this is generally a good thing, there are some edge-case scenarios where altering these dates could be really useful: for example, when we need to restore an old backup and fill it with the “missing” tasks lost due to a DB crash.

When such a scenario occurs, this set of queries might come to the rescue:

(more…)

 

Programmatically create a Zip Archive file and send it as ActionResult using native ASP.NET MVC C#

If you’re working with ASP.NET or ASP.NET Core and you need to create a zip file on-the-fly within your controller – for example to allow the user to download multiple files with a single request – you can easily do that using the ZipArchive class, introduced in Framework 4.5.

Here’s a quick code sample using a MemoryStream and a couple of byte arrays representing two files:

(more…)

 

WannaCry: how to check if your system is protected using a PowerShell script

If you’ve stumbled upon this post you are probably well-aware of the Win32/WannaCrypt Ransomware, better known as WannaCry: we already talked about it in this other post, which contains an extensive list of links to download the various patches to shield almost any Windows-based operating system against this dangerous treat.

However, you might also need to find a way to quickly check if your system is effectively protected against WannaCry or not: this could come very handy if you are a System Administrator and you don’t know which server is missing the updates or not. Altough the best suggestion we can give would always be “patch everything”, you can also use this great PowerShell script (which we stole from this great post from SpiceWorks community site – credits to CarlosTech for the great job):

(more…)