Logitech Gaming Software

by Luke 18. February 2012 07:03

I bought a new mouse (G400) and tried to install the software but just got a runtime error regarding the C++ redistributable so I checked the forum but only found people saying to reinstall the software which, of course, doesn't work. It turns out that you just need to make sure it runs as administrator for it to work.

 

My machine: W7 64 bit, Logitech gaming software 8.2

Tags: ,

General Technical

Regex - Validate IP

by Luke 2. November 2011 21:39

I was just doing some validation for a WOL application I'm making and needed to verify the IP was correct, here's my approach. I'm wondering if it could be any shorter / more efficient?

 

([0-2]?[0-9]{1,2}\.){3}([0-2]?[0-9]{1,2})

Tags: ,

.NET Development

HTC Desire S: Delete Google / Facebook Contacts

by Luke 29. May 2011 13:10

I got a new phone and have been trying to figure out how to do various bits and peices. While doing this I logged in to Facebook then gTalk and it downloaded all my contacts so whenever I tried to do anything in "People" it would show all the Google and Facebook friends. It took me a while to realise how to remove them but here it is:

 

Delete the unwanted contacts

 

  1. Go into People
  2. Press the three horizontal bars at  below the screen
  3. Press View
  4. Tick "Google" and untick the others
  5. Click Done.
  6. Now go back and you'll see all the Google contacts but none of your phone contacts
  7. Click Delete
  8. Get rid of the keyboard and press the three bars again then Select All and finally delete.

 

 

Now they're all gone :)

Tags: , ,

General Technical

Turning Bad Publicity Good

by Luke 15. April 2011 19:11

Over the past few days in Britain there has been a story about a gay couple who were thrown out of a pub for kissing. The pub has strategically avoided saying it is because the couple were gay but whether or not that is a problem is down to their own prejudices... however, they have missed a massive marketing opportunity by reacting defensively and clamming up about the situation. Their one representative, according to the news articles, seemed to be saying that they would have stopped a straight couple from kissing as well but this is not a positive for their business and is clearly just a stab at appearing to uphold equality values. Many local people were outraged at the gay couple being booted out so organised a 'kiss-in' where, reportedly, 700 people agreed to participate. Seven hundred people! FOR FREE! Due to this overwhelming protest they have closed their doors and will make no money tonight and have probably become unpopular with the locals because they have caused so much trouble.

 

So what should the pub company have done?

First: Regardless of why the particular landlord kicked out the couple they should have made a public announcement apologising for the pair being thrown out and either stating their rules clearly (if they do currently have rules that are fair on this issue) or send the landlord off for "training" then stand an open invite for all couples to come back. This would have kept them open today by negating the need for the protest entirely.

 

Second: If they didn't do my first point or if that didn't work they should have shut shop earlier this afternoon, bought a lot of love-heart balloons and whatever valentine's day leftovers they can find and decorated the pub. Following this they should then have posted on the Facebook group for the 'kiss-in' an apology for the misunderstanding and openly invited them to join in on this ad-hock late valentines evening. They should have also contacted local papers (plus the BBC) to make an open invite to all couples.

 

They would have had a LOT of interest, a LOT of revenue, a fantastic public image and probably won a huge amount of customer loyalty.

 

The stories:

http://www.bbc.co.uk/news/uk-england-london-13087715

http://www.bbc.co.uk/news/uk-england-london-13096519

Tags: , ,

Random

UFO Typer

by Luke 5. April 2011 20:55

I decided to try making a simple typing game in javascript but I didn't really expect to see it through to completion. However, things went better than expected and now you can play it HERE

Tags: ,

General Technical | Web Development

Magic The Gathering: Life Counter

by Luke 13. March 2011 17:41

I was going to write a program to act as a life counter and I considered adding other features but then I realised that there was no need to go to all that trouble for a simple life counter when you have Excel/OpenOffice installed. I just spenta few minutes listening to some random dubstep throwing this together. It looks horrible but hey, you can spruce it up.

MTG Life Counter.xls (25.00 kb)

Tags: ,

Random

Streaming Media with VLC

by Luke 8. March 2011 21:53

I was trying for a while to get this working and just couldn't - until now. There is documentation but I never find it clear enough so here's my explanation.

NOTE:/ VLC doesn't actually support streaming very well so if you follow this guide and it is unwatchable just share the folder with your video files and open them as you would a normal file using VLC.

FIRST OFF

You need to run VLC to 'SEND' the video and another instance to 'RECIEVE' the video and these CAN be on the same computer. So, open up VLC and click Media then either "Streaming" or "Advanced Open File"

You will then get this. Add some files and then click the drop down arrow at the bottom to select STREAM then click the button.

 

A few things here. After clicking the STREAM button you'll get a page that says "Source" and shows a string with the selected file names, just click the NEXT button on that and you will then get the below. Select RTP/MPEG and click ADD. I've also highlighted the 'pages' with a green underline in this image so you can see what I mean by 'page.'  Also, note that I have put a red box around the NEXT button - this is just to point out where it is.

 

