Warning: include(wp-includes/class-wp-query-update.php) [function.include]: failed to open stream: No such file or directory in /home/content/05/11443405/html/wp-settings.php on line 472

Warning: include() [function.include]: Failed opening 'wp-includes/class-wp-query-update.php' for inclusion (include_path='.:/usr/local/php5_3/lib/php') in /home/content/05/11443405/html/wp-settings.php on line 472

Warning: Cannot modify header information - headers already sent by (output started at /home/content/05/11443405/html/wp-settings.php:472) in /home/content/05/11443405/html/wp-content/themes/eclipsepro2/cyberchimps/functions.php on line 1457

Warning: Cannot modify header information - headers already sent by (output started at /home/content/05/11443405/html/wp-settings.php:472) in /home/content/05/11443405/html/wp-includes/feed-rss2.php on line 8
Zombies With Coffee, LLC http://zombieswithcoffee.com Late night programming fueled by the power of caffeine. Mon, 31 Jul 2017 15:01:20 +0000 en-US hourly 1 https://wordpress.org/?v=4.7.11 55598848 Determining Holidays in C# http://zombieswithcoffee.com/2017/05/determining-holidays-c/ http://zombieswithcoffee.com/2017/05/determining-holidays-c/#respond Sat, 27 May 2017 15:43:32 +0000 http://zombieswithcoffee.com/?p=585 I was needing to check for Holidays in an Appointment calendar and found some decent code that needed a bit of refactoring. http://geekswithblogs.net/wpeck/archive/2011/12/27/us-holiday-list-in-c.aspx

The post Determining Holidays in C# appeared first on Zombies With Coffee, LLC.

]]>
I was needing to check for Holidays in an Appointment calendar and found some decent code that needed a bit of refactoring.

http://geekswithblogs.net/wpeck/archive/2011/12/27/us-holiday-list-in-c.aspx

static HashSet<DateTime> GetHolidays(int year) {

    var holidays = new HashSet<DateTime>{
        NewYears(year),
        MemorialDay(year),
        IndependenceDay(year),
        LaborDay(year),
        Thanksgiving(year),
        Christmas(year)
    };

    var next = NextNewYears(year);

    if(next != null)
        holidays.Add(next.Value);

    return holidays;
}

static DateTime NewYears(int year){
    return AdjustForWeekendHoliday(new DateTime(year, 1, 1));
}

static DateTime IndependenceDay(int year){
    return AdjustForWeekendHoliday(new DateTime(year, 7, 4));
}

/// 
<summary>
/// Memorial Day is the last Monday in May 
/// </summary>

/// <param name="year"></param>
/// <returns></returns>

static DateTime MemorialDay(int year){

    var day = new DateTime(year, 5, 31);

    while (day.DayOfWeek != DayOfWeek.Monday) {
        day = day.AddDays(-1);
    }

    return day;
}

/// 
<summary>
/// Labor Day is the first Monday in September 
/// </summary>

/// <param name="year"></param>
/// <returns></returns>

static DateTime LaborDay(int year)
{
    var day = new DateTime(year, 9, 1);

    while (day.DayOfWeek != DayOfWeek.Monday) {
        day = day.AddDays(1);
    }

    return day;
}

/// 
<summary>
/// Thanksgiving Day is the fourth Thursday in November 
/// </summary>

/// <param name="year"></param>
/// <returns></returns>
        
static DateTime Thanksgiving(int year)
{
    var thanksgiving = (from date in Enumerable.Range(1, 30)
        where new DateTime(year, 11, date).DayOfWeek == DayOfWeek.Thursday
        select date).ElementAt(3);

    var day = new DateTime(year, 11, thanksgiving);

    return day;
}

static DateTime Christmas(int year){
    return AdjustForWeekendHoliday(new DateTime(year, 12, 25));
}

/// 
<summary>
/// If next year's new years is adjusted for this year, then count it
/// </summary>

/// <param name="year"></param>
/// <returns></returns>

static DateTime? NextNewYears(int year){
    var day = AdjustForWeekendHoliday(new DateTime(year + 1, 1, 1));

    if (day.Year == year)
        return day;

    return null;
}

