Wednesday, November 25, 2015

Handy howmany commandy

Here's a handy little bit of... well it isn't really SQL, is it? Shell scripting and SQL*Plus, more like.

tcsh & csh


alias howmany "echo 'select count(*) from table;' | sqlplus -s 'xxxxxx/xxxxxx@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xxxxxx)))'"


sh & bash


alias howmany="echo 'select count(*) from table;' | sqlplus -s 'xxxxxx/xxxxxx@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxxxx)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xxxxxx)))'"

(for ksh use either) - and then...

$ howmany

Enjoy!

p.s. I'd love to add a pipe to

sed -e '/^$/ d; s/^\s-*//g'

but the dollar sign screws things up, at least in tcsh. Oh well!

Wednesday, November 18, 2015

Sunday, November 15, 2015

Hard-to-read Podcasts

If you use the iOS Podcasts app, you've probably had occasion to swear at the producers of a podcast for their graphics and how they translate into dark text on a dark background. It's even worse in low light.


Well swear no more! At least not about this. It turns out there's a setting for that! Unfortunately, because this is iOS, you have to open the Settings app. Go there and choose Podcasts. And there aren't that many settings, so find this one, Custom Colors, and turn it off


And enjoy more podcasts!

Saturday, November 14, 2015

Don't take checks from strangers

I don't tend to be alarmist, but this article has an important warning... when you deposit a check, everything you write on it can go back to whoever issued it - your account number, social security number... huge identity theft problem. 

http://www.westernjournalism.com/alert-people-are-getting-checks-in-the-mail-from-walmart-when-they-deposit-them/


Wednesday, October 07, 2015

Emacs cleanup

Because I'm always needing this between tasks...
 
;; kill buffers visiting /scratch or /tmp files
(defun cleanup ()
  (interactive)
  (let* (
         (n)
         (list)
         (file)
         )
    (setq list (buffer-list))
    (setq n 0)
    (save-excursion
      (dolist (elt list)
        (setq file (buffer-file-name (get-buffer elt)))
        (if (and
             file
             (or
              (string-match "^/scratch/" file)
              (string-match "^/tmp/" file)
              )
             )
            (progn
              (if (kill-buffer elt)
                  (setq n (+ n 1))
                )
              )
          )
        )
      (message "Delete %d buffer%s." n (if (= n 1) "" "s"))
      )
    )
  )

Wednesday, August 26, 2015

I Repeat...

I'm always forgetting how to repeat a command. Here's how in tcsh:

$ repeat 9999 sh -c 'now=`date +%s` ; date > /tmp/tmp ; then=`date +%s` ; diff=`expr ${then} - ${now}` ; echo xxxxx ${diff} xxxxx ; if [ ${diff} -gt 0 ] ; then date ; fi ; sleep 15'

(The inner command is /bin/sh, of course)

Saturday, January 03, 2015

Hot and Sour Matzo Ball Soup

Ingredients:

  • Swanson Chinese hot and sour broth 
  • more broth (h&s or vegetable, optional)
  • a can or two of mushrooms
  • a scallion or two, chopped like you do
  • matzo balls, prepared as directed on the back of a can of Manischewitz matzo meal
Note: you can use one or two boxes/cans of broth, depending on your desired broth/ball ratio. The amount of scallions & mushrooms would then tend to follow the broth.

Instructions:

  1. Mix up the matzo ball ingredients and put them in the refrigerator.
  2. Cut up the scallion(s) and put them, along with the mushrooms, into the broth.
  3. Bring the broth and vegetables to a boil.
  4. Add the matzo balls to the boily broth.
  5. Lower the heat and simmer per the Manischewitz directions, about 30 minutes or so.

Monday, August 04, 2014

Listening Ports

Here's a handy command to find out which ports are listening:

/usr/sbin/lsof -P | sed -e '/(LISTEN)/ ! d; s/.* TCP .*:\([0-9][0-9]*\) .*/\1/' | sort -n | uniq