Once you have clicked the ADD button you'll get this screen and this is where things get confusing (or at least they did for me). You need to know what your network's broadcast address is as this IP is the destination you want to send to. You could read up on networking to find out what a "broadcast address" actually is or you could just use http://www.tech-faq.com/calculate-broadcast-address to figure it out for you based on your computer's IP address (use ipconfig or network properties to get that). Enter the address as shown and click next.

You will get the general Options page, tick SAP announce and enter a name for your stream - ignore Group Name - then click STREAM.

 

 

You are now STREAMING!!!! Now you know the quick and dirty way to get it done you can play with the other options and learn how to make it work smoothly and so you can remotely control it - I know these things are possible with VLC but I haven't figured them out yet.

NOW TO WATCH!

Open another VLC instance either on the same computer or a different one on the SAME network. Click Media then Open Network Stream.

 

Now enter RTP:// followed by your network's broadcast address and click PLAY.

 

Sit back and enjoy the film :)

 

 

NOTE:/ You can listen to rtp://@:5004 where '5004' is the pot selected in your DESTINATION.

Tags: , ,

General Technical

C#.NET Scripting Support In Your Applications

by Luke 1. November 2010 23:11

Hi all,

This is a technical blog post today that I hope will be fairly useful to everyone out there. I have wondered how to actually include scripting abilities within my applications and today I decided to figure it out. The process is actually pretty simple. You need to include two namespaces which are System.CodeDom.Compiler and System.Reflection to do this (the first compiles your 'script' while the second lets you use the result) and then you can do whatever you want from there. Here's one I made earlier...

private void btnRun_Click(object sender, EventArgs e)
  {
    CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("C#");
    CompilerParameters codeParams = new CompilerParameters();
    CompilerResults codeResults = null;
    codeParams.GenerateExecutable = false;
    codeParams.GenerateInMemory = true;
    codeParams.IncludeDebugInformation = false;
    codeParams.ReferencedAssemblies.Add("System.dll");
    codeParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
    codeResults = codeProvider.CompileAssemblyFromSource(
                        codeParams,
                        new string[] { txtSourceInput.Text }
                        );

    CompilerErrorCollection codeErrors = cResults.Errors;

    Type[] resultTypes = cResults.CompiledAssembly.GetTypes();
    object o = codeResults.CompiledAssembly.CreateInstance(
                  resultTypes[0].FullName
                  );
    MethodInfo[] m = resultTypes[0].GetMethods();
    m[0].Invoke(o, null);
}

