2013-05-06

CodeSOD: The Apex of T-SQL

Thomas has some problems around the office. Specifically, the code he supports has all sorts of different ways to generate HTML. Rarely, it’s WebForms code living in as ASPX. Far more often, it’s hard-coded into the CodeBehind. Sometimes, it’s sitting in a resource file.


And then sometimes, it sits in a stored procedure like this:



ALTER Procedure [dbo].[proc_GetCurrentOrderStatus] @OrderId as Int,@MyVar varchar(2000),@LangId int,
@Groupname varchar(10)
As
Declare @temp0 Table (
historyid int IDENTITY (1, 1) NOT NULL,
historytext nvarchar(1000) )


Declare @temp1 Table (
errid int IDENTITY (1, 1) NOT NULL,
errtext nvarchar(4000) )

Declare err_split Cursor for Select * from dbo.split(@MyVar,',')
open err_split
declare @langText as varchar(2000)
Fetch Next From err_split into @langText
While @@fetch_status=0
Begin
insert into @temp1 values(@langText)
Fetch Next From err_split into @langText
End
close err_split
deallocate err_split

For those following along at home, this first block loads a series of language names from the clearly named @MyVar variable. With that cursor out of the way, we need to open a fresh one. It’s called History-cursor , and it’s populated from a basic SELECT statement. It’s after fetching the first record that things get interesting.



Fetch Next From History_cursor Into /* Snip */ @Lots, @Of, @Variables, @Here
set @tablestr = '<table border = "0" class="texbox" cellspacing= "0" cellpadding = "5">'
insert into @temp0 values(@tablestr)

Yes, that is hard-coded HTML dumped into a string variable and then dumped into a table variable. You’ll see a lot of that.



