Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

Code search woes

Published 11/27/2013 by createdbyx in News
Tags:

As a programmer I am getting a bit frustrated when it comes to repeating my self. 

I have started a few hundred .net projects over the last 10+ years and too often I find myself needing to write a piece of code that I am sure I've written before. As soon as I get a sense of dejavu I stop and think OK where and in what project could that piece of code be located. 

Performing windows explorer searches are useless in this case as you never know what the method name was or if it was a piece of code within a method. Simple text based file contents searches are just not up to the task. And they are painfully slow and can return hundreds of files.

There are similar solutions like Krugle, or Ack etc but many of these are on-line search tools. 

What I am looking for is something for windows that can run on my local machine and parse/understand C# .cs and VB.net .vb code files. 

A visual studio extension would be ideal, but the ones I've found only search the open solution not a entire folder hierarchy containing multiple projects etc.

For example I have written a piece of code that you give a directory path and it will return a list of files from that directory structure even files that are in sub folders. But here is what I know...

  1. It uses GetDirectory or GetFiles but does not use GetDirectories
  2. It's a method that takes at least 1 string parameter
  3. It returns a List<> string[] or some type that implements a IEnumerable interface
  4. It's less then 100 lines of code give or take
  5. It may or may not recursively call it self

Given these points of data search every folder and sub folder for methods within code files that contain the closest match.

If I can't find a utility to do this I'm going to say screw it and write my own. Even though I don't really want to have to.


These last few days have been testing my patience. Three of my devices Razer Naga Epic, Steel Series 7H & Microsoft Surface Pro 2 all failed within the last few days. I’ve always meant to write a review on these devices after having used them for a long while so I am writing the reviews now while I’m still angry!

Razor Naga Epic

Just before writing this post my naga epic mouse just bricked it self on me again. Seems if you are running the mouse wirelessly and the battery dies it will brick itself and become totally unresponsive. The support website says to leave it plugged in for 30 minutes to let the battery charge up a bit and it unplug it then plug it back in and it should just work. With the 5+ times that the battery has died on me this has never ever worked. The only way to get it back to working condition was for me to flash the firmware yet again! Immediately after the firmware finished flashing poof everything works again!

Essentially this mouse is fucking useless as a wireless mouse especially when you are like me and always forget to dock it or plug it back in BEFORE the battery dies. Not to mention the fact that the battery does not hold a charge worth a dam and it never has compared to the three Logitech mice I have owned over the years. I have owned this mouse for only about two years and after the first few weeks of accidentally letting the battery die multiple times I swore up and down I would never use it in wireless mode ever again.

And like a fucking idiot who clearly has not learned his lesson, two days ago I started using it in wireless mode again. Guess what? Battery died while using it and It bricked itself AGAIN!

$100+ dollar “gaming” mouse that bricks itself. Fucking. Awesome. It must have been a value added feature I over looked when purchasing. The Razer Synapse software you use for setting up the buttons doesn't sync worth a dam between multiple computers, and takes up way too much memory for what it does. I guess that is what $100 gets you now a days.

Steel Series 7H Headphones

What looked to be a good set of headphones after reading reviews turned out to be typical plastic bullshit. It only took a month for the glue holding the padding on the top connector bar to start to separating. It never separated more then an inch on one side and was not a real issue but still. They could not chip in for a stronger adhesive?

Within the first three months I had to replace the Mini-usb/audio jack cable due to a line break at the usb end connector. I had to position the wire with a bend in it just to get it working. So I ordered 2 replacement cables “Just in case” it broke again. Over the last year I have been having issues with the contact points where the headphones unclip and disassemble for easier transport. I was having to twist the headphones back and fourth a bit while on my head to get the sound to work.

Then just two days ago the right ear stopped working and the only way to get it working albeit for a fraction of a second is to rotate the right ear muff 90 degrees from the head strap part. Because of this it seamed to me that there was a wire getting pinched so I took the right ear piece apart and repositioned the wire a bit offset to give it more slack but with no success.

I wear the headphones fully extended to fit comfortable around my head and white looking at the top piece with the padding strip on it it appears as though at both ends where the contacts are the plastic is cracked. I guess I must have a huge bobble head.

Again $100+ dollar headphones dead after two years of infrequent use. I prefer using my 5.1 desktop surround sound so I hardly ever used them unless I was traveling or away from home. I bought them because I thought to myself hey they have good reviews and they come apart for easy transportation. Only two years with light use and there basically toast. Waste of fucking money. Went online to look for decent replacement headphones. Prices $80+ Fuck me the prices are ridiculous.

