Thursday, March 11, 2010

Medium Difficulty Math Problem

Posted by Scott on 30. April 2009 07:54

I haven't done real math in a couple of years in college.  An haven't done true algebra for almost a decade now, but I was just confronted with a real math problem I didn't know how to do.  I actually had to read off someone else's code to figure it out and see whats going on.  I suspect others have might have this same problem so I decided to brush up on my math skills a bit and expect almost every programmer to do the same.

The problem I had is this:

I know there is a name for this problem, but it escapes me at this moment.

I have k, a static number that never changes is multiplied by 50% to 150 percent on a random basis.  The answer will be k multiplied by 50% to 150% randomly and I have to figure out what 'k' is through the answers I get.

k * .50-1.50 = 15000
k * .50-1.50 = 12000

So if I have the equation above, I have to find where 15000/(.5 - 1.5) and 12000/(.5 - 1.5) intersect. The intersection point(s) could be k. I also get the chance to add as many (answers) to the equation as possible so I can define my answer more and more if I would like.

So here is the problem.  If I do have the numbers 15000 and 12000, what is k?

Good Luck and tell me in the comments how you did it and the actual answer(s).  I will post the answer(s) on Monday.

Have Fun!

If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

Can You Teach Me to Code-Program?

Posted by Scott on 31. March 2009 05:05

Training the un-wanting is just plain hard.

Can you teach me to program/code?  I get this question a lot in my day to day life.  I have fallen for it almost 100% of the time and in total, about 10 times in the past two years. Friends ask me if I can teach them how to program.  Other Friends want to create nifty little applications and need to know how to start.  Then there are those that wish they knew, but don't know where to start.  Every time I tell people I am a full time developer, I tend to get the question.  The problem here is not that I get the question, its that 99% of the time I say yes.  I actually don't really remember the last time I said no.

The United States along with other countries such as South Korea, India, Parts of China, Australia and Parts of England are now fast becoming post industrial countries.  They are losing their manufacturing expertise and moving to more of an intellectual work environment.  In this work environment, most people sit on their butts all day in front of a computer and get something done.  In a work where the computer rules the office space, people want to manipulate their computers more and more.  They want to figure out how to change information and manipulate the way things work. So because of this post industrial revolution, people want to learn how to program.  Take for example, MySpace.  You have to know how to develop for the web in order for you to make your page more personal.  Its becoming more and more mainstream to hack a bit at code.  It used to be the things that nerds do and now every kid on myspace.com has coded a little bit.

 


Photo by Wonderlane

 

I have one friend who wanted to create a small application for user management of their organization (I ended up doing most of their work).  I have another friend who wanted to learn how to create online games for Myspace.  I sat down with him for a couple of hours and banged out some code.  For the next week, he experimented a lot.  Then he just fell off and I no longer heard him talk about code.  I just had another friend who knew a bit of C and C++ in which she asked me if I can teach her to code.  I said yes for the plain fact that its hard to say no.  I learned to say no a while back and people tend to confuse me with someone as selfish or self absorbed.  I usually let it go as that for the short answer.  The long answer for those closer to me is I almost always said yes to things and became overwhelmed with things to do.  It happens to everyone that says yes too much, so I had to learn to be a bit more selfish or people would just step all over you.

So, how do I make sure that the people I teach are actually going to continue doing it?  This is a question I ask my self a lot and still don't have an answer for.  For every person I taught; I have tried to seduce them to being my partner in crime but it just doesn't seem to happen.  I still don't know how to keep these people working on code.  To keep developing, to keep moving and firing.  The point is, I need to start saying no to these folks as well or I need to bind them to a contract that says we are going to build this together and this will be how you learn to code.  By helping me build this application, I will teach you how to code.

Thanks for listening.

If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

How to Create a Threaded Comment System with ASP.NET

Posted by Scott on 4. February 2009 05:49

A few days ago I was designing a threaded comment system for Drinkingfor.com which allows users to reply back to other users directly instead of a flat comment system like you see at most other places.  I made my argument for threaded comments over here and why they should be used.  I didn't know where to start or how to write the code.  I had a pretty good idea on database design which was decently simple.  Each comment shall have an owner comment.  The treeview is the best example of what the data in the database should look like.  As for how to display this out to code is another problem.  I ended up searching on the internet and found a man who created hierarchy class which is exactly what I needed.  The Hierarchy class selects the information from the database and organizes it into a cached treeview.  I ended up talking to him and he had explained to me that he was refactoring the class which will allow it to run faster.  As for how I implemented the code to write out HTML, I ran through the hierarchy class recursively and then created html for each node found.  The class was quite impressive and I included some sample code below.  I didn't want something like this to be wasted and hope everyone can put it to good use.