set @tablestr=''
While @@FETCH_STATUS=0
Begin
If @Groupname='Cust'
Begin
If @Status_Code = 'Cn'
Begin
set @tablestr = @tablestr + '<tr class = "textbox" >'
set @tablestr = @tablestr + '<td nowrap ="nowrap" width = "250px" >Statut actuel de votre commande: </td>'
set @tablestr = @tablestr + '<td nowrap ="nowrap" ><img src = ''' + @Status_Color
+ ''' width = "15px" height="15px" alt="album" />&nbsp; ' +
(select errtext from @temp1 where errid=21) + ' </td>'
set @tablestr = @tablestr + '</tr>'
Break
End

At this point, you might say, "Oh, I see how this works, this If repeats itself, almost identically, and the only variation is the errid used in the sub-query.


But no. Depending on the condition, you might see something like this:



If @Status_Code= 'Cn'
Begin
set @tablestr = @tablestr + '<tr class = "texbox" >'
set @tablestr = @tablestr + '<td nowrap ="nowrap" width = "180px" >Statut actuel de votre commande: </td>'
set @tablestr = @tablestr + '<td nowrap ="nowrap" ><img src = ''' + @Status_Color
+ ''' width = "15px" height="15px" alt="album" />&nbsp; ' + @status_name + ' ' + @Name + ' </td>'
set @tablestr = @tablestr + '</tr>'
End

Or perhaps, this:



If @VoucherID <> 0 And @Status_Code = 'N'
Begin
set @tablestr = @tablestr + '<tr class = "textbox">'
set @tablestr = @tablestr + '<td nowrap ="nowrap" width = "180px" >Statut actuel de votre commande: </td>'
set @tablestr = @tablestr + '<td nowrap ="nowrap" ><img src = ''' + @Status_Color
+ '''width = "15px" height="15px" alt="album" />&nbsp;' + @Status_Name + ' '
+ @OrderNumber + ' ' + @Name + '</td>'
set @tablestr = @tablestr + '</tr>'
End

So similar, yet so different. This block is hundreds of lines long, and each condition does something subtly different from each other block.


Someone read that doing too much concatenation must be bad, so at the bottom of the loop, we have this simple step:



insert into @temp0 values(@tablestr)
set @tablestr=''

After the loop closes and the cursors are deallocated, the rancid icing on this SQL-HTML cake:



set @tablestr = @tablestr + '</table>'
insert into @temp0 values(@tablestr)
set @tablestr=''
Select * from @temp0 order by historyid

At least we can take solace in the fact that this is a small product from Thomas’s company. No one would build a large-scale product completely dedicated to generating HTML from database stored procedures, right?



[Advertisement] Make your team a DevOps team with BuildMaster . Pairing an easy-to-use web UI with a free base platform, BuildMaster gets you started in minutes. See how Allrecipes.com and others use BuildMaster to automate their software delivery.








via The Daily WTF http://thedailywtf.com/Articles/The-Apex-of-TSQL.aspx

2013-05-04

Bad Day? 8 Ways to Feel Better About Yourself



If trying to think yourself into a better mood fails, try doing something instead. Here are eight ideas.


Some people claim the way you talk to yourself is the key to how you feel.


Try it. Pump your first in the air and repeat after me: "I feel great about myself!"


How did that work out for you?


Positive self-talk can be helpful at times, but more often than not those mental conversations veer off course because it's too easy to be your own worst critic.


That's why feeling great about yourself isn't about talking; it's about doing. Try doing one of these eight things:


Ask for help.


I know: You probably don't equate feeling vulnerable with feeling happier with yourself.


Asking for help actually does several things: It shows you respect the person you ask; it shows you trust the person you ask; and it shows you're willing to admit a weakness or lack of knowledge and skill.


Asking for help isn't a sign of weakness. It's a sign of strength, because it shows you're secure enough to admit you need help.


Try it. Ask for help. You'll make other people feel better about themselves--which is reason enough, because that will automatically make you feel better. And you'll also feel better about yourself because you felt strong enough to ask.


Do something nice that no one will notice.


If the true test of character is what you do when no one else is looking, one of the best ways to feel better about yourself is to do something nice when no one else is looking.


Then you're not doing it for praise or recognition but simply because you think it's the right thing to do--and when we do the right thing we always feel better about ourselves. (Even if doing the right thing is really, really hard.)


I like to put grocery items back on the shelf that have fallen on the floor or shopping carts that have escaped the cart corrals and wandered off into the parking lot or clothes that have fallen off a rack. I know it's someone's job to do it, but if I'm standing right there, why not me? It makes me feel like I'm helping someone.


That always feels good.


Fail, so you can keep getting better.


Failing, even at something simple and inconsequential, is demoralizing. So how can you feel better about yourself by doing something when you know you'll fail?


Example: Years ago I could do three sets of 20 dips with (relative) ease. I stopped working out for a long time. Years later I started going to the gym again and tried to do some dips.


I did four. Woo-hoo.


But two weeks later I could do three sets of 8. A few weeks after that I was doing three sets of 12. Within a few months I was doing 20, 16, and 14.


And here's the cool part: Every time I did just one more than the last time, I felt awesome. I was getting stronger. I was improving.


Pick something you can't do well. (Consider picking something physical since you'll get the added bonus of improved fitness and health.) Then do it.


You'll fail. So what. Keep doing it. You'll get better.


And every time--every time--you make an incremental improvement you'll feel better about yourself.


Say you're sorry.


Because not saying you're sorry creates a weight that slowly crushes your self-esteem.


Recapture that "first" feeling.


When something good happens you feel happier.


For a while. Then you adapt. You revise your expectations upwards. And then you're not as happy.


Think about a day when you felt excited and happy. Maybe it's the day you truly fell for your significant other. Or maybe it's the day you started your business. Life was filled with promise and hope and anticipation.


It still is.


Sit at the table, watch your significant other putter around the kitchen, and picture that first day. Or step outside where you work and picture that first day. Remember how you felt. Your significant other is still just as wonderful. Your business is still capable of reaching incredible heights.


Nothing has really changed except maybe you--and your expectations.


What you already have is wonderful. Bask in that thought. You'll feel better about yourself and you'll be inspired to make things even better.


Go out of your way to meet cool people.


I'm lucky enough to get to meet some extremely accomplished people. Sometimes I find myself in a group and it can seem like a game of "Which item doesn't belong in this picture?" and the totally-out-of-place item is me.


That doesn't feel so great.


But when you meet cool people and pay close attention you'll notice something interesting. For the most part, they're just like you: They share some of the same fears, insecurities, failings, etc. They don't live a charmed life.


You realize they're just regular people who have worked really hard to become great at what they do. And you have a lot more in common with them than you think.


Compliment someone who doesn't expect it.


If giving flowers "just because" carries more emotional weight than giving flowers on a holiday, giving a compliment to someone who doesn't expect it carries more emotional weight, too, both for the person you compliment and for you.


Tell a fellow business owner you love how she's decorated her store. Email an author to say you love his book. Walk over and tell your neighbors with whom you never speak (if you're like me you have plenty of neighbor-stranger options) their flowers are beautiful.


Every day the people around you do good things. Compliment them, even if it's not your job or your "place" to do so.


They'll love it--and you will love how that feels.


Step back into the shadows.


It's your time to shine. You're about to receive recognition and praise. Won't that feel awesome? Maybe... for a minute or two.


Try this instead: Shift the spotlight onto someone else. Let an employee take credit. Let someone else lead the project. Let another person take credit for your idea.


When you seek acclaim or affirmation from others, the feeling is fleeting at best. When you can step back, secure in the knowledge of what you've done, that's a sure sign you feel great about yourself--and that those feelings will last.


Share the spotlight. Better yet, avoid the spotlight. Even if people don't know what you did, you will.


And that's all that matters.






via Articles from Inc.com by Jeff Haden http://www.inc.com/jeff-haden/bad-day-8-ways-to-feel-better-about-yourself.html

2013-04-27

Gumroad


Gumroad is an easy way to add a micro-payment function to your blog, website, Facebook page, or Twitter — anywhere you can post a link. It allows you to quickly offer digital products — photos, videos, music, apps, PDFs — for small (or large) prices. It is not a marketplace, rather it generates a link that you post so that you can “sell where you share.” When a friend, fan, or follower purchases something off of your page, they get an email with a link for the download from Gumroad’s server. You can set your price anywhere from 0 and up. Gumroad’s cut is 5% + 25 cents per transaction, no setup or monthly fees. That’s a good deal if you are selling things for a few dollars, and better than other digital storefronts. Something priced as low as 99 cents means you get $.69 and Gumroad gets $.30.


For the past year I’ve been using Gumroad to sell a PDF version of my True Films guide to documentary movies for $.99 and the system works great.


-- KK


Gumroad







via Cool Tools http://kk.org/cooltools/archives/11645?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+CoolTools+%28Cool+Tools%29

2013-04-15

April 12, 2013



If you've been waiting to buy BAH tickets, wait no more. They will likely sell out in another day or two.



via Saturday Morning Breakfast Cereal (updated daily) http://www.smbc-comics.com/index.php?db=comics&id=2944&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+smbc-comics%2FPvLb+%28Saturday+Morning+Breakfast+Cereal+%28updated+daily%29%29

2013-04-10

Tiny backyard pod for shedworking in Medieval English town

Lawyer Nicolas Oldham and his wife moved to the historic English village of Berkhamsted for the good schools for their children, but their jobs are still in London. To avoid the commute when possible, a few years ago Oldham began working from home a couple of days a week. At first he used the edge of the sofa as his office, but stepping on his kids toys and never being able to find a pen, was less than ideal.



A longtime fan of tiny shelters- in his backyard he has a shed, a greenhouse and a life-sized dollhouse-, Oldham decided to add an office pod. Though unlike his other humble shacks, he bought a ready-made Archipod that Treehugger's Lloyd Alter calls "a beautiful shed in a dome" and "more of a land yacht than a shed".



Like his shedworking compatriots Roald Dahl and Virginia Wolff, Oldham uses his small shelter to find the isolation he needs to work.



More info on original story: http://faircompanies.com/videos/view/tiny-backyard-pod-for-shedworking-in-medieval-english-town/



Archipod: http://www.archipod.com/en-gb/index.php



Nicolas Oldham: http://www.mills-reeve.com/nicolas-oldham/



via Uploads by kirstendirksen http://www.youtube.com/watch?v=pZS4o9wBnlI&feature=youtube_gdata

2013-04-02

Coat’s Portable Hugs Make You Feel Loved Wherever You Go


A hug is an almost universally loved gesture that can instantly convey comfort – but what do you do when you’re miles away from everyone you care to hug? This jacket, designed by Si Chan as part of a final project at the London College of Fashion, doles out constant surrogate hugs to keep you feeling warm and fuzzy.



The Hug Me Jacket features five sets of arms and hands encircling the wearer. Over the coat’s zipper, the hands join up in the front and appear to be holding one another in a gesture of friendship or love.



Can a coat like this really help to stave off loneliness when you’re away from those you care about? Maybe, maybe not…but it is a fashion statement that will not go unnoticed, no matter how many caring people are around you.





Keep Going - Check out this Great Related Dornob Article:








Sleeping Bag Coats: Makeshift Wearable Homeless Shelters








Structural Ingenuity: Hand-Crafted Bio-Geometric Menswear
















via Dornob http://dornob.com/coats-portable-hugs-make-you-feel-loved-wherever-you-go/

2013-03-30

Learning JavaScript - my experience and advice


Since I've mentioned a few times that I just learned JavaScript over the last few months, a bunch of people have emailed to ask what I used and recommend to learn it. So here's my experience and best advice for 2013.


NOTE: I wanted to really learn JavaScript - not shortcuts, quick tricks, or meta-tools that keep me from having to learn JavaScript. I want to learn it, get it, read it, understand it, and memorize it, so that I can understand all the other cool things written in JavaScript for years to come.


First - a bunch of people will tell you to get JavaScript: The Good Parts - by Douglas Crockford. But when I started reading it, it was so dense and succinct that I had no idea what it was talking about!


You know when an expert is talking about their field, and don't know how to simplify it for just anyone? Well, this book felt like it'd be perfect for someone who's been programming for 20 years in C, Java, and C++, and just needs a quick overview of what they should know about JavaScript.


But it doesn't really TEACH you. It doesn't guide you through anything. So I recommend skipping it.


Instead, start with Eloquent JavaScript - by Marijn Haverbeke.


It starts so simple, so easy, almost too simple, but this is encouraging. You get your swagger back as you say, “This is easy!”


Do the online version, here, because you can test and experiment directly in your browser.


Then, after a few chapters of that, switch over to Professional JavaScript for Web Developers, 3rd Edition - by Nicholas Zakas.


THAT is the ultimate tutorial. It takes the time to explain everything thoroughly, and it covers pretty much everything. Put aside a few hours per chapter, and by the time you're done with this one book, you'll know as much as most people who call themselves JavaScript programmers.


Funny thing is, I went back to JavaScript: The Good Parts after finishing this one, and now I understood it. But because Professional JavaScript for Web Developers was so thorough, it had already covered all of the “good parts”, too.


Of course you have to retain what you're learning, so I highly recommend you write down every new thing you learn, ideally into a flashcard program, like this. It's a lot to take in, so you'll have to remind yourself of what you've learned in the weeks and months afterwards.


If you're in the mood for more books to really solidify JavaScript in your head, go through:

All of these are great, and you'll notice you go through them much faster now that you're fluent. Do the examples. Play around.


Read some real-world JavaScript code


After a thousand pages of tiny example code snippets, you'll love looking at the code to two very popular and powerful JavaScript projects:



  1. Underscore.js

  2. Backbone.js


You'll notice that it all makes sense, now. You're now functionally fluent in reading and understanding JavaScript.


Then jQuery, and more...


jQuery is absolutely everywhere, and you must learn it, for your JavaScript tutorial to be complete.


Now that you've learned the plain-JavaScript long and verbose way of doing things, you'll appreciate the shortcuts that jQuery provides.


I really liked Head First jQuery, as goofy as it is. It walks you through jQuery wonderfully well, and has you apply what you've learned, as you go.


And if you're still hungry to learn more JavaScript, dive into:



Then put down the books and go use it!


You would think this goes without saying, but if I didn't say it, someone would complain. So look at your existing sites, and go apply what you've learned. Or start a new site from scratch and make it all with JavaScript, even if just as an experiment.


Any other suggestions? What worked for you?







via Derek Sivers http://sivers.org/learn-js

2013-03-05

Cubism, Cubed: Green Tendrils Wrap Through White Kitchen


“Glamorous”, “spectacular” and “surrealism” are some descriptors offered by the Bulgarian designers of this this electrified room design.



Practicality takes a back seat to formal experimentation and cubist expressionism – shelves, cabinets and racks are fit into the carved-up walls almost as an afterthought.



As a bonus, there is almost no way for this room to look messy – it is chaotic by design, which is a good fit for at least certain cooking styles.



Gememilli Design Studio takes a similarly colorful and angular approach to other interior designs as well, including and beyond some of the examples shown above.





Keep Going - Check out this Great Related Dornob Article:








Modern Kitchen Design: All-in-One Cooking Island Idea








Contemporary Kitchen: Simple Modern Black & White Design
















via Dornob http://dornob.com/cubism-cubed-green-tendrils-wrap-animate-white-kitchen/

2013-03-04

Oreo-creme hater builds Rube Goldberg CNC router to remove the Stuf

oreo-separator


Look, we understand the need to find a project to occupy your time and interest. So we’re not going to ask the wrong question (why?) for this one. This guy hates the creme that connects the chocolate cookies to make an Oreo. So he built a complicated system to separate the cookies and remove the creme. Check out the video after the break for a hardware overview (where we catch a glimpse of an Arduino RBBB) and a complete demonstration.


Although the project is a marketing gimmick for the company, we really love the fun they had making the video and the device actually works! Drop a cookie in the chute and it will be lifted into position for cleaving with a hatchet (we’re unsure what the string mechanism on the hatchet is for). The two pieces are then grabbed by some servo-powered grippers and transferred to a CNC router bed where a Dremel tool removes the residual creme before dumping the cookies out into your hand.


Once again, marketers should take note of this style of advertising. Notice the two main features achieved here: including a product in something we’re genuinely interested in and not being annoying (we’re looking at you Head-On).



[via Reddit]




Filed under: cnc hacks



via Hack a Day http://hackaday.com/2013/03/01/oreo-creme-hater-builds-rube-goldberg-cnc-router-to-remove-the-stuf/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+hackaday%2FLgoM+%28Hack+a+Day%29

Wooden LEGO Bricks

Wooden LEGO Bricks

Japanese company Mokulock makes eco-friendly wooden versions of the famous LEGO bricks.


-- Delivered by Feed43 service






via Design Ideas and Tech Concepts - Toxel.com http://www.toxel.com/tech/2013/02/26/wooden-lego-bricks/

2013-03-03

Money Sculptures

Money Sculptures

Canadian artist Kristi Malakoff makes unique sculptures out of real money.


-- Delivered by Feed43 service






via Design Ideas and Tech Concepts - Toxel.com http://www.toxel.com/inspiration/2013/02/20/money-sculptures/

Freezing Android to crack the encryption

frozen-phone-encryption-hacking


Build a better lock and someone will make a tool to open it without the key. Or in this case they’ve made a tool to discover the key using a trip to through the deep freeze. The Forensic Recovery of Scrambled Telephones — or FROST — uses cold temperatures and a custom recovery image to crack Android encryption keys.


Cold boot hacks go way back. They leverage use of low temperatures to slow down the RAM in a device. In this case, the target phone must already be powered on. Booting a phone that uses the encryption offered by Android 4.0 and newer requires the owner’s pass code to decrypt the user partition. But it then remains usable until the next power cycle. By freezing the phone, then very quickly disconnecting and reconnecting the battery, researchers were able to flash their own recovery image without having the encryption key cleared from RAM. As you can see above, that recovery package can snoop for the key in several different ways.


[Thanks Rob]




Filed under: android hacks, security hacks



via Hack a Day http://hackaday.com/2013/02/20/freezing-android-to-crack-the-encryption/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+hackaday%2FLgoM+%28Hack+a+Day%29

2013-02-27

Hjemmeautomasjon

I februar begynte jeg på et nytt prosjekt for å automatisere lys og varme i hele huset. Nå, omtrent et halvt år etter begynner det endelig å se ut som noe fornuftig også. Hadde fra før en hel haug med … Continue reading →



via Shitprat.no http://shitprat.no/2012/12/19/hjemmeautomasjon/

2013-02-25

Nemi


-- Delivered by Feed43 service






via Nemi http://www.dagbladet.no/tegneserie/nemi/

2013-02-13

February 13, 2013



New WEEKLY WEINERSMITH!



via Saturday Morning Breakfast Cereal (updated daily) http://www.smbc-comics.com/index.php?db=comics&id=2886&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+smbc-comics%2FPvLb+%28Saturday+Morning+Breakfast+Cereal+%28updated+daily%29%29

2013-02-02

Random image from fukung.net: cc478f94c5ef02bd02409efcdbeece7b.jpg







via Fukung.net most recently added pictures http://fukung.net/v/44425/cc478f94c5ef02bd02409efcdbeece7b.jpg

February 01, 2013



Oh man. We have something big to announce for the book. STAY TUNED GEEKS!



via Saturday Morning Breakfast Cereal (updated daily) http://www.smbc-comics.com/index.php?db=comics&id=2874&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+smbc-comics%2FPvLb+%28Saturday+Morning+Breakfast+Cereal+%28updated+daily%29%29