Microsoft Surface Pro 2

So earlier this morning I was mid sentence writing a line of code and poof the screen goes black and the lights were off on the usb mouse and keyboard I had plugged in. I was like “what the hell”? Did the system go into a sleep mode? That can’t be right I was actively coding. I tapped the windows logo at the bottom of the surface screen and it would give vibration feedback indicating that the button was tapped but nothing would happen. I tried Ctrl+Alt+Delete nothing. Windows Key+ L again nothing. The white light on the end of the power cable was on and it was giving vibration feedback when the windows logo was pressed but other then that it was a totally unresponsive black screen.

“What the hell is going on here” I thought. I tapped the power button and still nothing. Then it hit me. What if it tanked and died permanently? For fuck sakes if it did It would mean I have no access to the hard drive because the fucking thing is glued together so there goes any chance of me getting my data off the system. Even if I could get to the hard drive there is no indication that it is a standard laptop ssd that I could just pop into another computer. It could very well be soldiered on to the motherboard. This is why I had a strong hesitation against buying a ultra portable computer. You can’t take it apart easily.

I started looking around on the internet and found a few articles with people having similar black screen issues. I held the power button down for 10 seconds, then held the volume up rocker and the power button for 10 seconds. Finally I managed to get it to reboot.

“What a fucking week, what next!”

I was keeping all my data on a 32gb SD card but then I deleted a code file and a few minutes later wanted to undelete it. Turns out there is no recycle bin for SD cards. Oh fuck no. So I moved my data over to the ssd as it was a bit faster working with files anyway and was going to setup a automated backup from the ssd over to the SD card using SyncBack free.

Then this morning the black screen of paranoia hit me and I realized that only some of my data is backed up to the cloud (SkyDrive). The rest was stored on the ssd, so had the system had a actual meltdown I would have been fucked and lost virtually all my data.

So my thinking was to keep all of my data on the SD card but with no recycle bin this become an serious issue. Storing files on the ssd without a backup solution is equally foolish as you can’t even get access to the physical ssd without destroying the machine. Putting files on the ssd and file backup to the SD card was my only option.

Microsoft SkyDrive

*takes a deep breath. Lets out long drawn out sigh*

How in the fuck can a company like Microsoft fuck up SkyDrive so badly. Ever since I have tried to use it back when Windows 8 first came out SkyDrive has displayed wonky messages, frequently takes up 30% of my CPU cycles and simply has not worked as expected compared to any and all other cloud based storage apps/services.

So one of the things I have foolishly tried to use again this week is SkyDrive to keep a cloud backup of my data. With the Surface Pro 2 I have 25gb plus another 200gb of free storage for two years. Shortly after Windows 8 launched I tried to move a few hundred thousand files from my coding projects over to SkyDrive so I could have them synced across all three of my machines. It took three fucking months to sync 8+ gigs of files. Three fucking months! On a 20mbit internet connection no less.

Since then I had stopped using it, but this week I gave it another try and moved my data from the SD card to the ssd (SkyDrive folder) and again this time I copied just over eight thousand files (about 300Mb) and two days later? Maybe a dozen or two code files had been backed up to the cloud. These are not big files they are code files! They are it’sy bitsy teeny weeny and SkyDrive seems to choke on them when trying to sync.

Google drive, Drop Box start syncing files immediately and work tirelessly to sync your files as soon as possible with little cpu overhead. SkyDrive seems to sit around on it’s ass twiddling it’s thumbs completely oblivious that I just put files into it’s folder. Then it has a heart attack when it realizes that there are files in it’s folder and starts taking 30% of my cpu cycles and after that still fucking seems to do nothing or next to nothing.

I have 225gb of SkyDrive storage and will not be using any of it. I do not ever want to have to think of using SkyDrive as a cloud backup service. 225gb of free online storage and you can’t even get people to use it. That’s how fucking craptacular your service is Microsoft. Zero customer trust. And to think a year ago for a brief moment I actually considered to pay for more SkyDrive space at one point. F that.


Surface Pro 2 Week 1

Published 10/31/2013 by createdbyx in News

So I received my Surface Pro 2 on October 25, 2013 and have been using it as my main machine this last week. Having never owned or even used a tablet before it has only been a slightly interesting experience as I am not one to get excited about such things.

Frankly the most immediate drawback to the tablet was running desktop software that has no touch support IE: Unity3D editor. It is making me realize that as a software developer I need to be making an extra effort thinking about touch integration. I was one of those people who really does not like the new windows 8 metro interface integration. As a developer I understand the reasons for it but even a year later it still has that meh feel to it.