/// 
<summary>
/// If the holiday falls on a Saturday, then make it Friday.
/// If the holiday falls on a Sunday, then make it Monday.
/// </summary>

/// <param name="holiday"></param>
/// <returns></returns>

public static DateTime AdjustForWeekendHoliday(DateTime holiday) {
    if (holiday.DayOfWeek == DayOfWeek.Saturday) {
        return holiday.AddDays(-1);
    }

    if (holiday.DayOfWeek == DayOfWeek.Sunday) {
        return holiday.AddDays(1);
    }

    return holiday;
}

The post Determining Holidays in C# appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2017/05/determining-holidays-c/feed/ 0 585
Password Expiration for MVC 5 http://zombieswithcoffee.com/2016/11/password-expiration-mvc-5/ http://zombieswithcoffee.com/2016/11/password-expiration-mvc-5/#respond Wed, 16 Nov 2016 13:57:47 +0000 http://zombieswithcoffee.com/?p=580 I needed a way to expire passwords in MVC 5.  Unfortunately, most of the ways that I found were no longer relevant, so I cobbled together this [PasswordAuthorize] attribute to use instead of [Authorize]. using Microsoft.AspNet.Identity.Owin; using System; using System.Web; using System.Web.Mvc; using System.Web.Routing; using Microsoft.AspNet.Identity; namespace Infrastructure { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class PasswordAuthorizeAttribute : […]

The post Password Expiration for MVC 5 appeared first on Zombies With Coffee, LLC.

]]>

I needed a way to expire passwords in MVC 5.  Unfortunately, most of the ways that I found were no longer relevant, so I cobbled together this [PasswordAuthorize] attribute to use instead of [Authorize].

using Microsoft.AspNet.Identity.Owin;
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.AspNet.Identity;

namespace Infrastructure {

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class PasswordAuthorizeAttribute : AuthorizeAttribute {

public PasswordAuthorizeAttribute(string maxPasswordAgeInDay = “90”) {
_maxPasswordAgeInDay = Convert.ToInt32(maxPasswordAgeInDay);
}

readonly int _maxPasswordAgeInDay;

protected override bool AuthorizeCore(HttpContextBase httpContext) {
base.AuthorizeCore(httpContext);

// Generally authenticated to the site
if (!httpContext.User.Identity.IsAuthenticated)
return false;

var userManager = httpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();

var user = userManager.FindById(httpContext.User.Identity.GetUserId());

var timeSpan = DateTime.Today – user.LastPasswordChangedDate;

return timeSpan?.TotalDays < _maxPasswordAgeInDay;
}

protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) {
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary{
{ “action”, “ChangePassword” },
{ “controller”, “Manage” }});
}
}
}

The post Password Expiration for MVC 5 appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2016/11/password-expiration-mvc-5/feed/ 0 580
WPF/XAML: Override DPI in an image http://zombieswithcoffee.com/2016/04/wpfxaml-override-dpi-in-an-image/ http://zombieswithcoffee.com/2016/04/wpfxaml-override-dpi-in-an-image/#respond Tue, 12 Apr 2016 13:06:01 +0000 http://zombieswithcoffee.com/?p=554 When displaying bitmap images in WPF, the system wants to display all images in 96 dpi.  WPF is one of the few environments where the file’s DPI is used in calculating the display DPI.  The images that I was working with had 500 dpi and the images were displaying blurry since they were being downsized […]

The post WPF/XAML: Override DPI in an image appeared first on Zombies With Coffee, LLC.

]]>
When displaying bitmap images in WPF, the system wants to display all images in 96 dpi.  WPF is one of the few environments where the file’s DPI is used in calculating the display DPI.  The images that I was working with had 500 dpi and the images were displaying blurry since they were being downsized to 72.

I haven’t found a way to override the output resolution of an image, so instead, I hack the resolution of the image when it is being read.  Bytes 38/39 is the Horizontal DPI and 42/43 is the Vertical DPI.