Photo by jurvetson

I also wanted to give a shout out to Stefan Cruysberghs and say thank you for creating this class and posting it up on the net.  Now to keep with the current standard, I will post up my execution of his code.

ThreadedComments.cs (5.98 kb)


If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

To Thread or Not To Thread Comments

Posted by Scott on 15. January 2009 05:24

With building a Social Site you always have to weigh the needs to have interaction with the site.  The current standard for any interaction is the comments section of the sites. The comment section is the talk back, the conversation to the site.  It is what allows for user participation and what most people would declare what Web 2.0 really is.  It allows the comment section to enable user interaction.  In building a site that would be used as a somewhat social site, you have to ask your self do you want to see a conversation another one sided page that has no interaction.  Would you rather get user feedback or just be one sided in everything you write or have to say.  You can't get feedback to see if they enjoy what your posting. You won't get a conversation going which inevitably makes the user want to come back to the site. The fact is, we need comments in the internet, we need conversation.

So in building a site, you have to worry about if you want it to be web 2.0 or web 1.0.  Comments in general are becoming standard on any site out there.  It is on all major social sites and it allows for more interaction between the users.  I don't see any problems with comments.  But I would like to start calling it something different.  A Conversation.  I call it a conversation today because more and more people are commenting.  More and more people are clicking that button to get a notification on what people say.  When you comment you save a part of your self on that site.

The Point

Comments are good, but threaded comments are better.  We are trying to build an online world.  We are trying to create a conversation that any person of any race of any creed and color can voice their ideas on.  Comments allow for anonymous participation in the world of tomorrow.  Free Speech.  Governments ban it and people are killed over what they say, but on the internet, you have all the free speech you want.  To create a conversation, you have to allow talk backs, you have to allow the user to reply to any other user.  You have to make sure a conversation can be had with any other user on the Web 2.0 site.  So in developing my site, I chose to use threaded comments as the default. Flat Comments can be chosen if they want to see flat comments.  Some people just can't handle threaded comments.  But if you think about it, Flat comments can also be threaded.

Just think of when someone posts:

@John,
Your Wrong!

@Tim,
I don't care what you have to say, threaded is better.

A conversation is happening right here if you like it or not. Threaded comments are at least for now the way of the future.  Someone else will invent a better way to have a conversation over a website, but for now threaded is my default and it should be yours too! Help carry on the conversation of the world and thread your comments.

Ask the Readers: What do you think, should threaded comments be a default?

Shameless Plug: DrinkingFor, it is still in Beta.

kick it on DotNetKicks.com

If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

Finish the UnFinished

Posted by Scott on 16. December 2008 18:50

Two things rob people of their peace of mind : work unfinished and work not yet begun.” - anonymous
 

This is not a story of work unfinished, but of work finished.  Life and work throws us into many different projects and work.  We as a society are getting better and faster at finishing tasks we once could not accomplish.  I had a customer come to me and describe to me that they wanted a "chat" application plugged into their current application.  They decided that it was too hard to talk over the phone and would rather type it down and hit enter only to receive a response moments later by the person on the other end.  The chat app had to be web based and had to be produced in the current language of the application in which is was being plugged into.  The language was ASP.NET.  I decided to try the easy route and looked all over the web for some type of chat app.  I found one which was nice, but was purely javascript.  I wanted one built in ASP.NET.  

In the end of this process, I realized there was nothing built in ASP.NET which came as close as to what they wanted me to build.  So, I started from scratch building it up and after about 2 weeks worth of work I got a working demo completed.  I then called up my customer to demo this thing out and they liked it a lot.  But they said there was one small problem.  They only needed to talk to me through it.  They didn't want to talk to anyone, but me.  So here I am with a working buddy list, Icons, Profile content, working group chat and singular chat.  I was frustrated.  It was a demo and not completely done, so I stepped back for a moment and reflected.  I said to my self, "If I don't finish this up now, it will be another thing I just haven't finished".  I was right because it would have turned into that.  It would have just turned into another app that was put out somewhere on some computer. It would have never seen the light of day and I would not have had a peace of mind.  So I decided not to bill the customer for what I had completed.  I built a small little chat "back and forth" messenger for the customer and me.  I then separated the main application and finished the chat application on my own time.  I was extremely happy with this accomplishment and decided that since I was unable to find a chat application built in ASP.NET, I wanted to release it to the world.  So in the coming days I will be posting the chat application on my blog.  Stay tuned.  It is impressive.