It’s only now that I have been using a tablet this last week that I am actually beginning to conceptually understand the reasons for it moving forward. On the desktop metro does not make sense, when using a tablet the windows desktop does not make any sense. There is this incompatible duality about it, but all in all it kind of works, but it still feels like it could use some more finesse.

But getting back to the Surface Pro 2 I knew what I wanted out of a tablet

  • Pen/stylus for drawing sketches, note taking, making pixel art, sculpting in a 3D app etc
  • Decent battery life
  • Minimum 1080p display resolution
  • Full windows 8 pro experience so I could run all my applications and developer tools etc
  • Reasonable performance
  • Something in my price range IE: $1000+/-
  • It had to be able to at least play games like Skyrim at playable graphics settings
  • Minimum 8gb ram and 256gb ssd
  • Some sort of stand

After having looked around at a number of tablets Microsoft’s Surface Pro 2 was really the only logical choice. It has all the features I was looking for in a tablet aside from a replaceable battery, and no keyboard. I am holding off getting a keyboard until 2014, so that I can get a power cover that will further extend the battery life. Again the power cover keyboard is a ridiculous price at $200.

I do want to mention a few things about the marketing for the surface pro offerings. The way that they talk about the kickstand and the sound it makes like it’s the most coolest thing ever. It does not help the brand it hurts it. It’s a kickstand, so long as it does it’s job there is nothing more to say about it. They should be focusing on how it can be a desktop replacement for a lot of casual pc users. They should be touting it’s battery life etc. and not trying to make something trivial more then what it is. It cheapens the product.

Another thing I like about it is the fact that I no longer have to position it on my lap in such a way so it will not block any fans. Often times the air intake, and exhausts on laptops are poorly placed such that by placing them on your lap your legs block the air intake. The fan noise is not even audible, and even after playing a game the fan noise is still very quiet.

Lenovo has a new Yoga 2 Pro with similar specs but much higher screen resolution and better battery life but at the expense of being a bit heaver. With the 10.6in screen on the surface pro 2 and 1080p resolution individual pixels are just barely visible with 100% scaling. So I really don’t understand the purpose of higher resolution displays being used on small 13in screen sizes and under. More pixels means more processing and that actually hurts battery life, and frankly it really is unnecessary.

A funny thing just happened as I was writing this post, I got a BSOD message with a DPC_WATCHDOG_VIOLATION code. That’s the first time in many years probably since windows xp that I have experienced a bsod error. It happened while I was watching a flash video in internet explorer.

What I don’t like about the surface pro 2

  1. No replaceable battery. My laptop lasted me 7+ years but it’s battery no longer holds a charge. This is my single biggest concern.
  2. No replaceable ssd. With ssd capacities growing and prices getting cheaper being able to upgrade after 5+ years would be nice, 1080p, 2k & 4k video take up a hell of a lot of room
  3. Built in obsolescence aka 12 month release cycles & glued together components etc
  4. Only 8gb of ram is not enough when you are running 4 instance of visual studio, 3 instances of unity, a dozen browser tabs etc. It sounds a bit extreme but my desktop has 3 monitors and I work with multiple related coding projects at the same time
  5. Does not come with a keyboard and the keyboard prices are rather ridiculous
  6. Even with the 2 position kickstand it still does not quite sit at the right viewing angle on your lap
  7. No place to attach the pen when the power is plugged in. A place at the top of the tablet would have been nice, or better yet a hole in the tablet that you could insert the pen into like the Nintendo 3DS
  8. No magnetic lock on the keyboards when closed to prevent them from flapping open unintentionally
  9. The fear that one day I am going to break off the kickstand.
  10. Poor placement of the magnetic power coupling. I wish it were higher up along the side of the device closer to the top. The reason for this is because of the constant bend in the power cable. Over time I think there is a small chance it could wear out and have broken or kinked wires inside.
  11. The front facing camera could be pointed down just a few degrees to get a better head shot. Often my chin gets cropped off and I need to reposition the tablet when being used on my lap or lying back in bed. The alternative is to have a much higher resolution camera with a larger FOV.
  12. You can’t open it up to clean out any dust that has accumulated. As the years go by more and more fine dust will build up internally so my concern is that you may see a performance hit over the years because of poor ventilation. You could use a can of air to spray it out but given the size of the gap I’m concerned any large dust bunnies could get wedged in even further

