When I start to feel angry at my wife and I see an argument brewing, I often stop to ask myself "what is the cost of the argument, and is it worth the cost?" Generally, when I look at it this way, I discover it's not. So often, the underlying issue is something trivial, and the damage done by the argument can be enormous, especially if it escalates.
Sometimes I try to think of some way of addressing an issue without turning it into an argument. For example, the other day I noticed that my wife had not cleaned the pans she had used to cook her breakfast, leaving them for me to deal with (again). I thought about confronting her directly, but whenever that happens, she immediately twists it to be about something she had done for me, making me into an ungrateful dick. So instead, I took a sideways tack. As I was cleaning the kitchen I looked over at the pans and said "didn't I just clean those yesterday?" Somehow, that got the point across without it becoming an argument.
Thursday, November 13, 2014
Wednesday, September 10, 2014
Determining keyboard modifiers (like Shift-Click) on a Wicket AjaxLink
If you want to determine if a user issued, say, a shift-click on an AjaxLink in Wicket 6, here's how you do it:
1) Add pass the keyboard state from javascript to the onClick function,via DynamicExtraParameters
2) Get the passed value in the onClick callback via the RequestParameters
Here's some sample code:
add(new AjaxLink("my-link") {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getDynamicExtraParameters()
.add("return {shiftKey: attrs.event.shiftKey};");
}
@Override
public void onClick(AjaxRequestTarget target) {
boolean shiftKey =
RequestCycle.get().getRequest().getRequestParameters().
getParameterValue("shiftKey").toBoolean();
if (shiftKey) {
....
}
}
};
1) Add pass the keyboard state from javascript to the onClick function,via DynamicExtraParameters
2) Get the passed value in the onClick callback via the RequestParameters
Here's some sample code:
add(new AjaxLink("my-link") {
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getDynamicExtraParameters()
.add("return {shiftKey: attrs.event.shiftKey};");
}
@Override
public void onClick(AjaxRequestTarget target) {
boolean shiftKey =
RequestCycle.get().getRequest().getRequestParameters().
getParameterValue("shiftKey").toBoolean();
if (shiftKey) {
....
}
}
};
Wednesday, October 16, 2013
The Tea Party's Beer Hall Putsch
Every revolution has it's seminal events: The Beer Hall Putsch in the Nazi's rise to power, or the Tennis Court Oath in the case of the French Revolution. When the history of the Tea Party is told, the Debt Ceiling Crisis will be one of these events. Like the Beer Hall Putsch, the clash will end in failure for the revolutionary party, and like the Beer Hall Putsch, the failure will be used as a spring board for Ted Cruz.
This has been Ted Cruz's strategy all along. He didn't really expect to get Obama to cave. It was always more likely that the Debt Ceiling Crisis would end in a useful failure. Boehner will bring a senate bill to a vote which will pass with votes from all Democrats, and a few turncoat Republicans. The battle lines will be drawn. The Tea Party will go after the turncoat Republicans, including Boehner. Tea Party challengers run to the right of the turncoat Republicans in 2014. The remaining Republicans align themselves with the Tea Party out of fear. If the plan succeeds, Ted Cruz emerges as speaker of the house, with an eye on the White House.
The revolutionary event that the Tea Party is supposed to bring to mind is, obviously, the Boston Tea Party. That itself leads credence to Krugman's assertion that this is a revolutionary movement. They are trying to overthrow the government, one way or another, and they don't care how much damage they cause in the process. They think of themselves as American heroes. I think they are traitors, and Ted Cruz is their demagogue.
This has been Ted Cruz's strategy all along. He didn't really expect to get Obama to cave. It was always more likely that the Debt Ceiling Crisis would end in a useful failure. Boehner will bring a senate bill to a vote which will pass with votes from all Democrats, and a few turncoat Republicans. The battle lines will be drawn. The Tea Party will go after the turncoat Republicans, including Boehner. Tea Party challengers run to the right of the turncoat Republicans in 2014. The remaining Republicans align themselves with the Tea Party out of fear. If the plan succeeds, Ted Cruz emerges as speaker of the house, with an eye on the White House.
The revolutionary event that the Tea Party is supposed to bring to mind is, obviously, the Boston Tea Party. That itself leads credence to Krugman's assertion that this is a revolutionary movement. They are trying to overthrow the government, one way or another, and they don't care how much damage they cause in the process. They think of themselves as American heroes. I think they are traitors, and Ted Cruz is their demagogue.
Thursday, May 2, 2013
Wicket + SSL + Nginx
I just fought a battle with technology, getting Wicket + SSL + NGINX to play well together, so I thought I'd document the procedure for the next poor soul who needs to do this.
My goal is to use NGINX as a proxy in front of wicket, where NGINX is responsible for https decryption. Thus NGINX is responsible for decrypting the data and passing it along to Wicket.
Configuring NGINX to serve up HTTPS is pretty easy. I'll just describe that briefly here.
Get an SSL cert from godaddy, download the zip file for "apache", concatenate the key, crt, and gd_bundle.crt into a single file, let's say: cert.pem, then set up something like the following in the /etc/nginx/nginx.conf file:
# HTTPS server
#
server {
listen 443;
server_name www.ggrocer.com;
ssl on;
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://www.ggrocer.com;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect http:// http://;
}
}
upstream www.ggrocer.com {
server 127.0.0.1:9090;
}
The X-Forwarded-For may not be needed for this case, but the X-Forwarded-Proto is. This tells NGINX to add the HTTP header X-Forwarded-Proto to the http request that is forwarded to Wicket.
The proxy_redirect is also important. I spent hours trying to figure out why, when viewing a non-secure page under HTTPS, the browser was going into a redirect loop. What happened was this: if @RequireHTTP is not set on a page and the request is HTTPS, then wicket forces a redirect to HTTP. NGINX then rewrites the LOCATION in the HTTP Response to the browser to be HTTPS. Rinse and repeat. Via the proxy_redirect setting, it's possible to prevent NGINX from rewriting the redirect URL.
With this configured, NGINX will listen to https traffic on port 443, decrypt it, and pass it on to my app, which is listening on 9090.
In the Wicket App, pages (and components) can be marked as requiring HTTPS via the annotation:
@RequireHTTP
on the page class. This is well documented elsewhere.
The following bits were not well documented however.
To get Wicket to honor the X-Forwarded-Proto header (i.e. to recognize that the request was HTTPS, even though it was already decrypted by the time it hit Jetty, two things are required:
1) In your Wicket Application's init method, add:
getFilterFactoryManager().addXForwardedRequestWrapperFactory(null);
2) To tell wicket attribute to use the "X-Forwarded-Proto" parameter, add a protocolHeader init-param to your web.xml like the following:
<filter>
<filter-name>wicket.ggrocer</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.ggrocer.site.GGrocerApp</param-value>
</init-param>
<init-param>
<param-name>protocolHeader</param-name>
<param-value>X-Forwarded-Proto</param-value>
</init-param>
</filter>
My goal is to use NGINX as a proxy in front of wicket, where NGINX is responsible for https decryption. Thus NGINX is responsible for decrypting the data and passing it along to Wicket.
Configuring NGINX to serve up HTTPS is pretty easy. I'll just describe that briefly here.
Get an SSL cert from godaddy, download the zip file for "apache", concatenate the key, crt, and gd_bundle.crt into a single file, let's say: cert.pem, then set up something like the following in the /etc/nginx/nginx.conf file:
# HTTPS server
#
server {
listen 443;
server_name www.ggrocer.com;
ssl on;
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://www.ggrocer.com;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect http:// http://;
}
}
upstream www.ggrocer.com {
server 127.0.0.1:9090;
}
The X-Forwarded-For may not be needed for this case, but the X-Forwarded-Proto is. This tells NGINX to add the HTTP header X-Forwarded-Proto to the http request that is forwarded to Wicket.
The proxy_redirect is also important. I spent hours trying to figure out why, when viewing a non-secure page under HTTPS, the browser was going into a redirect loop. What happened was this: if @RequireHTTP is not set on a page and the request is HTTPS, then wicket forces a redirect to HTTP. NGINX then rewrites the LOCATION in the HTTP Response to the browser to be HTTPS. Rinse and repeat. Via the proxy_redirect setting, it's possible to prevent NGINX from rewriting the redirect URL.
With this configured, NGINX will listen to https traffic on port 443, decrypt it, and pass it on to my app, which is listening on 9090.
In the Wicket App, pages (and components) can be marked as requiring HTTPS via the annotation:
@RequireHTTP
on the page class. This is well documented elsewhere.
The following bits were not well documented however.
To get Wicket to honor the X-Forwarded-Proto header (i.e. to recognize that the request was HTTPS, even though it was already decrypted by the time it hit Jetty, two things are required:
1) In your Wicket Application's init method, add:
getFilterFactoryManager().addXForwardedRequestWrapperFactory(null);
2) To tell wicket attribute to use the "X-Forwarded-Proto" parameter, add a protocolHeader init-param to your web.xml like the following:
<filter>
<filter-name>wicket.ggrocer</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.ggrocer.site.GGrocerApp</param-value>
</init-param>
<init-param>
<param-name>protocolHeader</param-name>
<param-value>X-Forwarded-Proto</param-value>
</init-param>
</filter>
Sunday, May 6, 2012
The Purpose of Education
It seems to me that in an earlier age, higher education served a higher purpose. There were trade schools, which trained the lower classes the skills needed for skilled labor, but for the upper class, education had a broader mandate: to teach the student how to live.
Granted, the upper reaches of academia were reserved for the sons and daughters of the upper crust, and those in that situation, through birth and connections, were assured of a good position on graduation, so long as they did nothing to blatantly indicate unfitness. And so preparation for a job, per se, was not entirely necessary. Instead, one learned the classics, and received a deep and thorough grounding in literatures and philosophy. An undergraduate education provided the breadth, and graduate school provided the depth in a specific field of choosing.
It seems to me that in recent years, the point of undergraduate education has shifted. There is no longer an aim to teach the student how to live, and how the world works. Instead, it is all about job preparation. In a sense, we are now all in trade school.
From kindergarten through college, the focus is on getting a job. And while becoming a productive individual is certainly of value to society, I wonder if something has gotten lost in the process.
I encounter too many educated people these days who haven’t learned to think logically. Too many who cannot write clearly. An inability to write clearly is, I believe, an inability to think clearly. For what is thought made of, but words?
At a dinner party the other night, I heard a contradictory perspective. A friend who had graduated with a liberal arts degree (I don’t know, off hand, in what subject) was bemoaning the difficulties she has had in life due to the fact that college did not prepare her for any specific job.
There must be a balance. At the risk of raising the bar for new graduates, perhaps there needs to be a new standard. Perhaps the master’s is the new bachelor’s. Perhaps undergraduate education should be about establishing that grounding in the humanities -- that is, what it is to be a human. And graduate school should be about depth in a particular field.
Granted, the upper reaches of academia were reserved for the sons and daughters of the upper crust, and those in that situation, through birth and connections, were assured of a good position on graduation, so long as they did nothing to blatantly indicate unfitness. And so preparation for a job, per se, was not entirely necessary. Instead, one learned the classics, and received a deep and thorough grounding in literatures and philosophy. An undergraduate education provided the breadth, and graduate school provided the depth in a specific field of choosing.
It seems to me that in recent years, the point of undergraduate education has shifted. There is no longer an aim to teach the student how to live, and how the world works. Instead, it is all about job preparation. In a sense, we are now all in trade school.
From kindergarten through college, the focus is on getting a job. And while becoming a productive individual is certainly of value to society, I wonder if something has gotten lost in the process.
I encounter too many educated people these days who haven’t learned to think logically. Too many who cannot write clearly. An inability to write clearly is, I believe, an inability to think clearly. For what is thought made of, but words?
At a dinner party the other night, I heard a contradictory perspective. A friend who had graduated with a liberal arts degree (I don’t know, off hand, in what subject) was bemoaning the difficulties she has had in life due to the fact that college did not prepare her for any specific job.
There must be a balance. At the risk of raising the bar for new graduates, perhaps there needs to be a new standard. Perhaps the master’s is the new bachelor’s. Perhaps undergraduate education should be about establishing that grounding in the humanities -- that is, what it is to be a human. And graduate school should be about depth in a particular field.
Wednesday, April 18, 2012
Why the federal government should invest in cities
There are many reasons why Obama, in his second term, should start investing heavily in cities.
1) WPA 2.0
There are many WPA style projects that could really benefit the unemployed, while also benefiting cities. These projects would put people to work, and help rebuild the economy while also strengthening our cities.
2) Why cities?
Because that's where 80% of the people live, and that's where the wealth is created.
Also, it is more environmentally friendly (ironically) to centralize people in cities, rather than having them spread out in suburbs or in the countryside. Leaves more open space for the critters.
3) A couple projects that come to mind:
a) Put cables Underground
Already some neighborhoods (mostly the rich ones) have their cables underground. But this should be done throughout all our cities. Federal money could be put towards this effort. All neighborhoods would become more beautiful. This would help attract people to cities, and retain them there (rather than fleeing to the burbs).
b) More smart traffic signals
A hybrid vehicle recycles energy from braking. But all cars, hybrid and non, would be even more efficient if they could avoid needless stops. Smart traffic signals would both improve traffic flow, and provide better fuel economy.
c) Free public transportation
Think how many more people would take public transport if it were free. One may ask: how can a city afford this? The same way it affords to pave streets, and man the fire department. Taxes. However by making public transport free, there will be less traffic and parking congestion, and the increase in people living in the city (because it's a more attractive place to be, what with the underground wires and free public transport) will provide a larger tax base with which to fund free public transport. I once heard Gavin Newsom propose this idea, and it blew my mind.
I hope these are the sort of things Obama does in his second term. That would be a great legacy.
Saturday, November 12, 2011
Obama should grow a pair
I recently read that President Obama bemoaned the fact that he had not done a better job of reaching across the aisle to build a stronger bipartisan relationship with the Republicans in the Senate. Echos of Neville Chamberlain. Does he really believe that this was remotely possible? The Republican party has become so self serving... their ONLY goal is power, at the expense of America. It's ok if the economy suffers -- in fact, all the better if it does, because American suffering increases their chances of regaining power. I suspect De Toqueville had something to say about this.
I wish Obama would lay the blame for the troubled economy where it belongs:
a) Deregulation of finance
b) The Bush tax cuts
c) The Bush wars in Iraq and Afghanistan
Forget the olive branch. It's time for bare knuckles politics, Chicago style. Something that Barack knows a thing or two about.
I wish Obama would lay the blame for the troubled economy where it belongs:
a) Deregulation of finance
b) The Bush tax cuts
c) The Bush wars in Iraq and Afghanistan
Forget the olive branch. It's time for bare knuckles politics, Chicago style. Something that Barack knows a thing or two about.
Subscribe to:
Posts (Atom)