Showing posts with label solutions. Show all posts
Showing posts with label solutions. Show all posts

Saturday, December 03, 2011

configure boxee to work as a second monitor with sound over hdmi

My HTPC setup is simple:
I ran a 40 foot HDMI cable from my computer room into my bedroom through the basement. I hooked up my TV in the bedroom to be the 2nd monitor on my PC and set boxee to run on that monitor.

The problem:
I wanted to have Boxee use sound over hdmi, but also be able to listen to to music and play games on my computer as usual without the sound coming from the bedroom TV.

Solution:
In your windows sound prefs set:
  • "Speakers" as your default audio device
  • "HDMI digital output" as your default communication device
In boxee sound config set:
  • primary soundcard: HDMI digial sound
restart boxee. Now you should be able to hear HDMI sound only on the TV, and all other sound will come from your speakers. 

Thursday, March 24, 2011

manually set id of grails domain object

Problem:
if you create a new domain object and set its id in the constructor like this:
Cat catman = new Cat(id:1000, name: "catman", kind: "domestic short haired")
later, if you look at the object the id will be null. what gives?!


Solution:
Its madness, but it works to assign the id after the object is made. Just add
catman.setId(1000);
and you are in business.

Note: if you want to save the object into db after doing this, you must set the id generator to 'assigned'

Monday, February 21, 2011

Class needed by SvnTask cannot be found

problem:
getting this error when trying to build:

taskdef A class needed by class org.tigris.subversion.svnant.SvnTask cannot be found: org/tigris/subversion/svnclientadapter/SVNClientException

solution:

I didnt unzip all libs that came with svnant into my lib folder. Only unzipped svnant.jar. need to put them all in there.

Monday, November 29, 2010

fixing java.lang.NoClassDefFoundError: javax/el/ELContext error

I got the error java.lang.NoClassDefFoundError: javax/el/ELContext  when i was trying to run a unit test.

Solution:
el-api.jar needs to be in your class path. This is usually found in the tomcat/lib dir. I usually add everything in the tomcat lib to my classpath

Tuesday, October 26, 2010

No Hibernate Session bound to thread

Problem:
I am converting an application that uses HibernateDaoSupport in the DAOs to use POJOs instead.
Each pojo now must autowire a sessionFactory in order to hook into hibernate.

I am getting the following error when i try to getSession() on my sessionFactory:


No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

Solution:
add a OpenSessionInViewFilter to my web.xml and filter on * with it

Tuesday, August 24, 2010

Waiting for things in javascript

Problem:
Sometimes i need to wait for something to come into existence in javascript, and then do something with it. This is usually because another frame (shudder) is still loading and i need something in it. Also it helps with IE bugs where something should be there, but isn't because IE is taking a stupid long time to load it.

Solution:

Use this utility function to create a check/act loop.

Tuesday, June 29, 2010

IE8: content-disposition:inline, opens as download

Problem:
We just had a pretty weird problem. Internet Explorer 8 decided to open some links as downloads instead of just navigating to the files as per usual. All normal browsers did not have this problem. I immediately checked the headers which revealed nothing out of the ordinary:

Server: Apache-Coyote/1.1
Cache-Control: public
Expires: Thu, 12 Jul 2012 19:13:38 GMT
Pragma: Thu, 12 Jul 2012 19:13:38 GMT
Content-Disposition: inline; filename="Recipe_Details_Attachments.htm"
Content-Type: text/html
Content-Encoding: gzip
Vary: Accept-Encoding
Date: Tue, 29 Jun 2010 19:13:38 GMT
Connection: close 
 
The Content-Disposition: inline; part tells me that the browser should not open this as a download.

Solution:
My coworker who i now owe 6 beers suggested that because of IE's stupidity it is looking at the entire Content-Disposition line, and doing substring matching on first 'attachment' and then 'inline'. He was correct. IE stupidly saw this line as basically Content-Disposition:attachment;

The fix was to change the filename to something that did not include 'attachments'.

Thursday, June 03, 2010

Disabling an input is slow on IE

So we ran into a problem today where disabling a massive amounts of inputs was really slow in IE8. It would take several seconds to disable 200 inputs. Caching the DOM elements in an array did not seem to help much. Setting the actual html attribute was the slow part.
My coworker came up with a pretty great IE hack to speed up the process of disabling and enabling the inputs:


faking it turns out to be faster then doing it the real way.

Saturday, April 24, 2010

Migrating to syntaxhighlighter 2.1.x

Problem:
I recently decided to upgrade to syntaxhighlighter 2.1 from 2.0 on my blogger blog. I thought it was going to be as easy as dropping in a new version. I was wrong, the TEXTAREA in which i was putting my code is no longer supported. instead SCRIPT tags are used to enclose the code! AHHH! I have about 40 code snippets on my blog and conversion seems very not-fun.

