Code Archives - Falafel Software Blog

Getting Started With Electron and TypeScript

By | Desktop, Electron, JavaScript, TypeScript, Web | 2 Comments

What is Electron? ElectronJS is a cross-platform app framework that allows you to leverage existing knowledge of JavaScript, HTML, and CSS to build apps for Windows, OSX, and Linux using a shared codebase. It is based on Node.js and Chromium and is used by many popular apps such as Visual Studio Code, Slack, and the Atom editor. If you haven’t already, install the Electron Prebuilt package from npm:

What is TypeScript? TypeScript is a typed superset of JavaScript that compiles into plain JavaScript. It is an easy way to simplify large complex JavaScript codebases or ensure integrity when working…

Read More

A Simple Natural Sort

By | .NET, C# | 5 Comments

If you’ve ever had to sort alphanumeric data, you’ve probably encountered the issue of sort order when letters and numbers are mixed. Here is a quick example:

The first set is using a standard ASCII sort which is sorted correctly, but not what most people expect–shouldn’t a2 come BEFORE a11? What they want is a natural sort which treats letters as letters and numbers as numbers rather than treating everything as an individual ASCII character. There are PLENTY of natural sort solutions out there and some may work better for your particular situation, but I came up with a simple natural…

Read More

Heart Rate Display with a Photon and a Microsoft Band

By | .NET, Blogs, C#, Fun, IoT, Microsoft Band, Mobile, Multi-Device, News, Photon, Visual Studio, Windows Phone | 4 Comments

Those who know me, know I love sensors, and doing things with sensors. I’ve published many posts on accessing the various sensors on the Microsoft Band: Accelerometer & Gyroscope, Ultraviolet, Skin Temperature, and Galvanic Skin Response. One subject that I haven’t gotten to is the heart rate sensor. I’ve also started to publish a few IoT posts. For this post, I thought it would be fun to integrate the Band’s heart rate sensor with a Particle Photon so you can visualize your heart rate with an RGB LED. The LED pulses at the same rate as your heart and will shift…

Read More

Controlling an RGB LED on a Photon with a UWA Color Picker

By | .NET, Blogs, C#, Fun, IoT, Microsoft, Mobile, Multi-Device, News, Photon, Visual Studio, Windows Universal Apps | 3 Comments

The Particle Photon makes it easy to control the color of an RGB LED. There are a number of color picker controls you can use in Windows apps. I wanted to see how easy it was to hook a Photon RGB LED up to a Windows app color picker. It ended up being a snap by using the Particle cloud functions. In this project I wrote a simple UWA that calls a Particle cloud function called “setRGB” on my targeted Photon whenever I change the selected value on the color picker. Then I implemented an event handler on that Photon’s…

Read More

Exploring Multi-Photon and Particle Cloud Functionality with a Useless Machine

By | .NET, Blogs, C#, Fun, Hardware, IoT, Microsoft, Mobile, Multi-Device, News, Photon, Visual Studio, Web, Windows, Windows Universal Apps | 2 Comments

There are many ways for Particle Photons to interact with each other. Even more ways for other devices and apps to interact with Photons through the Particle Cloud. To explore these capabilities, I created a useless machine. My useless machine is made up of two Photons. Photon 1 “falafel_1” has a photo resistor and a green LED. Photon 2 “falafel_2” also has a photo resistor and a green LED. However, Photon 2 also has a servo motor and a second red LED. The servo motor is mounted so that when it is rotated to 90 degrees, it covers both photo…

Read More

Windows IoT Core Remote Wifi Scanner

By | .NET, C#, Fun, IoT, Microsoft, Mobile, Multi-Device, News, Visual Studio, Windows, Windows Universal Apps | 3 Comments

Windows IoT Core has a nice web-based device management interface. This app can configure many aspects of the device, such as connecting the device to a WiFi network. Because the web-based device management was just a web app, I thought it shouldn’t be difficult to write a remote app to do the same. I ended up with a remote app that could query WiFi networks visible to a Windows IoT Core device and connect or disconnect that device to those networks. To get started, I connected my browser to the web-based device management app for one of my Windows IoT Core…

Read More

Microsoft Band Sensors – Accelerometer & Gyroscope

