It doesn’t seem possible but I have not blogged for 7 months. That needs to change…
Category: Uncategorized
Time Zone C# Collection…
Here is a simple C# one liner to get a collection of time zones:
System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
Visual Studio 2013 Error message 401.2.: Unauthorized: Logon failed due to server configuration
Installed Visual Studio 2013 with great anticipation for an improved IDE. However, was immediately disappointed with a 401.2 error when running the debugger for the first time. This fix was trivial, the experience however was so Microsoft-ish. Like why can’t Microsoft products just work the first time? Why must I have to always solve a problem to get things going?
A google search pointed me to my problem source. Actually it was the same problem some encountered with Visual Studio 2012., i.e.
Server Error in '/' Application.
Access is denied.
Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.
Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
Resolved by:
1. Pressing F4 which brings up the Properties pane in the bottom right hand corner:
2, Choosing the application in the Solution Explorer pane. This will then display all the properties relevant to the project in the Properties pane.
3. Change the "Windows Authentication" property to Enabled.
Solution courtesy:
Display a web application version on an ASP.NET master page…
To display a web application version on an ASP.NET master page:
1. Add an AssemblyInfo.cs file to the App_Code directory of a web application.
using System.Reflection;
[assembly: AssemblyVersion("2.1.1.2")]
2. Then in the Default.master.cs file add the following to the Page_Load event.
Assembly assembly = Assembly.Load("App_Code");
StringBuilder sb = new StringBuilder("Version ");
sb.Append(assembly.GetName().Version.ToString());
version.Text = sb.ToString();
3. In the Default.master file add the following where you want the version to display.
<asp:Label ID="version" CssClass="Version" runat="server" />
4. Finally add the following to the css style sheet.
.Version
{
font-size:.4em;
font-style:italic;
margin-left:.2em;
}
Access session from class library…
Here is a little method I used to access the session from a class library:
public static string GetSessionValue(string sessionKey)
{
string keyValue = "";
HttpContext httpsContext = HttpContext.Current;
if (httpsContext.ApplicationInstance.Session.Count > 0)
keyValue =
httpsContext.ApplicationInstance.Session[sessionKey].ToString();
return keyValue;
}
Disable Chromebook trackpad…
It would be nice if you could disable the Chromebook trackpad with a simple function key click. But alas its just not that simple. But there is way, click
Ctrl+Alt+T
which will bring up crosh in a browser window. At the crosh prompt type
tpcontrol status
This will display a list of settings. I'm using a Samsung Cromebook and the setting I need to change is "Device Enabled (111): 1". Next type
tpcontrol set 111 0
then type exit and close the browser widow. You should now find the trackpad not longer functions. To restore functionality just simply repeat the steps above and type tpcontrol set 111 1.
Elapsed minutes between datetime’s…
Here is a simple little method to calculate the number of minutes between two datetimes. Make sure to use TotaMinutes not Minutes in your return value.
public static double GetMinuetsSpan(DateTime beginDate, DateTime endDate)
{
TimeSpan DeltaMinutes = TimeSpan.Zero;
TimeSpan BeginDate = new TimeSpan(beginDate.Ticks);
TimeSpan EndDate = new TimeSpan(endDate.Ticks);
DeltaMinutes = BeginDate - EndDate;
return DeltaMinutes.TotalMinutes;
}
jQuery datepicker format date…
Here is how to format a JQuery datepicker id ASP.NET .aspx file:
$(document).ready(function () {
$(function () {
var pickerOpts = { dateFormat: “d-M-yy”};
$(“#”).datepicker(pickerOpts);
});
});
Simple unless it’s you first time. Here is a link to a great reference on the subject.
Display fractional values…
Found a nice class written by "anubisascends" on the MSDN site to convert decimal values to their fractional string representations. This really simplified my effort to desplay fractions… the only change I made was to return a zero when the input is a zero.
public static class FractionConverter
{
public static string Convert(decimal value)
{
if (value == 0) return "0";
// get the whole value of the fraction
decimal mWhole = Math.Truncate(value);
// get the fractional value
decimal mFraction = value - mWhole;
// initialize a numerator and denomintar
uint mNumerator = 0;
uint mDenomenator = 1;
// ensure that there is actual a fraction
if (mFraction > 0m)
{
// convert the value to a string so that you can count the number of decimal places there are
string strFraction = mFraction.ToString().Remove(0, 2);
// store teh number of decimal places
uint intFractLength = (uint)strFraction.Length;
// set the numerator to have the proper amount of zeros
mNumerator = (uint)Math.Pow(10, intFractLength);
// parse the fraction value to an integer that equals [fraction value] * 10^[number of decimal places]
uint.TryParse(strFraction, out mDenomenator);
// get the greatest common divisor for both numbers
uint gcd = GreatestCommonDivisor(mDenomenator, mNumerator);
// divide the numerator and the denominator by the gratest common divisor
mNumerator = mNumerator / gcd;
mDenomenator = mDenomenator / gcd;
}
// create a string builder
StringBuilder mBuilder = new StringBuilder();
// add the whole number if it's greater than 0
if (mWhole > 0m)
{
mBuilder.Append(mWhole);
}
// add the fraction if it's greater than 0m
if (mFraction > 0m)
{
if (mBuilder.Length > 0)
{
mBuilder.Append(" ");
}
mBuilder.Append(mDenomenator);
mBuilder.Append("/");
mBuilder.Append(mNumerator);
}
return mBuilder.ToString();
}
public static decimal Convert(string value)
{
return 0m;
}
private static uint GreatestCommonDivisor(uint valA, uint valB)
{
// return 0 if both values are 0 (no GSD)
if (valA == 0 &&
valB == 0)
{
return 0;
}
// return value b if only a == 0
else if (valA == 0 &&
valB != 0)
{
return valB;
}
// return value a if only b == 0
else if (valA != 0 && valB == 0)
{
return valA;
}
// actually find the GSD
else
{
uint first = valA;
uint second = valB;
while (first != second)
{
if (first > second)
{
first = first - second;
}
else
{
second = second - first;
}
}
return first;
}
}
}
Java ArrayList…
The following code demonstrates how to use a Java ArrayList<T>… its a very simple demo.
import java.util.ArrayList;
public class MyMolecules {
public static void main(String[] args) {
ArrayList<Molecule> myMolecules = new ArrayList<Molecule>();
Molecule m1 = new Molecule(“First”);
Molecule m2 = new Molecule(“Second”);
Molecule m3 = new Molecule(“Third”);
Molecule m4 = new Molecule(“Fourth”);
myMolecules.add(m1);
myMolecules.add(m2);
myMolecules.add(m3);
myMolecules.add(m4);
for (Molecule item : myMolecules) {
System.out.println(item.getName());
}
}
};
public class Molecule {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Molecule(String name){
this.name = name;
}
}