Thursday, April 7, 2011

MySQL madness from MM

MYSQL> use information_schema
Database changed

MYSQL> show tables;
+---------------------------------------+
| Tables_in_information_schema          |
+---------------------------------------+
| CHARACTER_SETS                        |
| COLLATIONS                            |
| COLLATION_CHARACTER_SET_APPLICABILITY |
| COLUMNS                               |
| COLUMN_PRIVILEGES                     |
| KEY_COLUMN_USAGE                      |
| PROFILING                             |
| ROUTINES                              |
| SCHEMATA                              |
| SCHEMA_PRIVILEGES                     |
| STATISTICS                            |
| TABLES                                |
| TABLE_CONSTRAINTS                     |
| TABLE_PRIVILEGES                      |
| TRIGGERS                              |
| USER_PRIVILEGES                       |
| VIEWS                                 |
+---------------------------------------+
17 rows in set (0.01 sec)

MYSQL> select distinct grantee from user_privileges;
+--------------------+
| grantee            |
+--------------------+
| 'root'@'localhost' |
| 'root'@'dbro101'   |
| 'rc'@'localhost'   |
| ''@'dbro101'       |
| ''@'localhost'     |
| 'rc'@'%'           |
| 'redcarpet'@'%'    |
| 'sdc_updater'@'%'  |
+--------------------+
8 rows in set (0.01 sec)

MYSQL> CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
MYSQL> GRANT ALL ON *.* TO 'jeffrey'@'localhost'; 

Wednesday, March 9, 2011

I want to be like Mike (Masters)

Mike gave me some crib notes on unix:

df -h
reports file system disk space usage

du -h
shows disk usage by directory
-h is human readable

du -h --max-depth=1
summarizes all the du under a dir at a certain depth. this takes a long time at root level, so you wouldn't do it there

cat /proc/cpuinfo (no /proc dir on a Mac)
summarizes the cpu info for the machine

/bin is scripts and things
/etc is configs & default settings
/dev is devices
/lib is header files for c libraries and such
/var/log is usually where logs are
/usr/local for installing new software (many install scripts look for /usr/local)
/var/lib is another place software may be installed

also:
sudo su
allows you to emulate root

Thursday, December 9, 2010

How to make list.toArray() return a specific class


debugStringsArray = new String[] {
"productId", "browseNode", "brand", "merchant", "productSource", "priceMetricDAL", "calculatedCPC",
"mexpMerchantIsActive", "yield", "mexpCatId", "relevance", "boost", "ctr", "tags"
};
if (newGrid) {
// boy it's a PITA to append to an already-initialized array
List debugStringsList = new ArrayList();
for (String debugString : debugStringsArray) {
debugStringsList.add(debugString);
}
debugStringsList.add("productTitle");
debugStringsList.add("imageFile");

// here is how you get around the fact that ordinary list.toArray() returns Object[]
debugStringsArray = new String[debugStringsList.size()];
debugStringsArray = debugStringsList.toArray(debugStringsArray);
}

// ETA: It's actually not that much of a PITA:
ArrayUtils.add(Object[] array, Object element) // convenience method

Wednesday, December 8, 2010

Do not forget: Stay out of debt

To create a fresh copy (not pointing at the source items) use:

Collections.copy(destList, srcList);

Tuesday, November 30, 2010

LinkedHashMap

If you have a HashMap in a particular order and want to make sure it gets maintained, use LinkedHashMap.


// LinkedHashMap remembers the order in which the items are added to the list,
// which preserves the sorting coming from the db
Map<String, List<TopSellerDO>> topSellersByCategoryMap = new LinkedHashMap<String, List<TopSellerDO>>();

Tuesday, November 2, 2010

JSTL code to iterate over a Map

Helpful snippet of JSTL code to iterate over a
Map<String, List<SomeDO>>

<c:set var="topSellersByCategoryMap" value="${results.topSellersByCategoryMap}"/>

<c:forEach var="entry" items="${topSellersByCategoryMap}">
  Name: ${entry.key}
  Value: ${entry.value}

    <c:forEach var="listitem" items="${entry.value}">
      Item: ${listitem.merchant.domain}
    </c:forEach>
</c:forEach>

Thursday, July 22, 2010

Yeats poem

This was quoted in an email from Congressman Alan Grayson and I forgot how much I love it. Putting it here to hold onto for another day.

TURNING and turning in the widening gyre
The falcon cannot hear the falconer;
Things fall apart; the centre cannot hold;
Mere anarchy is loosed upon the world,
The blood-dimmed tide is loosed, and everywhere
The ceremony of innocence is drowned;
The best lack all conviction, while the worst
Are full of passionate intensity.

William Butler Yeats, "The Second Coming"