By | .NET, Blogs, C#, Fun, Microsoft, Mobile, Multi-Device, News, Windows | 11 Comments

Microsoft just released the Microsoft Band SDK Preview and I’m excited. Just like with any other electronic gadget, I’m interested in the sensors. The Band is stuffed full of sensors, but the first ones I want to look at are the accelerometers and gyroscopes. From the preview site you can download samples for Windows Phone, Android, and iOS. You also need the documentation. To get started with my sensors investigation, I downloaded the Windows Phone sample code and followed the instructions here to get started with my own project. Accessing the accelerometers and gyroscopes is easy and follows a familiar…

Read More

Data Annotations & Entity Type Configuration

By | .NET, C#, News, Web | 3 Comments

We can replace Data Annotations with Entity Type Configuration to make our classes look clean and simple. Majority of developers prefer using View Models for CRUD operations leaving no reason to have Data Annotations defined in our model classes. This article will show you how to replace Data Annotations with Entity Type Configuration when using Entity Framework Code-First.

Read More

Displaying the Device Compass in Unity

By | .NET, Blogs, C#, Fun, Mobile, Multi-Device, News, Unity, Windows | 5 Comments

In my last Unity post we looked at integrating the accelerometers in a Unity app. In this post we look at integrating the magnetometer. A couple of years ago I published a magnetometer application in the Windows Phone Store. That app shows the magnetometer readings in 3D in relation to the orientation of the phone. The magnetometer sensor is how your device senses true north for the compass. For some devices (like my Nokia 1520), the Unity magnetometer API hides the 3D vector and only gives you access to the 2D vector “compass” data. I’ll live with that for now. In…

Read More
Falafel Blog

Microsoft OCR Library

By | .NET, Blogs, C#, Fun, Microsoft, Multi-Device, News | 2 Comments

Microsoft recently announced that their OCR Library for Windows Runtime has been released as a NuGet package. This library enables you to add text reading capabilities to your Windows Phone 8/8.1 and Windows 8.1 Store apps. I wanted to get a simple working example up and running and found it to be quite easy and functional. I created a basic Windows 8.1 Store app. The XAML for the main page is listed below.

The code behind has only one event handler for the button click and because this is just a simple working example contains all of the code necessary…

Read More

Entity Framework and Enum Flags

By | .NET, C# | 2 Comments

If you have ever had the need to store one or more possible values in a single field, you may have used the [Flags] attribute on an enum in C# which would look something like this:

The numeric values that we assign are important, because it allows us to do bit-wise operations on the number.  The values themselves can easily be calculated by raising 2 to the power of a zero-based sequence of numbers.  So this: 2⁰, 2¹, 2², 2³, 2⁴, 2⁵, 2⁶ yields this (yes, 2 to the zero power is one): 1, 2, 4, 8, 16, 32,…

Read More
Page Selector

Sitefinity: Page Selector Field for Multisite

By | .NET, C#, News, Sitefinity | No Comments

Multisite is a great feature in the Sitefinity, which helps you centrally manage multiple sites using one administration panel. Few days ago I was working in a same environment where I needed to add a Page Selector field to a custom module built using Module Builder. But we needed to make Page Selector field to show pages from the current site. As it takes a rootNodeId (GUID for root page node) so it shows same pages under provided id. So, we needed to make it dynamic so that it would load pages from the current site.

Read More
Adding Document Selector Field

Document Selector Field in Sitefinity

By | .NET, C#, Sitefinity, Web | No Comments

Sitefinity Thunder lets you create field controls very easily which can be added to custom modules. However some work is required particularly when you need to have a selector field. Recently I built a Document Selector field control so I thought to share it. The purpose of this selector is to allow single document selection and be added as a text field (localizable).

Read More

Picking your Challenges – Luminance for Points

By | .NET, Blogs, C#, Fun, Windows | No Comments

One of the things I’m learning as I’m settling into my #2520orBust challenge, is picking which challenges I’m going to tackle on DVLUP.com. You have to consider the requirements of the challenge and the due dates. You also have to consider the amount of free time you have to devote to the challenge. For me, that’s not much time. So, I’m looking at the low hanging fruit right now. The next challenge on my list is the “New App Special“. It’s 250 pts, and I’ve got until the end of August. The app I have in mind is a lux…