What I would like to see in future surface pro hardware

  • Dedicated graphics hardware
  • At least 2 usb 3 ports
  • A replaceable battery/ssd
  • Slightly larger screen size offerings still at 1080 resolution
  • 32gb ram to help future proof the hardware and offer space for super speed ram drives
  • More sensors
  • DisplayPort in so you can use your tablet as a extra touch screen monitor
  • Kinect camera integration
  • A AMD based sku
  • Magnetic lock on the keyboard to make it stay securely attached to the screen when closed and used as a screen cover.

I believe with these few extra features (even without kinect camera integration) the surface pro line of tablets could be poised to take a dominant share of the tablet market. They have everything going for them but Microsoft being who they are will probably fail to capitalize on it. Stay tuned for further updates about my experience with the surface pro 2.


I am back from picking Matsutake. It’s supposed to be nice this upcoming week in my area so I may try and take a few trips up near the airport to see if I can find any more.

Also now that I am back I will be continuing my Code snippet and Unity tip series of posts, so watch out for them.


Gone Shroom’in!

Published 5/19/2013 by createdbyx in News

I'll be heading to High Level, Alberta May 26, 2013 to do some Morel picking for at least a few weeks. The last time I went Morel picking was about 6+ years ago so it will be fun to try it again.


Need to send simulated user input to the game window? Unity provides the EditorGUIUtility.QueueGameViewInputEvent method for doing just that. Using this method you could construct a utility that captures and plays back user input as your game is running which would be handy for debugging and unit testing purposes.


Unity comes with a helper method for generating a unique asset paths called AssetDatabase.GenerateUniqueAssetPath. The documentation for this method is rather minimal but the code example below should help you understand how to use it a little better.

GenerateUniqueAssetPath

[MenuItem("CBX/Test")]
public static void Test()
{
    // outputs "Assets/Rules.xml" if "Assets/Rules.xml" file does not already exist.
    // if "Assets/Rules.xml" already exists it outputs "Assets/Rules 1.xml"  
    Debug.Log(AssetDatabase.GenerateUniqueAssetPath("Assets/Rules.xml"));

    // expects path to start with "Assets/" & outputs a console error in the console "pathName.find("assets/") == 0"  
    // then outputs "Rules.xml" 
    Debug.Log(AssetDatabase.GenerateUniqueAssetPath("Rules.xml")); 
}