To set it to 72 DPI, we must first realize that the resolution is in meters.   Google’s online conversion app says that 3780 inches = 96 meters.  So we set our resolution to 0x0EC4!

    var bytes = File.ReadAllBytes(fileName);

    bytes[38] = 0xc4;  // HLL to 3780 (96 dpi)
    bytes[39] = 0x0e;
    bytes[42] = 0xc4;  // VLL to 3780 (96 dpi)
    bytes[43] = 0x0e;

    var bitmapImage = new BitmapImage();
    bitmapImage.BeginInit();
    bitmapImage.CacheOption = BitmapCacheOption.Default;
    bitmapImage.StreamSource = new MemoryStream(bytes);
    bitmapImage.EndInit();

The post WPF/XAML: Override DPI in an image appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2016/04/wpfxaml-override-dpi-in-an-image/feed/ 0 554
Visual Studio not showing Git changes http://zombieswithcoffee.com/2016/03/visual-studio-not-showing-git-changes/ http://zombieswithcoffee.com/2016/03/visual-studio-not-showing-git-changes/#respond Fri, 18 Mar 2016 14:55:22 +0000 http://zombieswithcoffee.com/?p=551 I have some assembly code shared on multiple projects.  As I switch between these projects, sometimes the shared assembly encounters a read permission and Git forgets what files are changed. An easy fix for this is to run this in the command prompt in the assemblies root directory to refresh all of the changes. git […]

The post Visual Studio not showing Git changes appeared first on Zombies With Coffee, LLC.

]]>
I have some assembly code shared on multiple projects.  As I switch between these projects, sometimes the shared assembly encounters a read permission and Git forgets what files are changed.

An easy fix for this is to run this in the command prompt in the assemblies root directory to refresh all of the changes.

git add -u 

The post Visual Studio not showing Git changes appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2016/03/visual-studio-not-showing-git-changes/feed/ 0 551
Importing XML into SQL with Photographs http://zombieswithcoffee.com/2016/03/importing-xml-into-sql-with-photographs/ http://zombieswithcoffee.com/2016/03/importing-xml-into-sql-with-photographs/#respond Fri, 04 Mar 2016 18:46:08 +0000 http://zombieswithcoffee.com/?p=545 I had a task to import some XML files that included a Base64 encoded photograph into SQL. The data was simple enough, it was just a list of names and photographs. <?xml version="1.0" standalone="yes"?> <dsExport xmlns=http://www.tempuri.org/dsXMLExport.xsd> <DemographicData> <FirstName>Jane</FirstName> <LastName>Doe</LastName> <Photograph>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQg...... </Photograph> ... <DemographicData> </dsExport> The problem occurred when I tried any of the samples with […]

The post Importing XML into SQL with Photographs appeared first on Zombies With Coffee, LLC.

]]>

I had a task to import some XML files that included a Base64 encoded photograph into SQL.

The data was simple enough, it was just a list of names and photographs.
<?xml version="1.0" standalone="yes"?>
<dsExport xmlns=http://www.tempuri.org/dsXMLExport.xsd>
    <DemographicData>
       <FirstName>Jane</FirstName>
       <LastName>Doe</LastName>
       <Photograph>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQg...... </Photograph>
    ...
    <DemographicData>
</dsExport>
The problem occurred when I tried any of the samples with the xmlns still in the xml data. Having a namespace here is causing the rest of the import to fail.
The third parameter to the command sp_xml_preparedocument allows for a namespace, the trick is to pick your own namespace and then use it inside of the import command.

The first step was to import the XML in it’s entirety into SQL.
USE MyDatabase
GO

DROP TABLE XMLwithOpenXML
GO

CREATE TABLE XMLwithOpenXML(
   Id INT IDENTITY PRIMARY KEY,
   XMLData XML,
   LoadedDateTime DATETIME)

 INSERT INTO XMLwithOpenXML(XMLData, LoadedDateTime)
 SELECT CONVERT(XML, BulkColumn) AS BulkColumn, GETDATE()
 FROM OPENROWSET(BULK 'D:\Data.xml', SINGLE_BLOB) AS x;
 This takes the XML file and imports it into SQL as a XML database table.  Doing this step separately from the rest of the steps will allow you to rerun the rest of the code without the time overhead.  Also, doing this step here reduces the import time considerably.