Read More

It’s Tuples All The Way Down!

By | C# | No Comments

Tuples in C# provide developers with a quick way of creating data structures without the need to define a separate class, but they should be used with caution. I’ll demonstrate when you should–and shouldn’t–use tuples. Spoiler alert: I do not recommend the code in the adjacent image!

Read More

Entity Framework and Custom Properties

By | News | 2 Comments

Entity Framework makes it very easy to get data from your database through mapped entities and having foreign keys mapped as navigation properties makes it really easy to traverse relationships in your database.  However, there is often a lot of overhead if you “include” your entire child entity along with the primary, parent entity. For example, let’s say we have an Order entity and each Order has a non-null ShippingAddressId that gives us a 1..1 to the Address entity.  We can use Include() to return that related Address entity:

But what if our Address entity has 20 columns in…

Read More

Using Generic Attached Properties to Simplify Windows 8 Settings Charm Pages

By | .NET, C#, Fun, Microsoft, Tools | No Comments

I’ve always liked attached properties… so much so that a couple of years ago I created a series of generic classes to simplify the process of creating custom attached properties. Attached Properties – a review: External control interactions — like the Grid.Row attached property. Basic info storage — just like the Tag property. Behaviors — changing properties and behaviors of the parent control. Bindings — to achieve custom bindings between UI controls. If you use XAML, you use attached properties whether you realize it or not. Creating a custom attached property only takes a few lines of code. Many declarative…

Read More

What is “var that = this” in JavaScript?

By | Web | No Comments

If you’ve looked at JavaScript recently after any kind of hiatus, you’ve probably noticed that the language has changed a little in the last few years. Technically, the language hasn’t changed so much as the way we use it has.  One of the most noticeable changes–besides the daily multiplying list of new libraries and frameworks–is the object oriented way in with the language is used. For instance, instead of just creating a sea of functions, you might now create your JavaScript code in classes of related functionality: var mathObj = {     writeToLog: function (message) {         console.log(message);     },       addNumbers: function (one, two)…

Read More

Breaking on Exceptions in XCode

By | iOS | No Comments

If you happen to be experienced in development using Visual Studio, but a bit new to working in XCode for iOS development (like me), you are probably used to your application breaking on exceptions during debugging.  But by default, your iOS application may not act as you expect when it comes to debugging crash exceptions.  You may instead see something like this: With an error message that says:  *** Terminating app due to uncaught exception What?  Why was my exception uncaught while I am debugging?  I, for one, would rather be taken to the point at which the exception occurred,…

Read More

Loading Google SketchUp 3D Models into Windows Phone Applications

By | .NET, Mobile | No Comments

In some of my previous WP7 blogs, such as Basic XNA Graphics for the WP7, I go over how to build basic 3D models for your applications. What happens when you want something more complex? You need a good 3D tool to generate those models for you. I started exploring Google SketchUp as a possibility for generating 3D models for the WP7. I found Jim’s Blog on how to load a Google SketchUp model into a XNA game. Jim used the DirectX/XNA Exporter Plugin. So I installed the plugin and started playing around. I thought it would be cool to…

Read More

Finding Closest Location by Latitude and Longitude

By | .NET, C# | One Comment

Mobile applications and web sites provide the perfect platform for proximity-based services so users can find the nearest X to their current location.  I will demonstrate some code that will allow you to find the closest location in a list when compared to a current latitude and longitude. While latitude and longitude provide precise coordinates, we can’t use a Euclidean distance formula because latitude and longitude are not on a cartesian plane, but on a sphere (technically, an ellipsoid, but we don’t need to be so precise here).  There are several pages that describe the differences between using the Haversine…

Read More

Generic Covariance and Contravariance Explained

By | C# | No Comments

One of the new features introduced in C# and VB 4.0 is this daunting pair of words. What is generic covariance and contravariance? The short explanation is that this new feature allows the generic type parameters of interfaces and delegates to behave polymorphically as you would expect of an equivalent non-generic interface or delegate. For more details and examples, read on. Definitions When class A is more derived (inherits from) class B, class A is covariant of class B. When class A is less derived (is the parent of) class B, class A is contravariant of class B. Example Classes…

Read More