Draco Rat

Family, Video Games, DnD

Blog Roll

C# Color Slerp

namespace Dracorat { using System; using System.Drawing; public static class MyExtensionMethods { public static Color Slerp(this Color source, Color destination, float amount) { int a, r, g, b = 0; if ((1 >= amount) && (0 <= amount)) { a = (int)Slerp(source.A, destination.A, amount); r = (int)Slerp(source.R, destination.R, amount); g = (int)Slerp(source.G, destination.G, amount); b = (int)Slerp(source.B, destination.B, amount); } else { if (1 >= amount) return source; return destination; } return Color.FromArgb(a, r, g, b); } public static float Slerp(this float source, float destination, float amount) { double radian = amount * Math.PI - (Math.PI * 0.5); double sin = Math.Sin(radian); double sinNormalized = (sin + 1) / 2; double targetValue = ((destination - source) * sinNormalized) + source; return (float)targetValue; } } } Use: this.beginColor.Slerp(this.endColor, percentAsFloat); // Last param in range 0.0f - 1.0f

XML Formatting

Lately, I've been using XMLSpectrum-FX for my xml formatting needs. It works well, but all the default coloring options suck, especially when you're emailing the XML output to someone else.   So, I replaced the (in the color-themes.xml file) solarized-light theme with the following which actually looks good: <c:theme name="solarized-light"> <c:color name="base" value="000000"/> <c:color name="base01" value="0000FF"/> <c:color name="base03" value="FFFFFF"/> <c:color name="base0" value="000000"/> <c:color name="base1" value="0000FF"/> <c:color name="yellow" value="000000"/> <c:color name="orange" value="000000"/> <c:color name="red" value="000000"/> <c:color name="magenta" value="000000"/> <c:color name="violet" value="A000A0"/> <c:color name="blue" value="8000A0"/> <c:color name="cyan" value="0000A0"/> <c:color name="green" value="AA6500"/> </c:theme> The output... <?xml version="1.0" encoding="utf-8"?><soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetBaseStepsForCustomerResponsexmlns="http://loancoach.com/soap/Secure"><GetBaseStepsForCustomerResult><Success>true</Success> ... etc

Format a number as US Currency in Javascript!

Converts 1234.56 -> $1,234.56 without using JQuery. (Not that there's anything wrong with JQuery.) [More]

JQuery Ajax to Web Service

JQuery has the ability to send ajax requests, but it's written primarily to be used with RESTful services. You can also use it to send XML requests to Web services, but it took a bit to figure out. Here's the proper method: var ajaxRequest = $.ajax({ url: "RoutingManagement.asmx/GetTiers", data: ['<?xml version="1.0" encoding="utf-8"?>', '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">', ' <soap:Body>', ' <GetTiers xmlns="http://xmlns.company.corp/InventoryInvestigation/RoutingManagement" />', ' </soap:Body>', '</soap:Envelope>'].join('\n'), dataType: "xml", contentType: "text/xml", type: "post" });

PowerShell autostarting scripts

PowerShell can be set to run scripts at startup. Unfortunately, there are two scripts if you're using ISE, so here's how to save heartache... More...

Simple C# Web Server, Code Example

This uses a WinForm with a textbox called Output. (For status tracking): More...

Downloading Data Revisited

Now, using the National Weather Service... Remember this is a PowerShell script and you will need to change the city data to your local cities... More...

Numeric UpDown on Asp.Net

Here's how to implement a snazzy Numeric UpDown while using Asp.net.  I didn't like the html that the Ajax component added, so I just decided to scrap it and write my own. My labor is your fruitMore...

Regular Expressions to Filter BAD WORDS!

Left to my own devices, I would never have done this, but where I work, they needed a way to filter bad words out of requests. So, as part of doing this, I sat down and looked up bad word lists online and there are many lists, but none use the power of regular expressions to get the job done. So, using those lists, a bit of judgment and some elbow grease (testing) here is a list of regular expressions that seem to be doing a superb job of filtering bad words. Use them at your leisure... More...

Using PowerShell to Download a SOAP Document

It's hard to find code online that can do this, so after hours of poking around, I finally managed to get it done on my own. So, for the Web-i-verse, here is code that will download weather data through a proxy server as SOAP and then record that data in to a local Oracle XE database. Yes, it wasn't easy figuring all this out. You're welcome   $URL = New-Object System.Uri("http://www.webservicex.net/weatherforecast.asmx") $Proxy = New-Object System.Net.WebProxy "192.168.1.80:8080" #If you can't use default credentials, use the following two lines instead #$Credentials = New-Object System.Net.NetworkCredential("User", "Password", "Domain"); #$Proxy.Credentials = $Credentials $Proxy.UseDefaultCredentials = $true #Zip Codes ... #Kingman: 86401 #Lake Havasu City: 86403 #Nogales: 85621 #Tucson: 85701 $ZipList = @("86401", "86403", "85621", "85701") for($J = 0 ; $J -lt $ZipList.Length ; $J++){ $SoapSender = New-Object System.Net.WebClient $SoapSender.Proxy = $Proxy $SoapSender.Headers.Add("Content-Type","text/xml;charset=UTF-8"); $SoapSender.Headers.Add("SOAPAction","""http://www.webservicex.net/GetWeatherByZipCode""") [System.Net.ServicePointManager]::Expect100Continue = $false #The above line stops HTTP 417 Expectation errors since SOAP servers don't usually send 100-Continue messages $SoapMessage = @" "@ + $ZipList[$J] + @" "@ $Result = ([XML]$SoapSender.UploadString($URL, $SoapMessage)) $NsManager = New-Object System.Xml.XmlNamespaceManager($Result.NameTable) $NsManager.AddNamespace("w", "http://www.webservicex.net") $WeatherBase = $Result.SelectSingleNode("//w:GetWeatherByZipCodeResult", $NsManager) $OracleHost = "127.0.0.1" $OraclePort = "1522" $OracleServiceName = "XE" $OracleUser = "User" $OraclePassword = "Password" $OracleConnectionString = @" Provider=msdaora; Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$OracleHost)(PORT=$OraclePort))(CONNECT_DATA=(SERVICE_NAME=$OracleServiceName))); User Id=$OracleUser; Password=$OraclePassword; "@ $DbFactory = [System.Data.Common.DbProviderFactories]::GetFactory("System.Data.OleDb") $DbConnection = $DbFactory.CreateConnection() $DbConnection.ConnectionString = $OracleConnectionString $DbCommand = $DbConnection.CreateCommand() $DbCommand.CommandText = "Select 1 FROM DUAL" $DbConnection.Open() #$WeatherBase.SelectSingleNode("w:PlaceName", $NsManager).InnerText + ", " + $WeatherBase.SelectSingleNode("w:StateCode", $NsManager).InnerText $CityName = $WeatherBase.SelectSingleNode("w:PlaceName", $NsManager).InnerText foreach ($N in $WeatherBase.SelectNodes("w:Details/w:WeatherData", $NsManager)) { $DateText = $N.SelectSingleNode("w:Day", $NsManager).InnerText if($DateText -ne $null){ #get rid of the day off the front before we attempt to parse the string $DT = [DateTime]::Parse($DateText.Substring($DateText.IndexOf(",") + 1)) $MaxTemp = $N.SelectSingleNode("w:MaxTem... [More]

Valid XHTML 1.0 Transitional