Tuesday, May 12, 2009

This was hard to figure out...

... and it doesn't even include the regex .dll I had to write in C# to make the stored procedure work! Watch it crash when I actually put it live : )

CREATE PROCEDURE [dbo].[UpdateFolderSort]
(
@folder_id int,
@folder_sort int = NULL
)

AS

DECLARE @root_decimal varchar(500)
DECLARE @folder_parent int
DECLARE @old_decimal varchar(500)
DECLARE @folder_level int
DECLARE @pos int
DECLARE @level_loop int
DECLARE @regex_prefix varchar(500)

BEGIN
SET @folder_parent = (SELECT folder_parent FROM Folders WHERE folder_id = @folder_id)
END

BEGIN
IF @folder_parent IS NOT NULL
SET @root_decimal = (SELECT folder_decimal FROM Folders WHERE folder_id = @folder_parent)
END

BEGIN
SET @old_decimal = (SELECT folder_decimal FROM Folders WHERE folder_id = @folder_id)
SET @old_decimal = RIGHT(@old_decimal, 4)
END

BEGIN
SET @folder_level = (SELECT folder_level FROM Folders WHERE folder_id = @folder_id)
END

IF @folder_level = 1
BEGIN
UPDATE
Folders
SET
folder_decimal = STUFF(folder_decimal, 1, 4, SUBSTRING('0000',1,4 - LEN(CONVERT(varchar(4), @folder_sort))) + CONVERT(varchar(4), @folder_sort))
WHERE
dbo.RegexMatch(folder_decimal, @old_decimal + '\.') = 1 AND folder_lineage LIKE '%/' + CONVERT(varchar(4), @folder_id) + '/%'
END
ELSE
BEGIN
SET @pos = ((@folder_level - 1) * 4) + @folder_level

SET @level_loop = 1
SET @regex_prefix = ''
WHILE @level_loop < @folder_level
BEGIN
SET @regex_prefix = @regex_prefix + '\d{4}\.'
SET @level_loop = @level_loop + 1
IF @level_loop = @folder_level
BREAK
ELSE
CONTINUE
END

UPDATE
Folders
SET
folder_decimal = STUFF(folder_decimal, @pos, 4, SUBSTRING('0000',1,4 - LEN(CONVERT(varchar(4), @folder_sort))) + CONVERT(varchar(4), @folder_sort))
WHERE
dbo.RegexMatch(folder_decimal, @regex_prefix + @old_decimal + '\.') = 1 AND folder_lineage LIKE '%/' + CONVERT(varchar(4), @folder_id) + '/%'
END

BEGIN
IF @root_decimal IS NOT NULL
BEGIN
UPDATE
Folders
SET
folder_sort = @folder_sort,
folder_decimal = @root_decimal + '.' + SUBSTRING('0000',1,4 - LEN(CONVERT(varchar(4), @folder_sort))) + CONVERT(varchar(4), @folder_sort)
WHERE
folder_id = @folder_id
END
ELSE
BEGIN
UPDATE
Folders
SET
folder_sort = @folder_sort,
folder_decimal = SUBSTRING('0000',1,4 - LEN(CONVERT(varchar(4), @folder_sort))) + CONVERT(varchar(4), @folder_sort)
WHERE
folder_id = @folder_id
END
END

Labels:

Sunday, August 3, 2008

A trophy