And ymmv, but sudo is probably a good way to run that.

Saturday, April 26, 2014

Emacs Window Title

One of those things I'll forget if I don't write it down - how to change the title of an Emacs window.

M-x set-frame-name

th! Stack Overflow

Wednesday, April 23, 2014

New cron job

Welcome to my crontab, new cron job!

18 * * * * ps -feww | grep -v grep | grep python | wc -l | sed -e '/^[0-4]$/ d; s/$/ pythons are running/g'

Why? If you've ever run into the problem where python cron jobs start piling up because of abrtd, and you've restarted abrtd, this will help you keep an eye on things. Every hour on the 18 (so as not to run into one of my running python scripts) I'm counting python processes and if there are more than four, I'll hear about it.

Friday, January 31, 2014

Pet Peeve: "infinite number of"

Welcome to my long list of pet peeves, "infinite number of"!!

Why say "infinite number of monkeys" when you can just say "infinite monkeys"??

Tuesday, January 28, 2014

Solaris TAR with Excluded Directories

It's been a long time since I had to use Solaris, and tar is bad enough without the differences between Linux and my previously favorite Unix!

$ tar cfX - /tmp/excludes . | gzip > ~/excluded.tgz

where /tmp/excludes looks like this:

./sub1
./sub2
./sub3

So it's not just a list of what's excluded, it's starting with the dot!

hattip: thank you, My Couple Of Cents!!

Saturday, November 02, 2013

Android SQLite queries and numeric predicates

The typical code for making an Android SQLite query goes something like this:

Uri uri = MyProvider.URI;
String[] projection = ...;
String where = COLUMN_NAME + "=?";
String[] whereArgs = new String[] { someValue };
String sortOrder = SORT_COL + " " + sortDir;
Cursor c = getContentResolver().query(uri, projection, 
  where, whereArgs, sortOrder);

But what if someValue isn't a String? What if you want to query your database on a numeric column? I was bashing my head against this and getting wrong results until I stumbled onto the suggestion that the "?" argument needs to be converted to a number. How to do it? Just add zero.

long someValue = ...;
Uri uri = MyProvider.URI;
String[] projection = ...;
String where = COLUMN_NAME + "=(?+0)";
String[] whereArgs = new String[] { Long.toString(someValue) };
String sortOrder = SORT_COL + " " + sortDir;
Cursor c = getContentResolver().query(uri, projection, 
  where, whereArgs, sortOrder);

You have to pass your selection arguments as an array of strings, so you'll use toString for that. But the query itself can use an addition operation to convert the string argument to a number. See the "+0" in the where string? That's it.

Maybe there's another, even better way, but this solved my problem - my queries now return just what they're supposed to. All you need is plus.

Tuesday, October 22, 2013

World Series Match-Ups

How many times have the Red Sox and Cardinals played each other in the World Series? This is the fourth time. The others were in 1946, 1967 and 2004. I was alive for two of those - can you guess which ones?

In case you're wondering about other match-ups, here is the complete list of which teams have played each other how many times.

