filed in Programming, SQL on Jan.11, 2012
Method 1: Using a cursor
declare cursor1 cursor local for select * from tablename
open cursor1
fetch next from cursor1 into #temptable
while @@fetch_status = 0
begin
if exists (select column from tablename where
id = (select id from #temptable))
begin
/* do stuff here */
end
else
begin
/* do other stuff here */
end
if object_id('tempdb..#temptable') is not null
drop table #temptable
fetch next from cursor1 into #temptable
end
close cursor1
deallocate cursor1
Method 2: Using a temporary table with primary key
(via: http://support.microsoft.com/kb/111401)
declare @au_id char( 11 )
set rowcount 0
select * into #mytemp from authors
set rowcount 1
select @au_id = au_id from #mytemp
while @@rowcount <> 0
begin
set rowcount 0
select * from #mytemp where au_id = @au_id
delete #mytemp where au_id = @au_id
set rowcount 1
select @au_id = au_id from #mytemp<BR/>
end
set rowcount 0
Method 3: Using a temporary table without primary key
(via: http://support.microsoft.com/kb/111401)
set rowcount 0
select NULL mykey, * into #mytemp from authors
set rowcount 1
update #mytemp set mykey = 1
while @@rowcount > 0
begin
set rowcount 0
select * from #mytemp where mykey = 1
delete #mytemp where mykey = 1
set rowcount 1
update #mytemp set mykey = 1
end
set rowcount 0
Tags: cursor, database, dbms, iterate, Programming, result set, SQL, table, temp, temporary

Loading ...
filed in Programming, SQL on Jan.11, 2012
Method 1: Using a cursor
declare cursor1 cursor local for select * from tablename
open cursor1
fetch next from cursor1 into #temptable
while @@fetch_status = 0
begin
if exists (select column from tablename where
id = (select id from #temptable))
begin
/* do stuff here */
end
else
begin
/* do other stuff here */
end
if object_id('tempdb..#temptable') is not null
drop table #temptable
fetch next from cursor1 into #temptable
end
close cursor1
deallocate cursor1
Method 2: Using a temporary table with primary key
(via: http://support.microsoft.com/kb/111401)
declare @au_id char( 11 )
set rowcount 0
select * into #mytemp from authors
set rowcount 1
select @au_id = au_id from #mytemp
while @@rowcount <> 0
begin
set rowcount 0
select * from #mytemp where au_id = @au_id
delete #mytemp where au_id = @au_id
set rowcount 1
select @au_id = au_id from #mytemp<BR/>
end
set rowcount 0
Method 3: Using a temporary table without primary key
(via: http://support.microsoft.com/kb/111401)
set rowcount 0
select NULL mykey, * into #mytemp from authors
set rowcount 1
update #mytemp set mykey = 1
while @@rowcount > 0
begin
set rowcount 0
select * from #mytemp where mykey = 1
delete #mytemp where mykey = 1
set rowcount 1
update #mytemp set mykey = 1
end
set rowcount 0
Tags: cursor, cursors, database, dbms, iterate, Programming, result set, rows, SQL, table, temp, temporary

Loading ...
filed in Javascript, Programming on Jan.11, 2012
“JavaScript is an object oriented (OO) language, with its roots in the Self programming language, although it’s (sadly) designed to look like Java. This makes the language’s really powerful and sweet features stay covered by some pretty ugly and counter-intuitive work-arounds.
One such affected feature is the implementation of prototypical inheritance. The concepts are simple yet flexible and powerful. It makes inheritance and behaviourism first-class citizens, just like functions are first-class in functional-ish languages (JavaScript included).
Fortunately, ECMAScript 5 has gotten plenty of things to move the language in the right way, and it’s on those sweet features that this article will expand. I’ll also cover the drawbacks of JavaScript’s design, and do a little comparison with the classical model here and there, where those would highlight the advantages or disadvantages of the language’s implementation of prototypical OO.
It’s important to note, though, that this article assumes you have knowledge over other basic JavaScript functionality, like functions (including the concepts of closures and first-class functions), primitive values, operators and such…”
Understanding JavaScript OOP (killdream.github.com)
Tags: javascript, object oriented, oop, Programming, tutorial, tutorials

Loading ...
filed in C/C++, Programming on Jan.08, 2012
“The C programming language was devised in the early 1970s as a system implementation language for the nascent Unix operating system. Derived from the typeless language BCPL, it evolved a type structure; created on a tiny machine as a tool to improve a meager programming environment, it has become one of the dominant languages of today. This paper studies its evolution.”
The Development of the C Language (cm.bell-labs.com)
Tags: C#, history, language, Programming

Loading ...
filed in Tips on Jan.06, 2012
If you are logged into your machine with a username that doesn’t have access to a certain SQL Server database you can launch SQL Server Management Studio with different credentials. This allows you to use Windows Authentication with a different username when connecting to the database server.
| runas /user:DOMAIN\USERNAME “C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe” |
Tags: microsoft, sql server, tips

Loading ...
filed in Miscellaneous on Jan.04, 2012
“Go analog. (e.g. cooking, hiking, astronomy, etc.)
Stay healthy. (e.g. weight loss, RSI, etc.)
Embrace the uncomfortable. (e.g. stop using a mouse, use Dvorak, try a different OS, etc.)
Learn a new programming language. (e.g. scala, erlang, haskell, OCaml, Prolog, etc.)
Automate. (build a robot, lego mindstorms, arduino boards, shell scripting, etc.)
Learn more mathematics.
Focus on security. (e.g. use KeePassX, PasswordSafe, set up SSL in Apache, encrypt your USB drives, etc.)
Back up your data.
Learn more theory.
Engage the arts and humanities. (e.g. Painting, sketching, music, film, etc.)
Learn new software. (e.g. try 3D modeling, use LaTeX, etc.)
Complete a personal project.”
Read on for more suggestions: 12 resolutions for programmers (matt.might.net)
Tags: new year, new year's, resolutions

Loading ...
filed in Hardware, Linux, Programming on Jan.04, 2012
“In the early days computers were much simpler. The various components of a system, such as the CPU, memory, mass storage, and network interfaces, were developed together and, as a result, were quite balanced in their performance. For example, the memory and network interfaces were not (much) faster than the CPU at providing data.
This situation changed once the basic structure of computers stabilized and hardware developers concentrated on optimizing individual subsystems. Suddenly the performance of some components of the computer fell significantly behind and bottlenecks developed. This was especially true for mass storage and memory subsystems which, for cost reasons, improved more slowly relative to other components.
The slowness of mass storage has mostly been dealt with using software techniques: operating systems keep most often used (and most likely to be used) data in main memory, which can be accessed at a rate orders of magnitude faster than the hard disk. Cache storage was added to the storage devices themselves, which requires no changes in the operating system to increase performance. {Changes are needed, however, to guarantee data integrity when using storage device caches.} For the purposes of this paper, we will not go into more details of software optimizations for the mass storage access…..
For the most part, this document will deal with CPU caches and some effects of memory controller design. In the process of exploring these topics, we will explore DMA and bring it into the larger picture. However, we will start with an overview of the design for today’s commodity hardware. This is a prerequisite to understanding the problems and the limitations of efficiently using memory subsystems. We will also learn about, in some detail, the different types of RAM and illustrate why these differences still exist…..”
Part 1 (http://lwn.net/Articles/250967/)
Part 2 (http://lwn.net/Articles/252125/)
Part 3 (http://lwn.net/Articles/253361/)
Part 4 (http://lwn.net/Articles/254445/)
Part 5 (http://lwn.net/Articles/255364/)
Part 6 (http://lwn.net/Articles/256433/)
Part 7 (http://lwn.net/Articles/257209/)
Tags: cache, linux, memory, Programming

Loading ...
filed in Miscellaneous on Jan.03, 2012
“As most software and creative professionals know, coffee is an important technology for boosting mental acuity and maintaining peak on-the-job performance. But did you also know that coffee can be a damn tasty beverage? It’s true. All you need is the appropriate amount of disrespect for the mainstream coffee industry and a desire to enjoy a better beverage. So read on, and learn the secrets to great coffee.
First things first. Mainstream coffee sucks, and specialty coffee mostly sucks. Mainstream coffee is primarily stale, low-quality, high-yield beans, many times cheap robustas, foisted on a largely unknowing public in supermarkets nationwide. Specialty coffee isn’t so much coffee as it is flavorings, sweeteners, and milk; what coffee is sold is often neither “special” nor properly prepared – it’s usually over-roasted to serve as a background for sweet flavorings. A few specialty coffee purveyors, however, do sell good coffee, and I’ll show you how to find them, but most are happy to sell you stale beans whose dead taste is hidden behind raspberry and caramel syrups. Buyer beware.
Nevertheless, good coffee is good – great even – all by itself. It’s also dirt cheap and easy to make. Therefore, don’t settle for a cup of crappy coffee: make a cup of the good stuff for yourself…” (source: A Coder’s Guide to Coffee )
Read the rest of the article here: A Coder’s Guide to Coffee (blog.moertel.com)
Tags: caffeine, coffee, productivity

Loading ...
filed in Linux, Mac OS X, Unix on Dec.29, 2011
& – This causes the application to run in the background. You will get a new shell prompt after issuing this command.
nohup and disown – Both of these prevent SIGHUP (hangup) signals so the application isn’t killed when the terminal session is closed. nohup does this when the job starts. disown can be used to make changes to an actively running job.
Tags: &, bsd, disown, linux, mac, nohup, OS X, unix

Loading ...
filed in Tutorials on Dec.29, 2011
By now most users should have the new Google bar, however if you don’t follow these instructions.
If you are using Google Chrome right click on any whitespace on a Google page and select “Inspect Element”. Click on the Console tab and paste the following text and press enter.
document.cookie=”PREF=ID=03fd476a699d6487:U=88e8716486ff1e5d:FF=0:LD=en:
CR=2:TM=1322688084:LM=1322688085:S=McEsyvcXKMiVfGds; path=/; domain=.google.com”;
window.location.reload(); |
Congratulations, you should now see the new Google bar at the top of the page!
Tags: google, google bar, google chrome

Loading ...