Now, as for the moral of the story:  Finish your work.  Bring it to completion.  If you just let it sit there it will collect dust.  It will be time not well spent in which you just lost a small bit of your life to something that you didn't get finished. Go host your project on codeplex and just maybe it would be found by some agile developer a few years from now.  The developer will decide to implement your code and make a much better application built off what you started.  If anything, just finish your work and you will start to have a peace of mind.  I know I do.


If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

Life is like Code, you never know what you will create next

Posted by Scott on 10. December 2008 04:21

Appreciate the Beauty – Code can be amazingly beautiful.  It can be written in five lines to express what could also be written in 20 lines.  When I write beautiful code, I will often take a moment to step back and realize what I have just done.  You need to do this in life as well.  When you complete something that took a long time, step back and appreciate your time spent.

Be In the Now – I have always enjoyed coding. I could "get in a zone" and wouldn’t miss a bracket or a semi-colon.  In software development, you need to be in the now.  You need to hack away at the code until you get it just right. In life, you need to also figure out how to be in the “now”.  You need to live in the present.

Be Honest – Don’t mess around, be truthful to those you work for.  Coding is an art, be honest in how you code and what you code.  Take shortcuts, but don’t infringe on patents.  You will lead a much more satisfying life if you were just an honest person.

Plan ahead – Good programmers don’t just start coding.  Think about what you do before you do it.  Good coders make sure they have a game plan before they start writing.  Even if you’re an extreme programmer, think about what you do, before you do it.  In life, you need to ask, "Are the actions your taking now going to work well in the future?"

hello 
Picture taken by Amagill

Narrow Your Focus – Code is completed in functions.  Something goes into the box and something different comes out of the box.  You need to narrow your focus so you write the best functions possible to make you code complete the first time around on that particular function.  You need to apply that same level of attention and narrowness of focus to your everyday activities. You could get a lot more done if you jumped into one task or function a time and got that function done and then moved on.

Keep Your Eye On the Ball – To make great code, you have to know what’s at the end of the code.  You need to make sure it works well with everything.  If you’re an extreme programmer, make sure your correct in all your goals for the next release. It’s the same in life.  If I find that I’m not making the progress I want toward my goals, it is usually because I’ve let myself get "busy".

Mind Your Manners – Coders will tolerate a lot from a newbie.  They will help him along and make sure he doesn’t screw up, but most coders really don’t appreciate poor etiquette.  You should approach everyone in the world that way.  Peace on earth is easy if you just gave a bit more common courtesy.

The More You Do It, The Better You’ll Be- "Practice makes perfect" is the mantra every coder should follow.  Keep working and you will write better code than before.  I look back on old code I wrote and see a vast improvement than what I was doing 2 years ago.  How much richer would you be if you practiced better communication, compassion, and empathy?

Leave the Code Better then You Found It – I learned this in Boy scouts very early on.  It’s the same with code.  If you do a refactor, leave it in better condition than you made it.  Write better code than the lines you wrote before.  Make it do greater things.  You would be a much better friend and person if you made a concentrated effort to leave everything and everyone better than you found them.

kick it on DotNetKicks.com

If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

Why get bored, when you could be coding!

Posted by Scott on 23. November 2008 20:01

There are many times in life when you have nothing to do.  As a member of the civilized world, we as a people are becoming bored every day. We are a world that watches more movies everyday.  I bet if the movie industry came out, we would see the statistics of movie goers have increased over the last 20 years.  We are a world that technology has allowed to do many things that have taken us hours or even days to do before.  Our world is speeding up and everyone wants more.  They want to get done faster, finish things better and move on to the next project.  People get bored easily these days because production levels have gone through the roof with the help of technology which allows us to become lazier.  Life in it self is full of its bored moments.  People in general have less and less to do because technology has sped up our daily tasks.  I think that is one reason why more and more movies are being watched.  People want more out of life and movies give you that little action and adventure that your looking for. Movies give you the ability to stop boredom.  To some people, movies are a way of life. 

My life is no different, technology has made my life so much easier than people that have come before me.  My solution of boredom?  People need to find a hobby.  They need to find something that will keep their attention.  If they don't they will inevitably become a YouTuber.

YouTuber -A person that watches excessive amounts of YouTube to pass the time.  Not only applied to YouTube, but a person that does an excessive amount of anything to which they do just to pass the time.  This isn't a hobby, but a time waster.  