Below is a code sample containing drawing methods for drawing check boxes or any control type in a grid based layout similar to the SelectionGrid.

 
    using System;

    using UnityEngine;

    public class ControlGrid
    {
        /// <summary>
        /// Draw a grid of check boxes similar to SelectionGrid.
        /// </summary>
        /// <param name="checkedValues">Specifies the checked values of the check boxes.</param>
        /// <param name="text">The content for each individual check box.</param>
        /// <param name="columns">The number of columns in the grid.</param>
        /// <param name="style">The style to be applied to each check box.</param>
        /// <param name="options">Specifies layout options to be applied to each check box.</param>
        /// <returns>Returns the checked state for each check box.</returns>
        /// <remarks><p>Check boxes are drawn top to bottom, left to right.</p>  </remarks>
        /// <exception cref="IndexOutOfRangeException">Can occur if the size of the array is too small.</exception>
        public static bool[] DrawCheckBoxGrid(bool[] checkedValues, string[] text, int columns, GUIStyle style, params GUILayoutOption[] options)
        {
            // convert string content into gui content
            var content = new GUIContent[text.Length];
            for (var i = 0; i < content.Length; i++)
            {
                content[i] = new GUIContent(text[i]);
            }
            return DrawCheckBoxGrid(checkedValues, content, columns, style, options);
        }

        /// <summary>
        /// Draw a grid of check boxes similar to SelectionGrid.
        /// </summary>
        /// <param name="checkedValues">Specifies the checked values of the check boxes.</param>
        /// <param name="textures">The content for each individual check box.</param>
        /// <param name="columns">The number of columns in the grid.</param>
        /// <param name="style">The style to be applied to each check box.</param>
        /// <param name="options">Specifies layout options to be applied to each check box.</param>
        /// <returns>Returns the checked state for each check box.</returns>
        /// <remarks><p>Check boxes are drawn top to bottom, left to right.</p>  </remarks>
        /// <exception cref="IndexOutOfRangeException">Can occur if the size of the array is too small.</exception>
        public static bool[] DrawCheckBoxGrid(bool[] checkedValues, Texture2D[] textures, int columns, GUIStyle style, params GUILayoutOption[] options)
        {
            // convert texture content into gui content
            var content = new GUIContent[textures.Length];
            for (var i = 0; i < content.Length; i++)
            {
                content[i] = new GUIContent(string.Empty, textures[i]);
            }
            return DrawCheckBoxGrid(checkedValues, content, columns, style, options);
        }

        /// <summary>
        /// Draw a grid of check boxes similar to SelectionGrid.
        /// </summary>
        /// <param name="checkedValues">Specifies the checked values of the check boxes.</param>
        /// <param name="content">The content for each individual check box.</param>
        /// <param name="columns">The number of columns in the grid.</param>
        /// <param name="style">The style to be applied to each check box.</param>
        /// <param name="options">Specifies layout options to be applied to each check box.</param>
        /// <returns>Returns the checked state for each check box.</returns>
        /// <remarks><p>Check boxes are drawn top to bottom, left to right.</p>  </remarks>
        /// <exception cref="IndexOutOfRangeException">Can occur if the size of the array is too small.</exception>
        public static bool[] DrawCheckBoxGrid(bool[] checkedValues, GUIContent[] content, int columns, GUIStyle style, params GUILayoutOption[] options)
        {
            return DrawGenericGrid((e, i, s, o) => GUILayout.Toggle(e[i], content[i], style, options), checkedValues, content, columns, style, options);
        }

        /// <summary>
        /// Draw a grid of controls using a draw callback similar to SelectionGrid.
        /// </summary>
        /// <param name="drawCallback">Specifies a draw callback that is responsible for performing the actual drawing.</param>
        /// <param name="values">Specifies the values of the controls.</param>
        /// <param name="content">The content for each individual control.</param>
        /// <param name="columns">The number of columns in the grid.</param>
        /// <param name="style">The style to be applied to each control.</param>
        /// <param name="options">Specifies layout options to be applied to each control.</param>
        /// <returns>Returns the value for each control.</returns>
        /// <remarks><p>Controls are drawn top to bottom, left to right.</p>  </remarks>
        /// <exception cref="IndexOutOfRangeException">Can occur if the size of the array is too small.</exception>
        /// <exception cref="ArgumentNullException">If the drawCallback is null.</exception>
        public static T[] DrawGenericGrid<T>(Func<T[], int, GUIStyle, GUILayoutOption[], T> drawCallback, T[] values, GUIContent[] content, int columns, GUIStyle style, params GUILayoutOption[] options)
        {
            if (drawCallback == null)
            {
                throw new ArgumentNullException("drawCallback");
            }

            GUILayout.BeginVertical();
            var rowIndex = 0;
            var columnIndex = 0;
            var index = rowIndex * columns + columnIndex;

            GUILayout.BeginHorizontal();
            while (index < values.Length)
            {
                // draw control
                values[index] = drawCallback(values, index, style, options);

                // move to next column
                columnIndex++;

                // if passed max columns move down to next row and set to first column
                if (columnIndex > columns - 1)
                {
                    columnIndex = 0;
                    rowIndex++;

                    // remember to start a new horizontal layout
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }

                // re-calculate the index
                index = rowIndex * columns + columnIndex;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            return values;
        }
    } 

Here is a simple example of how to use the draw methods

var emptyContent = new[] { GUIContent.none, GUIContent.none, GUIContent.none, 
                            GUIContent.none, GUIContent.none, GUIContent.none, 
                            GUIContent.none, GUIContent.none, GUIContent.none };

GUILayout.BeginVertical(GUILayout.MinWidth(128));
rule.IgnoreUpper = GUILayout.Toggle(rule.IgnoreUpper, "Upper Neighbors");
rule.NeighborsUpper = ControlGrid.DrawCheckBoxGrid(rule.NeighborsUpper, emptyContent, 3, GUI.skin.button, GUILayout.MaxWidth(32), GUILayout.MaxHeight(32));
GUILayout.EndVertical();

ControlGrid


You can set the mouse cursor for a UI control by using EditorGUIUtility.AddCursorRect and specifying a MouseCursor enum.

if (GUILayout.Button("Add"))
{

}
            
// show the "Link" cursor when the mouse is hovering over this rectangle.
EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);


I was recently trying to get my Windows 7 Home Premium 64bit laptop to see the network drive on my Asus RT-N56U router with no success. It was a bit frustrating because my Windows 8 Pro desktop could see the drive on the router without any issues. Some search results talked about changing registry settings or changing values under the Group Policy Editor but these did not apply to Windows 7 Home Premium.

Ultimately I came across this one post here that suggested to add an entry to the hosts file. After adding “192.168.1.1  RT-N56U” to the bottom of the list poof I could now see a network place called “RT-N56U” inside file explorer. Wooty Woot !


Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume