Tech-Today
C# Converting a date to timestamp and how to create an Md5 function
A always use these 2 methods so I'm gonna paste them here. I don't remember if I change some lines in these code but I'm sure I got them from Microsoft hmmm already forget about it.
DateTime -> TimeStamp
///
/// method for converting a System.DateTime value to a UNIX Timestamp
///
/// date to convert///
private static double ConvertToTimestamp(DateTime value)
{
//create Timespan by subtracting the value provided from
//the Unix Epoch
TimeSpan span = (value - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
//return the total seconds (which is a UNIX timestamp)
return (double)span.TotalSeconds;
}
Md5
// Hash an input string and return the hash as
// a 32 character hexadecimal string.
private static string Md5(string input)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
-
Secure Angular4 With Keycloak Role Or Group
Demo template is available for sale for $50. You can send payment via skype at:
[email protected] This article will be an extension of an existing one: http://czetsuya-tech.blogspot.com/2017/10/how-to-secure-angular-app-using.html. Normally in the...
-
Common Swift Collection Casting Or Type Conversion
Collection of Common Swift Casting or Type Conversion String to Double var a = "1.5" var b = (a as NSString).doubleValue Double to String var a : Double = 1.5 var b = String(format:"%f", a) Double to Int var a : Double =...
-
Create A Custom Json String Deserializer In Java
On normal cases we really have a lot of ways in doing so, we can use jaxb, jackson and more. But in some cases we really need to improvised, for example in the project I'm working right now I have a date string from a .net application in this format:...
-
How To Send And Receive Stomp Message In Jboss 7.2
The following code is an example of how we can send and receive a stomp message with JBoss 7.2. package org.meveo.util; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.util.Properties; import javax.naming.InitialContext;...
-
Moving Data From A Table In One Database Into Another With The Same Table Definition
Objective: Given the same schema of database for example an active and archive, how should we move rows of data from one table in one database into the same table name in another database. Below is a java code snippet/pseudocode that I've created:...
Tech-Today