The following code takes the XML database able and imports it into your Demographics table.  The script only imports First, Last, and Photo.  Adding the additional fields should be easy enough.

USE MyDatabase
GO

DECLARE @XmlDocument AS XML
DECLARE @XmlDocumentHandle AS INT
DECLARE @SQL NVARCHAR (MAX)
SELECT @XmlDocument = XMLData FROM XMLwithOpenXML
EXEC sp_xml_preparedocument @XmlDocumentHandle OUTPUT, @XmlDocument, '<ns xmlns:x="http://www.tempuri.org/dsXMLExport.xsd"/>'
INSERT INTO Demographics(First_Name, Last_Name, Photo)
SELECT FirstName, LastName, Photograph.value('.', 'varbinary(max)')
   FROM OPENXML(@XmlDocumentHandle, '/x:dsXMLExport/x:VMSData', 2)
   WITH(
      LastName [nvarchar](255) 'x:FirstName',
      FirstName [nvarchar](255) 'x:LastName',
      Photograph xml
   ) as T

EXEC sp_xml_removedocument @XmlDocumentHandle
GO

The ‘2’ in the OpenXML statement is to allow for the fields to be elements instead of attributes.


With that, I was able to import my records into my database and was able to view the photographs.
Good luck!

The post Importing XML into SQL with Photographs appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2016/03/importing-xml-into-sql-with-photographs/feed/ 0 545
Follow-up to the iOS Universal Asset http://zombieswithcoffee.com/2015/05/follow-up-to-the-universal-asset-post/ http://zombieswithcoffee.com/2015/05/follow-up-to-the-universal-asset-post/#respond Fri, 08 May 2015 18:26:00 +0000 http://zombieswithcoffee.com/?p=540 After I discovered that the only device that uses the 1x Universal image asset was the iPad 2, I went back and did a little bit more experimentation.  If the 1x image is missing, then the iPad 2 will use the 2x image, scaled down properly for the device.  Since it is a easy 50% […]

The post Follow-up to the iOS Universal Asset appeared first on Zombies With Coffee, LLC.

]]>
After I discovered that the only device that uses the 1x Universal image asset was the iPad 2, I went back and did a little bit more experimentation.  If the 1x image is missing, then the iPad 2 will use the 2x image, scaled down properly for the device.  Since it is a easy 50% reduction in the image size, there should be no degradation of the image quality.

The iPhone 6 also adjusted correctly.  If the 3x image was missing, it upscaled the 2x image to fit in our screen size properly.  Although functional, upsizing the image will cause a bit of blur to occur, so I’ll continue to support adding the 3x images.

So the only assets that need to be used in a Swift SpriteKit application are Universal images 2x & 3x.  This let me reduce the overall file size significantly and made my job a whole lot easier.

The post Follow-up to the iOS Universal Asset appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2015/05/follow-up-to-the-universal-asset-post/feed/ 0 540
Universal SpriteKit resource image asset files http://zombieswithcoffee.com/2015/05/universal-spritekit-resource-image-asset-files/ http://zombieswithcoffee.com/2015/05/universal-spritekit-resource-image-asset-files/#respond Thu, 07 May 2015 16:58:28 +0000 http://zombieswithcoffee.com/?p=534 I’ve been working on SpriteKit in XCode and have finally determined the best way to use the Universal asset files on each device. In the fantastic game tutorials from Ray Wenderlich’s site recommends 2048 x 1536, with all background images set to the same size.  But I wanted to make sure to optimize each of the […]

The post Universal SpriteKit resource image asset files appeared first on Zombies With Coffee, LLC.

]]>
I’ve been working on SpriteKit in XCode and have finally determined the best way to use the Universal asset files on each device.

In the fantastic game tutorials from Ray Wenderlich’s site recommends 2048 x 1536, with all background images set to the same size.  But I wanted to make sure to optimize each of the images with the new Universal asset size collection.

This new asset size allows for 1x – 3x images and are the type that the default app uses when creating a Swift SpriteKit game.