Solution:
I started to hand convert some of the entries, to find that the new blogger post editor was also losing all of my tabs! This was going to be painful to do by hand..
Alas, i decided to try to do it with javascript, and it worked!

I pulled in the latest jquery into my template to ease the pain. Instead of the regular synataxhighlighter init i now have this:



Now, i dont need to hand convert all of my textareas to the new format, and the tabs are saved. Good deal!

Friday, April 23, 2010

Populate a DTO with mock data

Problem:
Every so often i need to have a list of some simple DTOs in order to build a screen. The DTOs need to be populated from the database, but the query is not ready. Its somewhat painful to write dummy data creation methods over and over again.

Solution:
Using Groovy(though not required), Spring and a bit of reflection i cover most of the simple DTOs.



To use, pass the class a list of which you expect

Wednesday, January 27, 2010

SQL: describe a select statement instead of table

Problem:
QA asked me to put max lengths in input fields that would map to values that would eventually be inserted into the Oracle database. The problem was that these values were not going into a single table, but about 10 different tables, which were defined by a complex select statement. I didnt want to describe each individual table to find out the max lengths on the column names

Solution:
Take the complex SQL statement and create a view with it:


Then describe the view, and drop the view when you are done with it.

Friday, January 22, 2010

IBatis: Iterate over multiple lists at the same time

Problem:
I needed to verify if each record passed several rules, where each rule consisted of several flags and their values. The problem was complexity: I had 7 flags(which had 3 possible values) to check, and 1 to 5 rules per status. This could lead to some ugly and hard to test SQL.

Another problem was that you cant iterate over multiple lists at the same time (using the same index) in ibatis.

Solution:
The solution was to use Ibatis's Iterate directive. I would iterate over lists of maps, where each map represented a rule, and each bucket of the map represented a flag and its expected value.

Those iBastis code ended up looking something like this:


and the parameter class had the following code:



This worked pretty well to abstract the flags and rules away from the iBatis sql and keep them all in the rules class.

Wednesday, December 16, 2009

JdkDynamicAopProxy ClassCastException

Problem:
I am suddenly getting an error after some spring config was changed:

java.lang.ClassCastException: $Proxy47 cannot be cast to com.mycompany.MyConcreteClass

The code looks like this:
MyConcreteClass myClass = (MyConcreteClass) model.get("myClass");

I should add that MyConcreteClass was autoWired with spring elsewhere, and this setup used to work until something was changed in spring config.

Solution:
This is happening because we are casting to the concrete implementation, what needs to be done is that the object needs to be cast to the interface:
MyInterface myClass = (MyInterface) model.get("myClass");

Also, the relevant spring configuration that causes this issue is:

<tx:annotation-driven manager="springTransactionManager" ></tx:annotation-driven>

In order for the proxy to not proxy the interfaces but concrete classes, you need to add the following attribute to the above directive:
proxy-target-class="true"

Wednesday, August 12, 2009

Readynas: insufficient system resources exist complete requested service

Problem:
Whenever i try to access my readynas nv+ shares from any computer, i get the following error message:
insufficient system resources exist complete requested service
All of my computers have plenty of free memory, hard disk space, etc. The problem is clearly the NAS. Googling leads me to believe that the NAS is returning a malformed response to windows and so windows gives this incorrect error message.

Moreover, i can still log into frontview, and ssh in.

Solution:
Recently i was playing around with the NAS, i installed the addon that gave me root and installed some programs in the root directory /root. One of those programs misbehaved and filled up my root partition with some data. I sshed in and checked diskspace:
df - k
This showed me that the root partition was indeed at 100%. This is the problem, to solve it i needed to delete the big files that were taking up all the space. I used the method i previously wrote about to find the big files and remove them. After i was finished, root was at 46% full. i rebooted the NAS and the problem went away.

Friday, July 31, 2009

Intellij Tomcat Configuration Already Run

Problem:
I have a debug tomcat configuration that i always use. Recently i started having a problem where after killing tomcat, and trying to run it again, i would get the error title "Configuration Already Run" which said "Run configuration 'tomcat local' has been already run. Do you want to redeploy it?". Clicking both yes and no buttons didnt do anything. Tomcat was not re-run.

(i am using tomcat 6, and intellij 8.1.3)

Solution:
This seems like an intellij bug. Confirm that tomcat is really dead by running this at the command line:
taskkill /F /IM tomcat6.exe

If that doesnt fix it, proceed with the workaround:
Open the debug tool panel in intellij, and locate the close button, its a red X above the help button, which is a question mark, its on the left side of the screen. Press the close button to close the debug tool panel. Start the debug tomcat, it should run now.