There's a lot to note here:

 

  1. Lines 9 and 10 are adding referenced assemblies programmatically but this is the same as right clicking "References" in your project and clicking "Add Reference" as this makes the methods within those assemblies available to the dynamically compiled code (the user's script). I was testing this by popping up a messagebox so needed System.Windows.Forms.dll but you could add anything here that would work using the "Add Reference" option of a normal project.
  2. Line 11 uses an array of strings, I'm not sure why but for a standard user script you can just do what I've done and enter the whole text box as the first element.
  3. Line 15 shows the retrieval of the compile errors collection which is IMPORTANT! If you don't check this for errors then your application will likely crash due to bad end-user code. I was just doing this as testing so I haven't added anything to actually check the collection but if "codeErrors.HasErrors" is false then it's good to go.
  4. Line 17 creates the type by using the FULL NAME If you do not do this you will get the exception "Non-static method requires a target" unless you execute static methods.
  5. The remaining lines are NOT good code and you shouldn't do things this way in your live applications but this is fine as an example. I'm showing the way to get the types, create an instance, get the methods of that type and then how to invoke the first method of the instance of that type. You can easily modify this code to check for an expected type and method and provide parameters as needed.
When you come to test this you must feed it fully correct C# or the CompilerErrorCollection will have errors. So, for example, you cannot try to compile "MessageBox.Show("HI!!");" but you can compile:

 

namespace MyDynamicNamespace
{
	public class MyDynamicClass
	{
		public void MyDynamicMethod() 
		{
			MessageBox.Show("This is a test");
		}

	}

}

Tags: , , ,

.NET Development

To Follow The Path You Must Become The Path

by Luke 12. October 2010 23:11

 

This ancient saying seems to, for a lot of people, be a complete mystery but it means “be the example.” At first this may seem a little complicated but it is essentially a suggestion to act in the way you would like others to act or how you believe it would be best for others to act.

For example, if you believe in peace above all else but you get aggressive because your sports team doesn’t win the game then you are not “becoming the path.” If your sports team lost and you were angry but knew that you were angry, understood why and consciously decided to accept it and move on you would be on the path to – and ‘be’ the path to – enlightenment.

In the same vain, if you believed in preserving life but chose not to save yourself or others in a crisis then you would not “be the path”. If you were under attack and chose to retaliate to save yourself and understood your decision to do so then you would “be the path”.

It is a very simple concept that is shrouded in thousands of years of mysticism. To grow beyond simple needs and vengeful desires you need to acknowledge, decide and move on.


 

Tags: , ,

Random

Screenshot Code

by Luke 23. September 2010 22:55

This is very simple but I wanted to test the Syntax highlighter I just installed on the blog.

001using System;
002using System.IO;
003using System.IO.Compression;
004using System.Drawing;
005using System.Drawing.Imaging;
006using System.Collections.Generic;
007using System.Windows.Forms;
008
009    class Screenshot
010    {
011        List<Bitmap> _screenImages = new List<Bitmap>();
012        Graphics _gfx;
013
014        /// <summary>
015        /// Creates a new Screenshot object for taking, saving and compressing screenshots
016        /// </summary>
017        public Screenshot()
018        {
019        }
020
021        /// <summary>
022        /// Get a stream for the selected image
023        /// </summary>
024        /// <param name="index">zero-based index of the image</param>
025        /// <param name="compress">use compression or not</param>
026        /// <returns>Stream</returns>
027        public Stream this[int index, bool compress]
028        {
029            get
030            {
031                if (index >= 0 && index <= _screenImages.Count)
032                {
033                    MemoryStream[] ms = new MemoryStream[] { new MemoryStream(), new MemoryStream() };
034                    _screenImages[index].Save(ms[0], ImageFormat.Bmp);
035                    if (compress)
036                    {
037                        compressOutput(ms[0], ms[1]);
038                        ms[0].Close();
039                        ms[0] = null;
040                        ms[1].Seek(0, SeekOrigin.Begin);
041                        return ms[1];
042                    }
043                    else
044                    {
045                        ms[0].Seek(0, SeekOrigin.Begin);
046                        return ms[0];
047                    }
048                }
049                return null;
050            }
051        }
052        /// <summary>
053        /// Get a stream for the selected image
054        /// </summary>
055        /// <param name="index">zero-based index of the image</param>
056        /// <param name="compress">use compression or not</param>
057        /// <param name="format">type of image to return</param>
058        /// <returns>Stream</returns>
059        public Stream this[int index, bool compress, ImageFormat format]
060        {
061            get
062            {
063                if (index >= 0 && _screenImages.Count < index)
064                {
065                    MemoryStream[] ms = new MemoryStream[1];
066                    _screenImages[index].Save(ms[0], format);
067                    if (compress)
068                    {
069                        compressOutput(ms[0], ms[1]);
070                        ms[0].Close();
071                        ms[0] = null;
072                        ms[1].Seek(0, SeekOrigin.Begin);
073                        return ms[1];
074                    }
075                    else
076                    {
077                        ms[0].Seek(0, SeekOrigin.Begin);
078                        return ms[0];
079                    }
080                }
081                return null;
082            }
083        }
084
085        public int Count
086        {
087            get { return _screenImages.Count; }
088        }
089
090        /// <summary>
091        /// Capture all screens to memory
092        /// </summary>
093        public void CaptureAllScreens()
094        {
095            _screenImages.Clear();
096            foreach (Screen x in Screen.AllScreens)
097            {
098                Bitmap tmp = new Bitmap(x.Bounds.Width, x.Bounds.Height, PixelFormat.Format32bppArgb);
099                _gfx = Graphics.FromImage(tmp);
100                _gfx.CopyFromScreen(0, 0, 0, 0, x.Bounds.Size, CopyPixelOperation.SourceCopy);
101                _screenImages.Add(tmp);
102            }
103        }
104
105        /// <summary>
106        /// Capture only the primary screen
107        /// </summary>
108        public void CapturePrimary()
109        {
110            _screenImages.Clear();
111            Bitmap tmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
112            _gfx = Graphics.FromImage(tmp);
113            _gfx.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
114            _screenImages.Add(tmp);
115        }
116        /// <summary>
117        /// Capture a specific screen from the Screen collection
118        /// </summary>
119        /// <param name="screen">Screen object</param>
120        public void CapureScreen(Screen screen)
121        {
122            _screenImages.Clear();
123            Bitmap tmp = new Bitmap(screen.Bounds.Width, screen.Bounds.Height, PixelFormat.Format32bppArgb);
124            _gfx = Graphics.FromImage(tmp);
125            _gfx.CopyFromScreen(0, 0, 0, 0, screen.Bounds.Size, CopyPixelOperation.SourceCopy);
126            _screenImages.Add(tmp);
127        }
128
129        /// <summary>
130        /// Compress the input stream to the output stream using DeflateStream
131        /// </summary>
132        /// <param name="source">source stream</param>
133        /// <param name="destination">destination stream</param>
134        void compressOutput(Stream source, Stream destination)
135        {
136            DeflateStream ds = new DeflateStream(destination, CompressionMode.Compress);
137            byte[] buffer = new byte[2048];
138            int bytesRead = 0;
139            source.Seek(0, SeekOrigin.Begin);
140            bytesRead = source.Read(buffer, 0, buffer.Length);
141            while (bytesRead > 0)
142            {
143                ds.Write(buffer, 0, bytesRead);
144                bytesRead = source.Read(buffer, 0, buffer.Length);
145            }
146            ds.Flush();
147        }
148    }
149

Tags:

.NET Development

About the author

Luke is a computer programmer from England with a keen interest in .NET development.