Wednesday, July 28, 2010

SQL to find non-consecutive numbers in a column

We had a need to find non-consecutive numbers in a sequence of numbers. This snippet of SQL finds userIDs which are non-consecutive.
SELECT A.userID + 1
FROM MyTable AS A
WHERE NOT EXISTS (
    SELECT B.userID FROM MyTable AS B 
    WHERE A.userID + 1 = B.userID)
GROUP BY A.userID;

Monday, July 26, 2010

Who's to blame for the recent economic meltdown?

A good summary from an interview with Nouriel Roubini at Amazon

The Fed kept interest rates too low for too long in the earlier part the past decade and fed — pun intended — the housing and credit bubble. Bankers and investors on Wall Street and in financial institutions were greedy, arrogant and reckless in their risk taking and build-up of leverage because they were compensated based on short term profits. As a result, they generated toxic loans – subprime mortgages and other mortgages and loans – that borrowers could not afford and then packaged these mortgages and loans into toxic securities – the entire alphabet soup of structured finance products, so-called “SIVs” like MBSs – Mortgage-Backed Securities, or CDOs – Collateralized Debt Obligations -- and even CDOs of CDOs. These were new, complex, exotic, non-transparent, non-traded, marked-to-model rather than market-to-market and mis-rated by the rating agencies. Indeed, the rating agencies were also culprits as they had massive conflicts of interest: they made most of their profits from mis-rating these new instruments and being paid handsomely by the issuers. Also, the regulators and supervisors were asleep at the wheel as the ideology in Washington for the last decade was one of laissez faire “Wild West” capitalism with little prudential regulation and supervision of banks and other financial institutions.

Wednesday, July 21, 2010

Default length of Delicious RSS feeds is 15

I use GoogleReader to keep track of interesting news stories, but I also use Firefox's live bookmarks combined with tagging at delicious.com.
As I find a site I'd like to add to my daily news reading I tag it with "news" and "daily". Long ago, I created a live bookmark in Firefox named "news+daily" to "http://del.icio.us/rss/fincher42/news+daily". I also have one for "energy+daily" and "blogs+daily".
In the morning I select in Firefox "Bookmarks/news+daily/Open All in Tabs" and it churns away and opens all my daily news sites in their own tidy little tab.
The problem I noticed lately is that the maximum number of tabs showing up was 15. After a little investigation I had to change my Firefox live bookmark source to append "?count=100" and now everything is rosy and "news+daily" has up to 100 bookmarks.

Friday, July 16, 2010

Emacs lisp code to backup current buffer

I've upgraded to the latest emacs and doing a little cleanup work. Just wrote this tiny elisp method to backup a file and embed the current date in the new file name. I use this right before I start making major changes in a file not under version control to have a temp file to go back to when things go awry - and they always go awry.

(defun backup-current-file ()
"backs up a file with date embedded. e.g., '.emacs' is copied to '.emacs-2010-07-16'"
(interactive)
(let ((backupfilename (concat (buffer-file-name) "-" (format-time-string "%C%y-%m-%d" (current-time)))))
(message (concat "copying file " (buffer-file-name) " to " backupfilename) )
(copy-file (buffer-file-name) backupfilename)
))

Wednesday, July 14, 2010

Using Emacs Tramp with Dreamhost

I finally got Emacs 23.2.1 to work using Tramp, a remote editing utility, with my hosting provider, Dreamhost. The secret was to use plink, which connects to PuTTY, as the transport. I had been using Ange-Ftp, but it transmits passwords in the clear, which is not safe in today's world. Now I can edit files on my hosting site in the comfort of Emacs, knowing my password is encrypted. In my .emacs file:
(if (string= emacs-version "23.2.1")
(progn
(require 'tramp)
(setq tramp-default-method "plink")
(setq tramp-verbose 10)
(setq tramp-debug-buffer t)
)
)

The Petroleum-Electric Myth is Alive and Well


The International Business Times had an article today referenced in slashdot which starts:
"As the U.S. moves to reduce dependence on oil, the nuclear industry is looking to expand, with new designs making their way through the regulatory process."
The introductory paragraph is just wrong because it implies if we just had enough electricity we wouldn't need as much oil, but we don't use petroleum to generate electricity. If Prometheus came down to earth and created enough new nuclear power plants overnight to supply 100% of the electricity in the US, do you know how much this would cut our oil dependency? Zero, zilch, zip. We need the oil to run our cars. Having all the electricity in the world won't power our cars - yet. The real path to energy independence is electric cars that we can power with nuclear, coal, hydro, wind, or solar. Then we can use our domestic oil for industry.

source

Saturday, July 03, 2010

A Fun Retro HTML5 Game


HTML5 holds plenty of promise - drawing directly on a canvas via JavaScript with GPU acceleration. A glimpse is an asteroid game here.