Friday, June 26, 2009

checkbox margins in IE incorrect

Problem:
By default, checkboxes have some margin and perhaps padding so they take up a bit more space than is needed. I needed to make some checkboxes take up the least amount of space possible, and the following css:

input {
margin:0;
padding:0;
}


didnt work in IE6 and IE7, while working perfectly in firefox (as usual).

Solution:

Add the following IE only css:

<!--[if IE]>
<style type="text/css">
input {
margin: -5px;
}
</style>
<![endif]-->


This fixes the problem on IE6, and IE7, i dont know if IE8 has this problem or not.

Monday, June 22, 2009

Scroll bars not working and MSThemeCompatible

I recently had a problem where scroll bars were not working properly when windows XP was themed in the default theme (not classic). The scroll bar would not move if one used the arrows, or clicked in the area between the bar and the arrows. It could still be used by dragging it up and down.

The weirdest part of this issue was that the scroll bar worked normally in the windows 'classic' theme, but would seize to function correctly if you switched themes over to the ugly blue default theme.

I should also add that this scrollbar was part of a javascript widget where its position determined position of another DIV in the widget.

Solution (Hack):
Before i found the proper solution i came with a hack - on page load, add 1px to the width of the scrollbar and change its css left to -1px like so (this is jQuery):

$scrollY.css({"position":"relative", "left":"-1px"});
$scrollY.width($scrollY.width() + 1);

This seemed to work for some reason, the scrollbar works after this is applied.

Solution:
I later stumbled on another solution that didnt smell like such a hack, but i am not sure what side effects it has other then making the scrollbar work. The solution is to set an a meta tag in IE only (because firefox has a bug with this metatag):

Friday, May 15, 2009

HTML forms - Things you should know

This is a list of things every web developer should know about forms. I didnt know these things, and thus wasted many hours banging my head against the desk. Hopefully this post will save someone else that time.

1. Disabled inputs are not submitted.

The HTML spec defines that only 'successful' controls's values will be sent in the form on submit. disabled controls arent 'successful' and are not submitted. If you want to submit a disabled control you will have to either:
  • Enable it right before submitting the form, and then disable it.
  • Copy its value into a hidden input before submit

2.
A form with only 1 text input will submit on enter in that input.

This is another little gem from the HTML spec that drove me nuts for a while. I couldnt figure out why the form was submitting on enter in an input type='text' when no key handlers were attached to the input, what was worse, my on submit validation was skipped. It turned out that if a form has a single input of type 'text' then pressing enter in this input will submit the form. To get around this you must:
  • Add another input of type text and hide it with css

3.
Internet exporer will not submit a form if it contains a file chooser with an invalid file path.

This is a fun one. IE does some rudementary form validation for you, and if it finds that you have selected a file which does not exist, it will not let you submit the form. This by itself is not a bad thing, but what is bad, is that it does not let the user, or the programmer know that the form was not submitted. As a UI programmer, I want to have an error message if the form submition fails, but I have no way of knowing it. To get around this you must:
  • Validate the path yourself using regex, and try to find invalid file paths, and raise error yourself before IE
  • Copy the value of the filechooser into a hidden input, disable the file chooser, and deal with invalid paths in serverside validation.(wont work as pointed out)

Form submitted unexpectedly on enter

Problem:
I have a form that would be submitted when i pressed enter in a text input field. It would skip over all my validation that i was doing in the input's onKeyDown callback function. I removed the onKeyDown event handler, and still the form would be submitted on enter. The input was not a submit type input so the submission was not expected.

Solution:
This problem stemmed from the fact that the input box in question was the only text type input box on the form. The HTML4 spec states that if you have one input box of type text, pressing enter in this input box will submit the form!

I solved this by adding another input of type text with style="display:none" and a name:

<input type="text" style="display:none" name="dummyinput" value="" id="dummyinput" >

The reason for this hack being that I had bound on-enter handlers to the first inputfield of my own, and trying to prevent those would break my code also.

Thursday, March 12, 2009

ST31000333AS disk size incorrect. 31MB

Problem: Today after rearranging the hard drives in my case, i noticed that my 1TB seagate drive was not coming up, instead i had a 32MB non-formatted drive. Checking the drive's hardware shows that it was indeed my 1TB ST31000333AS seagate barracuda. I tried changing the sata ports, and also ran it in an external usb enclosure. Drive size was reported as being 32MB by the bios and windows at all times. Seatools for windows did not show any problems with the drive.

Solution: I downloaded seatools for dos (direct link to eng iso), and burned it to a bootable cd. Booted to seatools and using advanced options set the drive capacity to MAX. rebooted, checked bios, drive was again 1TB. windows was able to detect and restore my drive letter, and files. I am happy.