For the asset sizes for your background images (in landscape mode)

  • 1x: 1024 x 768
  • 2x: 2048 x 1536
  • 3x: 3072 x 2304

Most of the different platforms will use the 2x resolution.  But the iPad 2 uses the 1x, and the iPhone 6 uses the 3x.

  • iPhone 4: 2x
  • iPhone 5: 2x
  • iPhone 5s: 2x
  • iPhone 6: 2x
  • iPhone 6s: 3x
  • iPad 2: 1x
  • iPad Air: 2x
  • iPad Retina: 2x

In my GameViewController, I hard code my GameScene to 1024×768.

   class GameViewController : UIViewController{
      override func viewDidLoad(){
         super.viewDidLoad()

         let skView = self.view as! SKView

         skView.showsFPS = true
         skView.showsNodeCount = true
         skView.ignoresSiblingOrder = true

         let scene = GameScene(size: CGSize(width: 1024, height: 768))
         scene.scaleMode = .AspectFill

         skView.presentScene(scene)
      }

Then in the Game Scene, to present your background image

   class GameScene : SKScene{

      let background : SKSpriteNode = SKSpriteNode(imageNamed: "background")

      override func didMoveToView(view: SKView){
         background.position = CGPoint(x: size.width / 2, y: size.height / 2)
         addChild(background)
      }
   }

The post Universal SpriteKit resource image asset files appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2015/05/universal-spritekit-resource-image-asset-files/feed/ 0 534
How to save a BitmapSource in WPF http://zombieswithcoffee.com/2014/07/save-bitmapsource-wpf/ http://zombieswithcoffee.com/2014/07/save-bitmapsource-wpf/#respond Tue, 15 Jul 2014 15:30:31 +0000 http://zombieswithcoffee.com/?p=527 A quick and dirty snippet so I don’t have to constantly look this up!

The post How to save a BitmapSource in WPF appeared first on Zombies With Coffee, LLC.

]]>
A quick and dirty snippet so I don’t have to constantly look this up!

  BitmapSource imageSource = ...

 using (FileStream stream = new FileStream(@"...\Test.png", FileMode.Create)) {
     PngBitmapEncoder encoder = new PngBitmapEncoder();
     encoder.Interlace = PngInterlaceOption.On;
     encoder.Frames.Add(BitmapFrame.Create(imageSource));
     encoder.Save(stream);
 }

The post How to save a BitmapSource in WPF appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2014/07/save-bitmapsource-wpf/feed/ 0 527
URL Testing Site http://zombieswithcoffee.com/2014/03/url-testing-site/ http://zombieswithcoffee.com/2014/03/url-testing-site/#respond Sat, 08 Mar 2014 13:12:25 +0000 http://zombieswithcoffee.com/?p=522 I am testing out some URL configuration for the Windows Phone 8 device. DSI Communication Setup Link In order to test “launch from URL”, put this as the first argument: Launch from URL 1 In order to test “launch from URL”, put this as the first argument: Launch From URL 2  

The post URL Testing Site appeared first on Zombies With Coffee, LLC.

]]>
I am testing out some URL configuration for the Windows Phone 8 device.

DSI Communication Setup Link

In order to test “launch from URL”, put this as the first argument:

Launch from URL 1

In order to test “launch from URL”, put this as the first argument:

Launch From URL 2

 

The post URL Testing Site appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2014/03/url-testing-site/feed/ 0 522
Video of Hammer Animation http://zombieswithcoffee.com/2013/11/video-hammer-animation/ http://zombieswithcoffee.com/2013/11/video-hammer-animation/#respond Wed, 27 Nov 2013 19:56:32 +0000 http://zombieswithcoffee.com/?p=515 I finally decided to grab a screen capture program and record the animation of the hammering and the timing inside of SpriteBuilder Hammer

The post Video of Hammer Animation appeared first on Zombies With Coffee, LLC.

]]>
I finally decided to grab a screen capture program and record the animation of the hammering and the timing inside of SpriteBuilder

Hammer

The post Video of Hammer Animation appeared first on Zombies With Coffee, LLC.

]]>
http://zombieswithcoffee.com/2013/11/video-hammer-animation/feed/ 0 515