People that watch and enjoy YouTube to me are either doing it because that is their hobby or they are doing it to pass the time.  I personally code as my hobby or down time.  I not only do it as a hobby, but to make my life and everyone else's life a bit easier and a bit better.  I am like every other programmer or hacker the does it. I chip away at making life better.  I don't think I will ever be as rich as Bill Gates, but I hope to have helped as many people in my life as he has.  This is where coding/hacking comes in. When I get bored I code; when I want to do something, I code.  Due to technology, I get to do a lot of my hobby. 

If this is your first time reading, then you wouldn't know that I usually try to have around 2-4 projects going on at once.  My projects are all for making life a bit easier for me and everyone that has access to a computer and internet.  I have about 15 ideas that could be implemented currently and boredom brings my code to life.  Like I said before, I don't get bored, I code.  Right now I am even sitting with friends and watching some football.  I can keep a conversation, watch football and blog all at once.  When I get bored, I code (so I am not coding, but being productive).  

The point I was trying to get across: Stop being bored, be productive.  Find a hobby, find something.  Carpe Diem (Seize the day).  Learn something, do something and retain it. When I get bored, I code.  Life is not about being bored.  Life is about doing something.  Its about achieving something better than your self.  My something better right now in my life is coding and my great girlfriend. 

If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

In programming, clever != smart.

Posted by Scott on 10. November 2008 21:52

You ever have one of those days where you think you are the smartest man in the world and the best programmer at your place of work?  Then some clever kid comes along and does something that speeds up your code by a few seconds/minutes?  Ease your self.  Just because that person just solved your problem, doesn't mean they are smart.

"In programming, clever != smart." - anonymous


You work all day on a certain project, take a step back and look at it.  Its some of the beautiful code you just created, but you are hung up on this little issue.  Along comes some programmer and they solve it for you. When I was in high school or middle school and I was getting off the bus.  One day I heard one of my bus drivers say to a girl.

"You might be book smart, but your not street smart" - anonymous 

I tend to think that I am about in the middle of this quote.  I tend to think I am both book and street smart.  I imagine most people do.  Book smart programmers tend to be better at writing code then their street smart counter part.

The book smart programmer (smart):

  1. tended to focus more in school on classes including algorithms.
  2. tended to have less of a social life due to studying more or less depending on how fast they got solutions to projects.
  3. tended to be either inside playing video games or working on a cool project that could solve the way USB drives communicated to computers.
  4. tended to have soda cans and candy around while staying up late around his computer.
  5. tended to get better grades.


The street smart programmer (clever):

  1. tended to focus a bit more on going out and socializing.
  2. tended to focus a bit more on girls.
  3. tended to copy and paste code.
  4. tended to join a social organization.
  5. tended to have a bit more fun in the activities they thought up.
  6. tended to get a little lower grades.


This reminds me of the movie "Real Genius". Where Chris seems to have both of these types of people tackled.  He sees Mitch and he sees the old him.  The book smart programmer(laser tech).  Mitch is stuck with trying to do the best in college that he can. Then one day, Chris gives Mitch a little lesson. He lets Mitch know that college and life can't just be all books.  It has to be books and fun.  It has to be smart and clever. Sure clever != smart, but wouldn't it be good to be both? Wouldn't it be satisfying to be Chris and let Mitch slack off a bit.  They are both geniuses.

I went to college for four years, I did my fair share of partying and I didn't graduate with the best GPA.  For a Computer Engineer, it is a pretty shameful GPA.  Though I got a real job before even graduating.  I had done some work on the side while still in school.  I got an intern with my college Fraternity. This advanced my ability to show my future employer I can have a real job and keep it.  I am not saying stop all your studies now, but live life.

Programmers need to both be smart and clever. Not just smart and not just clever.  If you want to tackle the real issues, you can't keep writing code all day and every day.  You need to just step out and have some fun.

"Don't let Life pass you by..." - Scott

I am not trying to be a philosopher, but what I am saying is find your true happiness in life.  Be smart and clever.  Don't get stuck on always trying to be the best or smartest, but make sure you Get the Job Done at the same time.

P.S. I always tend to start on one subject and completely finish with another by the end of the post.  This one is no different. hah.

kick it on DotNetKicks.com

If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

Whats up with Stored Procedures these days?

Posted by Scott on 20. October 2008 16:22

When life throws you hard balls, you can either step back and take a swing or bunt the hell out of it.  I just recently went to an information session on T-SQL, Stored Procedures and now LINQ.  These folks discussed stored procedures and why they are so important in the world today.

 

They stated ideas such as:

  1. Stored Procedures optimize queries.
  2. They stop SQL Injection attacks.
  3. Stored procedures are concrete and cannot be changed.
 