11 Dodgers & Yankees
 7 Giants & Yankees
 5 Cardinals & Yankees
 4 Athletics & Giants
 4 Braves & Yankees
 4 Cubs & Tigers
 3 Cardinals & Red Sox
 3 Cardinals & Tigers
 3 Reds & Yankees
 2 Athletics & Cardinals
 2 Athletics & Cubs
 2 Athletics & Dodgers
 2 Athletics & Reds
 2 Braves & Indians
 2 Cubs & Yankees
 2 Giants & Senators
 2 Orioles & Pirates
 2 Phillies & Yankees
 2 Pirates & Yankees
 1 Americans & Pirates
 1 Angels & Giants
 1 Astros & White Sox
 1 Athletics & Braves
 1 Athletics & Mets
 1 Blue Jays & Braves
 1 Blue Jays & Phillies
 1 Braves & Twins
 1 Brewers & Cardinals
 1 Browns & Cardinals
 1 Cardinals & Rangers
 1 Cardinals & Royals
 1 Cardinals & Twins
 1 Cubs & Red Sox
 1 Cubs & White Sox
 1 Diamondbacks & Yankees
 1 Dodgers & Orioles
 1 Dodgers & Twins
 1 Dodgers & White Sox
 1 Giants & Indians
 1 Giants & Rangers
 1 Giants & Red Sox
 1 Giants & Tigers
 1 Giants & White Sox
 1 Indians & Marlins
 1 Indians & Robins
 1 Marlins & Yankees
 1 Mets & Orioles
 1 Mets & Red Sox
 1 Mets & Yankees
 1 Orioles & Phillies
 1 Orioles & Reds
 1 Padres & Tigers
 1 Padres & Yankees
 1 Phillies & Rays
 1 Phillies & Red Sox
 1 Phillies & Royals
 1 Pirates & Senators
 1 Pirates & Tigers
 1 Red Sox & Reds
 1 Red Sox & Robins
 1 Red Sox & Rockies
 1 Reds & Tigers
 1 Reds & White Sox

Source: Wikipedia, of course! ðŸ˜ƒ

Wednesday, August 07, 2013

MySQL Reference

Doing some MySQL work over the past couple of days, I googled a couple topics I needed help with, and both times I ended up at the same place.

So thanks, nixCraft, for the assist!!

Tuesday, July 02, 2013

Upgrading Debian

Upgrading from Squeeze to Wheezy

Why? Why not!!

Actually, it's because of the whole google-chrome-stable and gconf-blah-blah business. It's scrolled off my screen, but it's all over the internets.

Mainly I'm following the steps I found here at HowtoForge.

Updated my sources.list, just replacing squeeze with wheezy

Did an update and an upgrade, started to do a dist-upgrade, but got this error:

E: Could not perform immediate configuration on 'openjdk-6-jre'. Please see man 5 apt.conf under APT::Immediate-Configure for details. (2)

Did this to continue:

sudo apt-get remove default-jre
sudo apt-get remove openjdk-6-jre

Now it's running... we'll see what happens next!

How about being WAN'd in via SSH and my end goes sleepy or wonky? Yikes!! But I did a:

sudo dpkg --configure -a

and the dist-upgrade is chugging along again.

A word of advice to whoever is responsible for configuration files: It sure would be nice if I could resolve all of the config conflicts either before or after the upgrade. Having the upgrade pause for me to Z and cp and blah blah blah, that's annoying.

And it's done. Now to fix the above:

sudo apt-get install default-jre
sudo apt-get install google-chrome-stable



Ta-da! It works! Even Chrome is back!!

Friday, June 21, 2013

Starting Oracle

This is what happens when I don't write stuff down. Fortunately I was able to piece together what I needed to remember when starting up my database after a reboot. And now I'm writing it down!

$ cd install-area/oracle11/software
$ setenv ORACLE_HOME `pwd`

$ setenv ORACLE_SID orcl

$ ./bin/sqlplus 'sys/password as sysdba'

SQL*Plus: Release 11.2.0.3.0 Production on Fri Jun 21 06:35:36 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup
.
.
.

$ ./bin/lsnrctl start

Filed under note-to-self and let's hope next time I remember there is a note!


Monday, March 18, 2013

Debian Console Mode?

I got myself stuck in VNC full-screen mode and like any good monkey just started pressing random key combinations. And I actually stumbled onto something magical and useful!

Sunday, March 17, 2013

Debian Wireless (solved)

I was struggling quite a bit with the Wi-Fi on the TiBook. Then for some reason I rebuilt Debian and had a chance to start over.

Sunday, March 10, 2013

My Apache setup

What, no notes to self about my previous Apache installation? Well how about I do that this time...