This SQL query solved a problem that was bugging me for two days:
SQLStr = "SELECT TOP 10 l.log_message, MAX(l.log_timestamp) AS high_time,
l.log_type, l.page_id, l.user_id, u.user_name, u.user_displayname " & _
"FROM tbluserlogs AS l, tblusers AS u, tblpages AS p WHERE l.user_id = '" &
user_id & "' AND l.site_id = '" & SiteID & "' AND l.user_id =
u.user_id " & _ "AND (l.page_id IS NULL OR (p.page_id = l.page_id AND "
& AllowedPermissions & ")) " & _ "GROUP BY l.log_message,
l.log_type, l.page_id, l.user_id, u.user_name, u.user_displayname ORDER BY
high_time DESC"
The above won't mean anything to anyone but me. It's posted here simply as a trophy of a personal victory in a battle I raged today.

I am often exclaiming to my non-caring computer, "Ha! I beat you!"

Labels:

Saturday, December 22, 2007

A learning computer

"My CPU is a neural net, a learning computer" - Terminator

I've written before about how the Web is a vast brainlike structure that we, just by participating, are programming into the first viable artificial intelligence through depth-linking of ideas. Check out this diagram of the central backbone of the Internet. It certainly looks like a brain.

Labels:

Sunday, December 16, 2007

So you're a web junky? Well, I'm your dealer

I saw this on the web and realized it's true. There are a great deal of similarities between software developers and drug dealers.

Drug DealersSoftware Developers
Refer to their clients as "users".Refer to their clients as "users".
"The first one's free!""Download a free trial version..."
Have important Asian connections.Have important Asian connections.
Strange jargon:

"Stick"
"Rock"
"Wrap"
"E"
"Stash"
"Drive-by"
"Hit (LSD)"
"Source"
"The Pigs"
Strange jargon:

"SCSI"
"RTFM"
"Packet"
"C"
"Cache"
"CTRL ALT DEL"
"Hit (WWW)"
"Source-code"
"Microsoft"
Realize that there's tons of cash in the 14- to 25-year-old market.Realize that there's tons of cash in the 14- to 25-year-old market.
Clients really like your stuff when it works. When it doesn't work they want to kill you.Clients really like your stuff when it works. When it doesn't work they want to kill you.
Job is assisted by the industry's producing newer, more potent product.Job is assisted by the industry's producing newer, more potent products.
Often seen in the company of pimps, hustlers and low-lifes.Often seen in the company of marketing people, venture capitalists and fund managers, ie. low-lifes.
When things go wrong, a "fix" is just a phone call away, but may be expensive.When things go wrong, a "fix" is just a phone call away, but may be expensive.
A lot of people are getting rich while still teenagers.A lot of people are getting rich while still teenagers.
Product causes unhealthy addictionsWorld of Warcraft, Everquest, stupid Flash games...
Do your job well and you can sleep with sexy movie stars who depend on you.Damn! DAMN!!!

Labels:

Thursday, November 15, 2007

Ten thousand lines

The bodhisattva once said to a visiting programmer: “There is more enlightenment in one line of Ruby than there is in ten thousand lines of C.”

The bodhisattva, who was very proud of his mastery of C, said: “How can this be? C is the language in which Ruby is implemented!”

The bodhisattva replied: “That is so. Nevertheless, there is more enlightenment in one line of Ruby than there is in ten thousand lines of C.”

The programmer grew distressed. “But through the C language we become as one with the operating system and the machine, reaping matchless performance!”

The bodhisattva replied: “All that you say is true. But there is still more enlightenment in one line of Ruby than there is in ten thousand lines of C.”

The programmer scoffed at the bodhisattva and rose to depart. But the bodhisattva nodded to his student, who wrote a line of Ruby on a nearby whiteboard, and said: “Master programmer, consider this code. Implemented in pure C, would it not span ten thousand lines?”

The programmer muttered through his beard, contemplating what the student had written. Finally he agreed that it was so.

“And how many hours would you require to implement and debug that C program?” asked the student.

“Many,” admitted the visiting programmer. “But only a fool would spend the time to do that when so many more worthy tasks await him.”

“And who better understands enlightenment?” The bodhisattva asked. “Is it he who writes the ten thousand lines, or he who, perceiving the emptiness of the task, gains merit by not coding?”

Upon hearing this, the programmer was enlightened.

- Adapted from Rootless Root by Eric S. Raymond

Labels: ,

Wednesday, May 30, 2007

Poignant guides to computer languages

So RTFM stands for "Read the Fucking Manual," implying that not many do. Can you blame them? Most manuals and computer books are ultra-stuffy and boring. Well, here's one you'll actually enjoy reading. It's poignant. The freely available book, Why's (Poignant) Guide to Ruby, is part programming manual, part comic book, part journal, and all art. I've never seen a computer book like this, but I hope I'll see a lot more of them in the future. In-depth coverage of the Ruby programming language coupled with an almost punk zine story telling.

Check it out, it's free!

Excerpt:

My conscience won’t let me call Ruby a computer language. That would imply that the language works primarily on the computer’s terms. That the language is designed to accomodate the computer, first and foremost. That therefore, we, the coders, are foreigners, seeking citizenship in the computer’s locale. It’s the computer’s language and we are translators for the world.

But what do you call the language when your brain begins to think in that language? When you start to use the language’s own words and colloquialisms to express yourself. Say, the computer can’t do that. How can it be the computer’s language? It is ours, we speak it natively!

We can no longer truthfully call it a computer language. It is coderspeak. It is the language of our thoughts.

Labels: , ,

Wednesday, May 23, 2007

Cheat sheet for the un-geek

You may have seen these code snippets on t-shirts and thought wtf? For those un-1337, like my Mom, I reprint them here w/ translations.

There's no place like 127.0.0.1
All network connections are assigned a numerical address. 127.0.0.1 is the local address of your computer for internal communication. In other words, this reads "There's no place like home."

10 print Home
20 print Sweet
30 goto 10
In BASIC (a programming language), code is written in numbered lines and performed in sequence. This says to print "Home", then "Sweet", then go back and print "Home". "Home Sweet Home".

There are only 10 types of people in the world: Those who understand binary and those who don't.
Binary code answers questions in yes (1) or no (0). You probably read that as "10" if you're not geek.

01111001 01101111 01110101 01100001 01110010 01100101 01100100 01110101 01101101 01100010
Obviously binary code, but what's it say? Well, it says "You are dumb".

$> cd /pub
$> more beer
UNIX for "Go to the pub, get more beer".

SELECT * FROM users WHERE clue > 0
Information is retrieved from databases via Structured Query Language (SQL) statements like this one that literally reads "Select all users where clue is greater than zero". In other words, "Select all the users that have a clue".

$> man woman
$> Segmentation fault (core dumped)
Pretty much self explanatory. UNIX combines man and woman. Sad things happen.

Roses are #FF0000
Violets are #0000FF
In HTML, colors are expressed in hex codes like these.

RTFM
This is an acronym that most un-geeks don't understand. If they did, they wouldn't have to hire geeks so often. It stands for "Read the fucking manual".

PEBKAC
Variation on RTFM. You may have heard tech support tell you that it is a PEBKAC problem. Sadly, it stands for "Problem Exists Between Keyboard And Chair". Yes, that means you.

Got Root?
In Linux, root privileges gives you complete power over the system. "Got root?" means "Have you hacked it?"

/(bb[^b]{2})/
Regular expressions are used in programming to find strings of characters that match a certain pattern. For example, the expression "g*gol" matches ggol, gogol, googol, gooogol, etc. This expression reads "To be or not to be", one of Shakespeare's famous lines.

01111001 01101111 01110101 01100001 01110010 01100101 01100100 01110101 01101101 01100010
Still means "you are dumb". Just checking if you're paying attention : )

i > u
The ultimate inequation. "I am greater than you."

42
The answer to life, the universe, and everything. Duh.

And for my 01001101 01001111 01001101 who can't read any of this, that means "MOM".

Labels: ,

Friday, May 11, 2007

Depth web versus shallow web

I've mentioned before (and will probably come back to) the idea that the web is all about depth exploration of a topic. No stand-alone topic is completely stand-alone, but rather linked to back stories and related information and virtually every side-notion imaginable. It can get really deep. Perhaps the best example of this is Wikipedia, where everything eventually ends up as a blue link to everything else. It's a seemingly endless click adventure that if pursued indefinitely will bring you back to the beginning knowing everything you could possibly know about a topic. Like I said, it's depth exploration.

That's the good web in a nutshell. Almost every web application is designed around this idea of seeing how many turtles down you can get.

Almost.

Some systems are better than others at depth treatment, but surprisingly there's at least one that doesn't even try. The opposite of depth exploration is flatland shallowness. It's called Twitter.

Twitter is instant updates in 140 characters or less of what you're doing at any given moment. You can share this log with your friends who (for some odd reason) might actually be interested in what you're doing at any given moment. Sounds kind of cool. It's totally webby in that it's broadcasting your life in real-time. It's also kind of creepy, but that's alright. It's not like voyeurism and the web haven't met before. I like it because it's challenging to continually express what you're doing in Haiku moments.

Example:
Went to Walmart. Bought a case of Dasani because local tap water tastes like pesticides. Wondering why the floor is sticky. <-123 characters

If every random thought that crosses your mind demands utterance, that's the idea behind Twitter. It's actually Twitter's saving grace. It's kind of a nifty concept keeping a log of random thoughts. Unfortunately it's also horizontal, flatland, and shallow.

The crucial feature that Twitter is lacking (Web 2.0 entrepreneurs take notice, as this is how to make a Twitter plus) is an automatic way of linking these random thoughts to other random thoughts, thereby creating a depth narrative. That's how the brain works, after all. No idea is an isolated thing. Each thought is intrinsically linked to other thoughts. Our brains automatically process information relative to previously stored information. Sticky floors instantly conjure up memories of that time you went to the movies, which is linked to that first kiss in the back row, which is linked to that trip you took with that girl you kissed, which is linked to the more mundane thought of buying Mountain Dew when you stopped to get gas, and now we're back to Dasani and water tasting like pesticides. Then we're off to explore another tangent. The whole process creates this depth story stemming from a seemingly shallow account of going to Walmart, expressed in a post of less than 140 characters.

That would be really cool, bordering on a blueprint for artificial intelligence, but we don't even have to stretch it that far. It's enough to say that if Twitter is to accurately represent the stream of consciousness of all us twits, it needs depth. Otherwise, it's just the Andy Warhol painting of Web 2.0. A bit of a novelty, but completely shallow.

Labels: , ,

Wednesday, May 2, 2007

My new theme song, "Code Monkey"

I have a new theme song, being the code monkey that I am:

"Code Monkey" by Jonathan Coulton. Dance by Emily.

Labels: ,

Friday, March 16, 2007

Feeding the machine

I have a love-hate relationship with technology.

I once worked in the dishroom of a large cafeteria serving hundreds of the rudest people imaginable. As they left, they would sling their trays in through a window and my job was to [get covered in slop] stack the trays and load them onto the conveyor belt of this large silver cleaning machine. No matter how many trays I stacked and loaded there were always more coming. Stack. Load. Stack. Load. Every day the same thing. Feed the machine. Before long I couldn't tell where the machine left off and I began.

Some devices were built to make our lives easier. They serve us. They're an accessory. This monstrous steam tray cleaner wasn't one of those devices. It was large, clearly in charge, and hungry. I was but a cog in the machine feeding it endlessly. To pass the time I even took to chanting in my head: "Feed the machine. Feed the machine. Feed the machine." I was a module — the human component of a machine designed for the greater goal of clean dishes.

And today?

Today I'm partly a software coder working on Web 2.0 applications. This came about because of an early love of print, old manuscripts, and the power of the written word. I learned a long time ago how to design for and run printing presses, but when the web hit the world I was the first in my little circle of friends take an awestruck gasp. It was amazing how comparatively inexpensive you can put any strange notion you had out there. In the early days, the web was just a digital version of print, a top-down publishing scheme but nonetheless amazing, and truly revolutionary.

Web 2.0 is the natural evolution of that idea. It is the same concept that any crazy idea can be put out there, but now in critical mass. The technology that coders have assembled has reduced the complexity of publishing and collapsed the hierarchy into a horizontal model. That was the idea behind Web 1.0, but it has only just come about in any real sense. Now every crazy idea that is put out there is tagged to other crazy ideas. Links evolved from hyperlinked documents to hyperlinked everything, up to and including people. No crazy idea is a singular phenomena, it is now a part of the collective of a bigger crazy.

That's the love. In all this madness, we are building something completely new. It's something the world has never seen before in any period of history. Unless the Library at Alexandria had some system I'm not aware of for user-generated content that automatically linked the content to everything else related, including the librarians themselves, we have stumbled upon something that is the envy of philosophers, mystics, and Kings alike — no matter what the age. This machine is being constructed by everyone, not just the programmers. You, I, my seventy-something-year-old grandmother, we're building the largest human endeavor ever constructed.

In the Wired article "We Are the Web", Kevin Kelly writes:

And who will write the software that makes this contraption useful and productive? We will. In fact, we're already doing it, each of us, every day. When we post and then tag pictures on the community photo album Flickr, we are teaching the Machine to give names to images. The thickening links between caption and picture form a neural net that can learn. Think of the 100 billion times per day humans click on a Web page as a way of teaching the Machine what we think is important. Each time we forge a link between words, we teach it an idea. Wikipedia encourages its citizen authors to link each fact in an article to a reference citation. Over time, a Wikipedia article becomes totally underlined in blue as ideas are cross-referenced. That massive cross-referencing is how brains think and remember. It is how neural nets answer questions. It is how our global skin of neurons will adapt autonomously and acquire a higher level of knowledge.
It doesn't even matter if people read this crap we post. We are programming the machine itself. It's learning from it's fathers and mothers, ourselves. We are here. We are giving birth to this machine. It's exciting times because when they look back, for good or ill, it all starts right now.

That's the love. It's also what scares the hell out of me.

Maybe it's a narcissistic/nostalgic yearning to remain at the top of the food chain, or a struggle to hold fast to the distinction of a boundary between man and machine. Maybe it's that I fancy myself an artist as well as a programmer and as such I'm duty bound to promote the human condition. Or maybe it's just flashback nightmares of loading trays into the Big Silver Machine. Whatever it is, I cringe at the thought of this massive machine that is more than any of us, ourselves. As father to it, the same as any of you, I wonder if I'm not one of those deadbeat dads that marvel at the birthing but want to skip town on eighteen years committed serving the creation.

One thing is clear. We can rage against the machine all we want. At some point, however, we have to step out of denial and realize the machine is now us. Whatever line there was is blurred.

Labels: , , ,

Jeremy Parnell .com Send Message My Blog Recent & Current Projects Photos, Videos, Etc. View My Profile Send Message