Posts

C# Producer Consumer using Rabbit MQ

So I've been learning about the different message queuing systems and discovered rabbit MQ, an open source and very popular message queuing system. I've created a very basic producer/consumer system that sends a message to a rabbit MQ queue. Producer/Consumer is pretty simple, you have two systems a producer that writes to a queue and a consumer that reads from a queue. This is desirable because it splits responsibility and allows for scalability. The code below is going to assume you have a rabbit MQ instance installed on your local machine. You can get rabbit MQ here:  https://www.rabbitmq.com/ Now the code is broken down into 3 parts, the main program, the producer, and the consumer. This is a basic example so its using old school threading rather than the new async/await .net prefers. But this is just to show how to use rabbit MQ in C# and to demonstrate a producer/consumer example. You will need to make sure your project has the rabbit MQ client nuget package installed

C# DateTime Formatting

C# Offers a wide variety of formatting date times using the ToString method. Below you will see the various options you can use and the results. Format Result DateTime.Now.ToString("MM/dd/yyyy") 05/29/2015 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 05:50 AM DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50 DateTime.Now.ToString("dddd, dd MMMM yyyy") Friday, 29 May 2015 5:50 AM DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss") Friday, 29 May 2015 05:50:06 DateTime.Now.ToString("MM/dd/yyyy HH:mm") 05/29/2015 05:50 DateTime.Now.ToString("MM/dd/yyyy hh:mm tt") 05/29/2015 05:50 AM DateTime.Now.ToString("MM/dd/yyyy H:mm") 05/29/2015 5:50 DateTime.Now.ToString("MM/dd/yyyy h:mm tt") 05/29/2015 5:5

C# Getting your IP address

Sometimes you need to know your ip address in code. With the following snippet you can! var hostName= new HostInformation(); var address = Dns.GetHostEntry(hostName).AddressList[0].ToString();

Old School C++ guess the number game

It's been a while since I blogged but I've got some old fashioned code I've updated using the latest versions. This is some C++ code for a simple guessing game. You get 10 tries to guess a number between 1 and 100. The game picks the number randomly and tells you if you've guessed to low, to high, or correctly. This is written using the newer C++ 11 standard so you'll notice some weird stuff with the random number generating. I will post some links to this below. #include <iostream> #include <random> using namespace std; int main() { random_device randomDevice; mt19937 mt(randomDevice()); uniform_real_distribution<double> dist(1.0, 100.0); int numberOfTries = 0; int numberToGuess = dist(mt); int maxNumberOfTries = 10; int currentGuess = 0; bool wonGame = false; cout << "Welcome to guess the number" << endl << endl

Raspberry PI 3+ python blinking LED

I've recently been getting into the raspberry PI world. I have a model 3+ that one of my first projects was to get an LED to blink. The following below will make an LED blink for a random amount of time for a random amount of times. import RPi.GPIO as GPIO import time import random from random import * # set the output mode of the GPIO pins GPIO.setmode(GPIO.BCM) # don't show warnings in the console GPIO.setwarnings(False) # this sets the output to pin 18 (positive) GPIO.setup(18,GPIO.OUT) # we randomly pick some numbers numberOfBlinks = randint(10,30) blinkLength = randint(1,5) print(numberOfBlinks,blinkLength) print("LEDs on") counter = 0 # loop through and turn the LED on and off while counter <= numberOfBlinks: # set the output to high (ON) GPIO.output(18,GPIO.HIGH) # wait for X seconds time.sleep(blinkLength) # set the output to low (OFF) GPIO.output(18,GPIO.LOW) counter =

WPF create a grid splitter

You will often find yourself needing to have two panels on a screen with a slider between them. WPF gives you a nice way to handle this with the GridSplitter control. You will need to create a column for the actual splitter and it will use the width you give it in the column definition. <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="5" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <TextBlock FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap">Left side</TextBlock> <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" /> <TextBlock Grid.Column="2" FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" Te

WPF Bind a combobox to an enumeration

I've often found myself needing to bind a combo box to an enumeration I've created. You can do this in WPF but it's a bit complicated. You end up needing to create a static resource. I had mine in a user control. First the enumeration I was using: namespace XmlCoderBI.Enums { /// <summary> /// An enumeration that represents the type of conversion we're doing /// </summary> public enum ConversionType { /// <summary> /// The binary /// </summary> [Description( "Binary" )] Binary = 0, /// <summary> /// The base64 /// </summary> [Description( "Binary" )] Base64 = 1, /// <summary> /// The hexadecimal /// </summary> [Description( "Hexadecimal" )] Hexadecimal = 2, /// <summary> /// The UTF-8 /// </summary> [Description( "