I hate the fact that XML doesn't allow nested comments! Since I have comments in almost every source file I write, and since I frequently want to disable portions of my code, I hit this problem a lot
I finally found out why they don't allow nested comments, or any "--" inside: the original SGML has some complicated rules about double-dashes and how they change the parsing inside a comment, and the XML spec mandates that XML docs are valid SGML, so it is more restrictive and says that XML cannot contain any double-dashes.
So, basically, I want to throttle whoever came up with this complication in SGML. Maybe the person to blame actually introduced this in a previous spec... but anyone who puts this kind of trickiness into a standard should be blacklisted from IT work permanently. Argh!
Monday, November 16, 2009
Thursday, October 15, 2009
Java Tutorial for Absolute Beginners
(I want to give programming newbies an introduction to Java, but in a way that they can do it independently such that the tools won't get in the way (eg. 'javac' to compile, 'java' to run, avoiding classpath issues, and so on). I think the best fit is to have them use Eclipse (or another Java IDE), which will allow them to get to the code quickly; hopefully the IDE won't distract them. Unfortunately, I cannot find any existing tutorials that fit the bill, so here's a set of instructions that I hope will work better.)
- Complete steps 1-4 of the Eclipse Java IDE tutorial. I assume you will be able to find and install Java and Eclipse (which are installed separately); when you choose a Java or Eclipse download, just choose a "Java" version... there's no need for anything fancy like "Java EE".
- Jump into "Part 2: The Syntax" of Brewing Java: A Tutorial, but stop when you get to "Command Line Arguments".
- In Eclipse, try to run the "Command Line Arguments" example, but realize that you'll get an error.
In order to supply run-time data to your program, you'll have to add an argument to run it: right-click on your program and select "Run As...", but then instead of "Java Application" choose "Run...", then click on the "Arguments" tab and fill in something (like your name) and click "Apply".
Now "Run" your program and you should get some good output. - Now you can continue with Brewing Java: A Tutorial. If you get this far, you should be able to do the rest of any other tutorial out there.
Sunday, October 4, 2009
Rubik's Cube Cheat Sheet
I finally sat down and followed instructions to solve a Rubik's Cube. I used Dan Brown's videos, and here is my summary of the instructions... useful for reference until I have them memorized.
(F=turn front side clockwise / U=up side / D=down side / L=left / R=right / i=inverted direction=counter-clockwise)
1) Goal: Top Cross
Move into spot. If flipped, put in front then:
Fi U Li Ui
2) Top Corners
Get them in or under spot, then:
Ri Di R D ... and maybe repeat
Now put the solved side on the bottom.
3 & 4) Middle Corners
Find one not matching now-top color, move by matching side color, then..
... if going left:
Ui Li U L U F Ui Fi
... if going right:
U R Ui Ri Ui Fi U F
5) Cross
If L: put back-left; if line, put horizontal, then:
F R U Ri Ui Fi ... and maybe repeat
6) Match sides
Put one that matches side colors in back and the other to right or front, then:
R U Ri U R U U Ri ... and maybe repeat
7) All Corners in Correct Spots, Possibly Turned
If any in correct spot, put in front-right, then:
U R Ui Li U Ri Ui L ... and maybe repeat
8) Finish
Put any unsolved in front-right, then:
Ri Di R D ... and maybe repeat
... and then Ui for next unsolved piece in front-right and repeat
(F=turn front side clockwise / U=up side / D=down side / L=left / R=right / i=inverted direction=counter-clockwise)
1) Goal: Top Cross
Move into spot. If flipped, put in front then:
Fi U Li Ui
2) Top Corners
Get them in or under spot, then:
Ri Di R D ... and maybe repeat
Now put the solved side on the bottom.
3 & 4) Middle Corners
Find one not matching now-top color, move by matching side color, then..
... if going left:
Ui Li U L U F Ui Fi
... if going right:
U R Ui Ri Ui Fi U F
5) Cross
If L: put back-left; if line, put horizontal, then:
F R U Ri Ui Fi ... and maybe repeat
6) Match sides
Put one that matches side colors in back and the other to right or front, then:
R U Ri U R U U Ri ... and maybe repeat
7) All Corners in Correct Spots, Possibly Turned
If any in correct spot, put in front-right, then:
U R Ui Li U Ri Ui L ... and maybe repeat
8) Finish
Put any unsolved in front-right, then:
Ri Di R D ... and maybe repeat
... and then Ui for next unsolved piece in front-right and repeat
Wednesday, September 16, 2009
"That's Not My Name" lyrics
I finally found the full set of lyrics for "That's Not My Name" by The Ting Tings; I have been especially searching for the words from the guy (Jules) who sings lower underneath at the end, and here they are:
I found them all on this YouTube video page, which Jessi S says is the "official video".
This song was in my head, now it's in my mind,
Call it, reach it, get some words and get some timing,
Though I realize, I cannot emphasize,
I'll stick around, but just a promise, nothing binding,
However can't you see, that you're so desperately,
A standing joker like a vocal one-liner,
Instead of sing-along, this song is monotone,
Gotta get some soul, gotta get some feeling....
I found them all on this YouTube video page, which Jessi S says is the "official video".
Wednesday, July 1, 2009
Consolidating Spreadsheet Lists
I sometimes have to get a list of unique items either by removing duplicates or by pulling the items from two lists (by finding the elements missing from one of them). These are easy to figure when you have the data in a SQL database, but it's a little tougher using only spreadsheet functions. Below are two example approaches.
Update: I just learned about the COUNTIF function that might help; check it out first.
Find the Unique Items
This is like the SQL "SELECT DISTINCT word FROM words"
Find the Elements Missing (when compared to another list)
This is like the SQL "SELECT * FROM words WHERE word NOT IN ('forbidden', ...)"
Update: I just learned about the COUNTIF function that might help; check it out first.
Find the Unique Items
This is like the SQL "SELECT DISTINCT word FROM words"
- Put the list in column A starting in row 1.
- In column B next to each value, paste a function which detects whether the item is a desired one; in this case, it's the last item in each run:
=NOT(EXACT(A1;A2)) - In Column C, put a counter down to each desired element:
=IF(B1; 0; C2+1) - In column D and row 1, paste this function to tell where the first element lies:
=C1 + 1 - In column D in the other rows, paste this function to tell where the next element lies:
=D1 + 1 + INDIRECT(ADDRESS(D1+1; 2)) - In column E in each row, paste this function to tell each unique item in succession:
=INDIRECT(ADDRESS(D1; 1)
Find the Elements Missing (when compared to another list)
This is like the SQL "SELECT * FROM words WHERE word NOT IN ('forbidden', ...)"
- Paste the main list into column B and the sublist into column A.
- In column C, put the function to find the desired one (like step 2 above); in this case, VLOOKUP function to detect if the item from B exists in A:
=ISERROR(VLOOKUP(B1; A$1:A$999; 1; 0)) - The rest of the steps are the same as steps 3-6 above. In column D, we count down to the desired element:
=IF(C1;0;D2+1) - In column E row 1, we put the row of the desired element:
=D1 + 1 - In the rest of column E, we find each element:
=E1 + 1+ INDIRECT(ADDRESS(E1+1;4)) - In column F, we find the value:
=INDIRECT(ADDRESS(E1;2))
Monday, June 22, 2009
Base Test Class with Maven
I've got some base Test classes (with settings for Spring, Wicket, etc) that I want to reuse in my integration tests, and I've put them under a 'test' directory (instead of 'main'), but that means that they don't get built and included in the main artifact. Here's how I forced Maven to build it into a test artifact (in the build/plugins section):
... and here's how I included it as a dependency in the other projects:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
... and here's how I included it as a dependency in the other projects:
<dependency>
<groupId>com.max.services</groupId>
<artifactId>MaxServices</artifactId>
<version>1.0.2-SNAPSHOT</version>
</dependency>
Base Test Class for Spring
When using Spring to configure my web application, I usually want to employ the same XML configuration file as the application, especially for database access. So here is what I currently use as the base class for all my integration test cases.
In addition to those two methods, earlier projects have overridden the 'onSetupBeforeTransaction' method as follows, although I found I haven't had to do this for my plain old integration tests:
However, on my Wicket project, I did have to play around with it a bit, so here is what I created for the 'HomePageTest':
One thing you might have noticed is that JMXSpringMBeanNamingStrategy, so I'll explain real quick: it's to allow me to share the same applicationContext.xml file with all my web app contexts such that the JMX engine won't break due to duplicate names. It's inserted this way:
Here is how it's defined; you can tell that it's not ideal, but it's what I got:
public class ServicesTestBase extends AbstractTransactionalDataSourceSpringContextTests {
private static final String CONFIG_LOCATION = "/context/applicationContext.xml";
@Override
protected ConfigurableApplicationContext createApplicationContext(String[] locations) {
ConfigurableWebApplicationContext appContext = new XmlWebApplicationContext();
// this is org.springframework.mock.web.MockServletContext
MockServletContext servletContext = new MockServletContext();
servletContext.addInitParameter(JMXSpringMBeanNamingStrategy.CONFIG_INIT_PARAM_NAME, CONFIG_LOCATION);
appContext.setServletContext(servletContext);
appContext.setConfigLocations(locations);
appContext.refresh();
return appContext;
}
@Override
protected String[] getConfigLocations() {
return new String[]{ CONFIG_LOCATION };
}
}
In addition to those two methods, earlier projects have overridden the 'onSetupBeforeTransaction' method as follows, although I found I haven't had to do this for my plain old integration tests:
@Override
protected void onSetUpBeforeTransaction() throws Exception {
// this is our own home-grown class which you may not need; source may be available by request
StaticApplicationContext.setContext(this.applicationContext); // Do this BEFORE onSetUpBeforeTransaction()
super.onSetUpBeforeTransaction();
}
However, on my Wicket project, I did have to play around with it a bit, so here is what I created for the 'HomePageTest':
@Override
protected void onSetUpBeforeTransaction() throws Exception {
StaticApplicationContext.setContext(this.applicationContext); // Do this BEFORE onSetUpBeforeTransaction()
super.onSetUpBeforeTransaction();
AuthenticatedWebApplication authenticatedWebApp = new BackOfficeApplication() {
@Override
public void init() {
addComponentInstantiationListener(new SpringComponentInjector(this, HomePageTest.this.applicationContext));
initForAppAndAllTests();
}
};
tester = new WicketTester(authenticatedWebApp);
}
One thing you might have noticed is that JMXSpringMBeanNamingStrategy, so I'll explain real quick: it's to allow me to share the same applicationContext.xml file with all my web app contexts such that the JMX engine won't break due to duplicate names. It's inserted this way:
<!-- (Initially copied from http://static.springframework.org/spring/docs/2.0.x/reference/jmx.html ) -->
<!-- This bean must not be lazily initialized if the exporting is to happen. (comment from docs) -->
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="namingStrategy"><bean class="com.max.utils.JMXSpringMBeanNamingStrategy" /></property>
<property name="beans">
<map merge="true">
<entry key="com.max.services.forWebApp:name=data-source" value-ref="dataSource" />
<entry key="com.max.services.forWebApp:name=log4j-settings" value-ref="log4jBean" />
<entry key="com.max.services.forWebApp:name=test-settings" value-ref="dynamicTestSettings" />
</map>
</property>
</bean>
Here is how it's defined; you can tell that it's not ideal, but it's what I got:
public class JMXSpringMBeanNamingStrategy implements ObjectNamingStrategy, ServletContextAware {
public static final String CONFIG_INIT_PARAM_NAME = "contextConfigLocation";
private ServletContext context;
public void setServletContext(ServletContext _context) {
this.context = _context;
}
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
// There's got to be a better way to get the context name of this app!
String springWebAppConfigFile = context.getInitParameter(CONFIG_INIT_PARAM_NAME);
String configName = springWebAppConfigFile;
configName = configName.replace("classpath", "");
configName = configName.replace("webapp", "");
configName = configName.replace("xml", "");
configName = configName.replace("context", "");
configName = configName.replaceAll("[\\:\\/\\.\\-]", "");
String newBeanKey = beanKey.replaceFirst("forWebApp", configName);
return new ObjectName(newBeanKey);
}
}
Subscribe to:
Posts (Atom)