I wanted to briefly state a counter argument against stored procedures and for T-SQL and LINQ:
 
  1. Stored procedures do not optimize queries.
    • A SP is not an optimized query, it does not save time.  SP’s used to save time and have been faster in the past, but more and more RAD development has been done without SP’s.  The development has caught up with SP’s and dynamic SQL has now caught up  and in some cases surpassed SP’s.  These days parameterized queries are now cached just like SP’swhich put them on an even playing field.
    • Microsoft LINQ and ADO teams both admit that SP’s are not faster than dynamic SQL.
    • Benchmarks have also been completed which explicitly show SP's are slower over small queries and tie dynamic queries over larger ones.
  2. Stored procedures do stop injection attacks, but you can also do it with parameterized queries. 
    • SP’s are good at this, but it can also be done with parameters.  Putting a value into a parameter means that it will not be a part SQL query string at all.
  3. Stored procedures are very concrete and are hard to change as a developer with a DBA.  This is the problem.
    • As a developer when you push a product out the door, you want to be fast at this.  Developers don’t want to learn two languages in order for their product to be pushed out the door and then go back to the database every time code needs to be changed.  They want dynamic abilities.  When SP’s are hard to change, it might be a bit harder and take longer when you have a DBA.  The inability for SP’s to be changed or created fast is the issue with this kind of development.
  4. SP’s mangle the three tier architecture designed for apps.
    • Instead of having a structure which separates logic from storage, you have storage and logic on the same tier.  This will cause potential problems down the road.
  5. Business logic in a SP does not scale.  Business logic should be in code and not in the storage center.
    • When you have multiple database servers, it is more difficult to keep the triggers and SP’s synced.
  6. There is no Version Control for SP’s.
    • In a place that can be disastrous if you screw up, it should have something.  This is one big reason why people like to avoid SP’s like the plague.  They run away and never move back into town.
 
If you see the new technologies coming out of Microsoft now, there will be no need for SP’s in the future.  LINQ is taking care of most of this by allowing for a data layer cheaply and efficiently with very little effort by the developer. LINQ handles all these problems and if you truly like a confirmation on all the things I said, just search the internet for Stored Procedures v.s. Dynamic SQL.
 
The debate these days has two sides. Not “Republican or Democrat”, but “Progressive and Non-Progressive”.  The Progressive folks are not using Stored Procedures these days.
 
kick it on DotNetKicks.com
If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark

FizzBuzz => BizzBuzz. Can you actually code?

Posted by Scott on 6. May 2008 18:46

42-16920498

Have you ever been in an interview where they asked you to write code in front of them?  Well I haven't, being so young and so fresh in the developer world.  My Interview went along the lines of:

  1. Have you ever worked on CSS, HTML, ASP.NET and SQL?
    1. Yes I have, as of 2008 I have over 9 years experience with this stuff except for only 1.5 years with ASP.NET.
  2. What are your favorite hobbies.
    1. Fun, Fraternity, my Girlfriend and of course all my software projects that I have going on.
  3. Having them critique me if I will actually fit in with the group.

I have never been asked if I can FizzBuzz.

FizzBuzz - To write a program that prints numbers 1-100.  For multiples of 3, print Fizz, for multiples of 5, print Buzz.  For numbers which are multiples of 3 and 5, print FizzBuzz.

It deals with Modules, hope I spelled that right.  Can you do it?  Leave your code in the comments section, I would like to see your answers to this little problem.

FizzBuzz, the phrase is over used all over the Internet.  It is used by multiple programmers and made popular by www.codinghorror.com which covered the FizzBuzz Dilemma here.

Why am I writing this?  I want to start a movement that doesn't use the word FizzBuzz anymore.  I want to use the phrase BizzBuzz. In my college life, I was a pretty big drinker and well we did play a few games that involved a table a die.  It was called Beer Die.  I suggest you look it up and think on it.  It is pretty fun for those people at the main table, but boring to the people that stand around the table. It was a fantastic game.  Like every drinking game, there were key words that couldn't be said. The words are Bizz and Buzz.  Bizz stood for 5 and Buzz stood for 7.  If you said either of these words, you finished a beer.  So lets start this movement!

BizzBuzz - To write a program that prints numbers 1-100.  But unlike FizzBuzz, For multiples of 5, print bizz.  For multiples of 7, print buzz. For multiples of 5 and 7, print BizzBuzz.

Why? well because FizzBuzz has become to popular and BizzBuzz has some history to it.  So lets start a cult following for BizzBuzz just like the following Beer has.

Thanks for listening. kick it on DotNetKicks.com


If you liked this post, please be sure to subscribe to my RSS Feed.

Share/Save/Bookmark