Mistakes
The world revolves around mistakes. NASA crashed a Cessna to help improve Emergency Location Transmitters in planes so we can all be found and rescued if a plane crashes. They purposely “made a mistake” by crashing a plane to move forward with innovation and make everyone safer.
In my opinion, mistakes are priceless life experiences. Mistakes motivate us to solve problems and move humanity forward. Really every mistake we make in life can be a negative experience or a positive learning opportunity depending on how we perceive it. Mistakes can empower or motivate us to help others. To help others through the same mistakes or to prevent them more making our mistakes. Mistakes can be painful, just like growing pains, but mistakes help you to grow as a person and give you valuable life experience. It could be said the the stackoverflow.com community is a bunch of programmers, of all different levels, making mistakes. That is a huge group of people that are learning from their own mistakes and empowering others to learn from those same mistakes.
We grow up thinking everyone around us has never made a mistake. But when you hear about others mistakes and you realize, everyone has made the same exact mistake you have. We realize we are never alone. It might be hard at first to deal with a mistake, but don’t be hard on yourself. Treating mistakes as a priceless learning opportunity can help us all to have a better attitude about our mistakes.
You are NASA. Learn as much as you can from mistakes. Make mistakes for a better future. And most importantly: Don’t. Give. Up.
Wednesday, July 29, 2015
Thursday, June 25, 2015
I Love The Apple Watch, But Don't Buy It
I have owned the Apple Watch for a little over a month now.
I get the question, “Should I get an Apple Watch?” more then I thought I would. Strangers, people I work with, and friends. The short answer is no. You really shouldn’t. Before I tell you why you shouldn’t get one, let me make it clear. I love this Apple Watch.
I love the Apple Watch. I love it because it solves three problems for me. One, I never ever pick up my phone (unless it is to make a call) because all my notifications are on my wrist. Two, it is amazing for texting. Out of all the things the Apple watch does, it does texting best. Three, it has helped me become aware of how unfit I am.
Notifications
This is the Apple Watch’s primary feature. Other then telling time it is a notification angel. It silently vibrates on my wrist letting me and only me know I have a notification. This is a thousand times better then my phone vibrating on my desk, scaring the crap out of me, and also telling all those around me I have a notification. I look at the Watch, I determine if it is an important notification or not and 95% of the time, and move my wrist back. Done. This saves me a ton of time and helps me focus on whatever task might be at hand. I love this about the Watch.
Texting
I believe Apple did this right. This is the killer feature for me. Everything is quick and simple. The replies that Apple suggests to me often times work so I don’t have to say anything to my Watch. Just a tap and done. If that doesn’t work I just talk to my watch and done. Easy as pie. Really love this about the Watch.
Fitness
I semi-like this feature. I say “semi” cause it doesn’t work well. It works but sometimes it doesn’t and that can be frustrating. I sometimes run down the block to my car from work but the “Move” activity line doesn’t move an inch. I find that discouraging even though I know I ran to the car. It has however motivated me to move more, stand up more, and just be more fit. It is motivation and works well, except when it doesn’t.
I love the Apple Watch. It looks good. Works well most of the time for what I need it for. And in typical Apple fashion works with the iPhone and Mac seamlessly. But you shouldn’t buy it.
It is way overpriced. You mights say, all Apple products are overpriced. Which is not untrue. The difference is the Apple Watch does nothing. In theory it does everything but in practice it does nothing. It might save you from reaching for your phone which saves you time. But it does nothing.
I took the day off from my Apple Watch today. And felt no difference in my life. I did tap my analog watch three or four times today instinctively to check the time. But I didn’t miss it. I don’t need the Watch. However, I love it. And at this point this post, I have not helped you to decide you need it or not. I think I know the secret though.
Yesterday I got 82 text message. 64 of them where not acknowledged in my head but ignored. I got 21 emails yesterday that hit my phone, 2 of which I picked up my phone to read and respond to. I saved myself from 85 times I could have picked up my phone to just ignore something or get distracted. To me that is amazing. Not picking up my iPhone to skim the lock screen and keep my notification center under control at the same time is amazing.
So my advice to you, the reader, don’t get an Apple Watch unless you have $500 laying around burning a hole in your pocket. It is quite possible that the fact that you are reading this means, you don’t need an Apple Watch. It has practical use cases. And if they aren’t immediately apparent how you will use the Watch simply isn’t worth the investment.
I get the question, “Should I get an Apple Watch?” more then I thought I would. Strangers, people I work with, and friends. The short answer is no. You really shouldn’t. Before I tell you why you shouldn’t get one, let me make it clear. I love this Apple Watch.
I love the Apple Watch. I love it because it solves three problems for me. One, I never ever pick up my phone (unless it is to make a call) because all my notifications are on my wrist. Two, it is amazing for texting. Out of all the things the Apple watch does, it does texting best. Three, it has helped me become aware of how unfit I am.
Notifications
This is the Apple Watch’s primary feature. Other then telling time it is a notification angel. It silently vibrates on my wrist letting me and only me know I have a notification. This is a thousand times better then my phone vibrating on my desk, scaring the crap out of me, and also telling all those around me I have a notification. I look at the Watch, I determine if it is an important notification or not and 95% of the time, and move my wrist back. Done. This saves me a ton of time and helps me focus on whatever task might be at hand. I love this about the Watch.
Texting
I believe Apple did this right. This is the killer feature for me. Everything is quick and simple. The replies that Apple suggests to me often times work so I don’t have to say anything to my Watch. Just a tap and done. If that doesn’t work I just talk to my watch and done. Easy as pie. Really love this about the Watch.
Fitness
I semi-like this feature. I say “semi” cause it doesn’t work well. It works but sometimes it doesn’t and that can be frustrating. I sometimes run down the block to my car from work but the “Move” activity line doesn’t move an inch. I find that discouraging even though I know I ran to the car. It has however motivated me to move more, stand up more, and just be more fit. It is motivation and works well, except when it doesn’t.
I love the Apple Watch. It looks good. Works well most of the time for what I need it for. And in typical Apple fashion works with the iPhone and Mac seamlessly. But you shouldn’t buy it.
It is way overpriced. You mights say, all Apple products are overpriced. Which is not untrue. The difference is the Apple Watch does nothing. In theory it does everything but in practice it does nothing. It might save you from reaching for your phone which saves you time. But it does nothing.
I took the day off from my Apple Watch today. And felt no difference in my life. I did tap my analog watch three or four times today instinctively to check the time. But I didn’t miss it. I don’t need the Watch. However, I love it. And at this point this post, I have not helped you to decide you need it or not. I think I know the secret though.
Yesterday I got 82 text message. 64 of them where not acknowledged in my head but ignored. I got 21 emails yesterday that hit my phone, 2 of which I picked up my phone to read and respond to. I saved myself from 85 times I could have picked up my phone to just ignore something or get distracted. To me that is amazing. Not picking up my iPhone to skim the lock screen and keep my notification center under control at the same time is amazing.
So my advice to you, the reader, don’t get an Apple Watch unless you have $500 laying around burning a hole in your pocket. It is quite possible that the fact that you are reading this means, you don’t need an Apple Watch. It has practical use cases. And if they aren’t immediately apparent how you will use the Watch simply isn’t worth the investment.
Thursday, November 6, 2014
SQL Azure Database with EF 6: The connection is broken and recovery is not possible.
This week I was working on several integration tests for a line of business MVC app my company manages. Integration tests ran fine one at a time. Even two or three at a time. But when we ran all of them after 3 to 5 tests ran the database came toppling over with an error I have never seen before.
Problem
Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: The connection is broken and recovery is not possible. The client driver attempted to recover the connection one or more times and all attempts failed. Increase the value of ConnectRetryCount to increase the number of recovery attempts. ---> System.Data.SqlClient.SqlException: Database 'DBNAMEHERE' on server 'serveraddress' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx'. Login failed for user 'testadmin'.
Holy cow.
It isn't a horrible problem. We are hitting the database with a million requests on a small size VM. Of course if we send it a ton of requests in a short period it is going to fail. And this will never happen in production because there is only at most 7 people logged in to the service at once working at human speed. And if we simply rerun the test it passes. But surely it is solvable.
Solution
The solution to this problem is actually really simple. All it takes is a few lines of code. This should work in both a database first and code first approaches however, I have not tested it on a code first approach.What we have done is added a class called "ContextConfiguration."
public class ContextConfiguration : DbConfiguration { public ContextConfiguration() { SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy(1, TimeSpan.FromSeconds(30))); } }
What this class does is sets up a custom DbConfiguration. In the constructor we set the execution strategy for a new SQL Azure Strategy. The two arguments for
SqlAzureExecutionStrategy()
are the number of times to retry and the max delay time to let it retry. So based on the arguments above it will retry once at exponentially growing intervals until the 30 seconds has been exhausted.We connect this to our entity framework instance by adding the following to our
entityFramework
tag in our web.config
file.codeConfigurationType="YourNamespace.ContextConfiguration, YourAssemblyName"
Remember to replace the
YourNamespace
and YourAssemblyName
with the actual values for your project.Also note this will only work on Entity Framework 6 and above.
Wrap Up
After we published this solution I haven't experienced this error since and have been able to run all our integration tests. It seems to be a good fit for what we are trying to accomplish. If you find any flaws feel free to let me know in the comments because I would love to know.Sources:
http://msdn.microsoft.com/en-us/data/jj556606.aspx - Entity Framework Config
http://msdn.microsoft.com/en-us/data/jj680699.aspx - Code-Based Configuration
Friday, May 16, 2014
xOS Webtop and Lessons Learned
xOS Webtop is a HTML/CSS/JS based "operating system" in the browser.
xOS Webtop was the first project I worked on when I began programming about 4 and a half years ago. (December 2009) I no longer have the time to maintain this project and improve the security of the user accounts (Oh yeah, md5 passwords all the way). I am just putting the code here on GitHub to save it. You can take it. Upload it to your own server (please don't use md5).
If you do upload it to your own server, please keep in mind you will need to execute the sql files at the root of this repository in MySQL. You will then need to update your MySQL credentials in all the places you find the string "password_here". Yes I duplicated the SQL credentials in a million places. This should be easily fixable however with a simple class.
I also feel I should admit that at some point during this project I didn't know what a function was, so I wrote about 10 or so files that updated the database with a different number for a preference. Oh yes, it was the best thing ever. Even better, each file defines the server, username, and password of the MySQL database. Super smart right?
Some Lessons Learned
1. Never ever under any circumstance use MD5.
2. Use Functions. They are helpful.
3. Don't duplicate code.
4. Classes are HUGEly helpful.
5. JavaScript and AJAX are awesome.
6. PHP sucks. (But then again I don't know it that well. [Confession: I still use PHP on rare occasions, though it is much better code])
Learn from these mistakes. Especially about MD5. Don't ever ever under any circumstance use it.
xOS Webtop was the first project I worked on when I began programming about 4 and a half years ago. (December 2009) I no longer have the time to maintain this project and improve the security of the user accounts (Oh yeah, md5 passwords all the way). I am just putting the code here on GitHub to save it. You can take it. Upload it to your own server (please don't use md5).
If you do upload it to your own server, please keep in mind you will need to execute the sql files at the root of this repository in MySQL. You will then need to update your MySQL credentials in all the places you find the string "password_here". Yes I duplicated the SQL credentials in a million places. This should be easily fixable however with a simple class.
I also feel I should admit that at some point during this project I didn't know what a function was, so I wrote about 10 or so files that updated the database with a different number for a preference. Oh yes, it was the best thing ever. Even better, each file defines the server, username, and password of the MySQL database. Super smart right?
Some Lessons Learned
1. Never ever under any circumstance use MD5.
2. Use Functions. They are helpful.
3. Don't duplicate code.
4. Classes are HUGEly helpful.
5. JavaScript and AJAX are awesome.
6. PHP sucks. (But then again I don't know it that well. [Confession: I still use PHP on rare occasions, though it is much better code])
Learn from these mistakes. Especially about MD5. Don't ever ever under any circumstance use it.
Friday, January 3, 2014
Running Windows PowerShell Scripts
I saw the need to find a way to count the lines of XAML code in a certain project. In Visual Studio 2012 there is no way to count the number of lines of the XAML code. I thought it would be interesting to know this stat. After some quick research I found an answer on StackOverflow on an simple way to accomplish this using Windows PowerShell. (http://stackoverflow.com/a/1244872/2526212) And it works quite well. But it has been a few days now and today I thought to write a batch file to do this for me. Simple enough right? No.
So here is what I did step by step to solve this problem.
Step 1: Set-ExecutionPolicy
So being the person I am I just jumped right in and started doing crazy totally wrong stuff. And of course I ended up working backwards. So the first thing you need to do is set the "ExecutionPolicy" in PowerShell.
There are 4 policy levels:
1) Restricted (default, This doesn't all you to run any script file at all)
2) RemoteSigned (Allows you to run scripts you wrote yourself)
3) AllSigned (Allows you to run all scripts as long as they are signed)
4) Unrestricted (Allows every script to run)
After some consideration (not much) I choose to just use the "Unrestricted" policy. This just allows me to write the script and run it.
So to set this policy you must run PowerShell as administrator. This is required because it changes the register which isn't available unless your running as administrator. Once this is done go ahead and enter this command:
To make sure this runs successfully you can use the command:
After you run this command you should see "Unrestricted" on the screen or what ever policy you have chosen.
Step 2: Write Your PowerShell Script
Now you can write whatever PowerShell script you want. I will go ahead and just used the script I am running. What I did was simply opened up a text document and dropped in the following text:
The save this file as a ".ps1" file. This file extension is very important or else you won't be able to run the file in PowerShell. I named my file "count-xaml.ps1" and saved it to my desktop.
Step 3: Write Your Batch File
Again just open up Notepad and type the following command. Of course replace the file name on the first line with what you named you file.
Then I also just saved this to my desktop.
Step 4: Run Your Batch File
Just run your batch file and it should open right up and run. Whatever directory you choose in your .ps1 file will be looped through and all the lines in the XAML files will be counted. The more files you have the longer it will take. Pretty nifty if I say so myself.
Wrap Up
Writing PowerShell scripts is pretty simple once you figure out all the nuts and bolts. Hopefully this helps you to write some PowerShell scripts. Go ahead and rub it in your colleague's face. You know you want to.
So here is what I did step by step to solve this problem.
Step 1: Set-ExecutionPolicy
So being the person I am I just jumped right in and started doing crazy totally wrong stuff. And of course I ended up working backwards. So the first thing you need to do is set the "ExecutionPolicy" in PowerShell.
There are 4 policy levels:
1) Restricted (default, This doesn't all you to run any script file at all)
2) RemoteSigned (Allows you to run scripts you wrote yourself)
3) AllSigned (Allows you to run all scripts as long as they are signed)
4) Unrestricted (Allows every script to run)
After some consideration (not much) I choose to just use the "Unrestricted" policy. This just allows me to write the script and run it.
So to set this policy you must run PowerShell as administrator. This is required because it changes the register which isn't available unless your running as administrator. Once this is done go ahead and enter this command:
Set-ExecutionPolicy Unrestricted
To make sure this runs successfully you can use the command:
Get-ExecutionPolicy
After you run this command you should see "Unrestricted" on the screen or what ever policy you have chosen.
What PowerShell should look like after you run the "Get-ExecutionPolicy" command |
Step 2: Write Your PowerShell Script
Now you can write whatever PowerShell script you want. I will go ahead and just used the script I am running. What I did was simply opened up a text document and dropped in the following text:
cd "C:\Projects\What\Ever\Your\Path\Is" (dir -include *.xaml -recurse | select-string .).Count
The save this file as a ".ps1" file. This file extension is very important or else you won't be able to run the file in PowerShell. I named my file "count-xaml.ps1" and saved it to my desktop.
Step 3: Write Your Batch File
Again just open up Notepad and type the following command. Of course replace the file name on the first line with what you named you file.
powershell.exe -file count-xaml.ps1 PAUSE
Then I also just saved this to my desktop.
Step 4: Run Your Batch File
Just run your batch file and it should open right up and run. Whatever directory you choose in your .ps1 file will be looped through and all the lines in the XAML files will be counted. The more files you have the longer it will take. Pretty nifty if I say so myself.
After you run your batch file |
Wrap Up
Writing PowerShell scripts is pretty simple once you figure out all the nuts and bolts. Hopefully this helps you to write some PowerShell scripts. Go ahead and rub it in your colleague's face. You know you want to.
Thursday, January 2, 2014
Welcome to CodeOneNow!
Hello to you and to 2014.
Welcome to CodeOneNow! As with every year we always want to move forward. Gain more knowledge. Experience new experiences. This blog is all about those goals. My goal with this blog is to post content about programing and the software development community that I find useful, my random thoughts, random opinions and anything else I feel is beneficial or needs to be said about software development. Posts may be sporadic or frequent. They may be short or long. Funny or lame.
A little about myself. I work at a television repair company that is using software to solve complex problems and automate processes. We build and manage multiple web and desktop applications for both employees and third parties that deal with our business. I work as a software engineer at my company. I have an extreme passion for the web and you will notice I push this quite a bit. You business does write many desktop apps for in-house use.
The languages that I feel most comfortable in are HTML, JavaScript, CSS, SASS, C#, PHP. I have dabbled in other languages but none suit my needs at current. At work I use C# as my primary backend language. We used C# and WPF for all our desktop apps. On our websites we use RESTful WCF services that is called from AJAX requests in JavaScript. We manage numerous Windows and Linux based servers. We use Microsoft SQL Server on our Windows servers and mySQL on our Linux servers.
So together let's make 2014 the most successful and productive year yet. We can work together and share knowledge. I encourage comments and corrections on anything I post. Always feel free to contact me on Twitter @bdavis_brandon.
Welcome to CodeOneNow! As with every year we always want to move forward. Gain more knowledge. Experience new experiences. This blog is all about those goals. My goal with this blog is to post content about programing and the software development community that I find useful, my random thoughts, random opinions and anything else I feel is beneficial or needs to be said about software development. Posts may be sporadic or frequent. They may be short or long. Funny or lame.
A little about myself. I work at a television repair company that is using software to solve complex problems and automate processes. We build and manage multiple web and desktop applications for both employees and third parties that deal with our business. I work as a software engineer at my company. I have an extreme passion for the web and you will notice I push this quite a bit. You business does write many desktop apps for in-house use.
The languages that I feel most comfortable in are HTML, JavaScript, CSS, SASS, C#, PHP. I have dabbled in other languages but none suit my needs at current. At work I use C# as my primary backend language. We used C# and WPF for all our desktop apps. On our websites we use RESTful WCF services that is called from AJAX requests in JavaScript. We manage numerous Windows and Linux based servers. We use Microsoft SQL Server on our Windows servers and mySQL on our Linux servers.
So together let's make 2014 the most successful and productive year yet. We can work together and share knowledge. I encourage comments and corrections on anything I post. Always feel free to contact me on Twitter @bdavis_brandon.
Subscribe to:
Posts (Atom)