One line way to get a random strings in SQL.
SELECT Substring(Replace(CONVERT(varchar(255), NEWID()),'-',''),0,10)
31 Tuesday Jan 2012
One line way to get a random strings in SQL.
SELECT Substring(Replace(CONVERT(varchar(255), NEWID()),'-',''),0,10)
29 Monday Aug 2011
If you ever need to quickly serialize an object into JSON here is a function to do it without any external dependencies. You will need to add the following namespaces to your imports
Imports System.Runtime.Serialization.Json Imports System.IO
Public Shared Function SerializeObjectToJSON(ByVal o As Object) As String
Dim serializer As New DataContractJsonSerializer(o.GetType())
Dim ms As New MemoryStream()
Using ms
serializer.WriteObject(ms, o)
ms.Flush()
Dim bytes As Byte() = ms.GetBuffer()
Dim jsonString As String = Encoding.UTF8.GetString(bytes, 0, bytes.Length).Trim(ControlChars.NullChar)
Return jsonString
End Using
End Function
26 Friday Aug 2011
Today I noticed in the deep bowels of old code that in one of our functions where we create a Captcha image, the code was saving an image to a physical location before applying it to the image ImageUrl property.
The folder where the images were saved was never cleaned up so it ended up with thousands of useless images.
A simple fix to would be to just put base64 representation of the image as the ImageUrl. Like this:
Using ms As New MemoryStream
myCaptcha.CaptchaImage.Save(ms, ImageFormat.Jpeg)
Dim imageBytes As Byte() = ms.ToArray
Dim base64String As String = Convert.ToBase64String(imageBytes)
imgCaptcha.ImageUrl = "data:image/jpg;base64," & base64String
End Using