17 March, 2011

Recover Mail.app after crash

Occasionally Mail.app tends to crash and after re-opening it all mail accounts are gone. It asks you to create new account to process. I hate when that happens. For the next time (hope it never comes) here's the solution:


sahver-mbp:Preferences martinkoppel$ pwd
/Users/martinkoppel/Library/Preferences

sahver-mbp:Preferences martinkoppel$ ls -la com.apple.mail*
-rw------- 1 martinkoppel staff 580 Mar 17 13:41 com.apple.mail.plist
-rw------- 1 martinkoppel staff 23285 Mar 16 18:09 com.apple.mail.plist.J6LEOAb


To recover all you need to do is:


sahver-mbp:Preferences martinkoppel$ mv com.apple.mail.plist com.apple.mail.plist.backup
sahver-mbp:Preferences martinkoppel$ mv com.apple.mail.plist.J6LEOAb com.apple.mail.plist


.. and now its safe to start Mail.app again.

18 November, 2009

Web and RTL languages

One day you may be facing the fact that you have to deal with RTL language support on your web page. I'm not writing how to do it, you can google about it. Instead, I'm giving you a hint that does not pop out of google that easily:

In case of RTL there are still some texts that need to be kept LTR: company names, numbers etc. I suggest you to surround these texts with special characters in your HTML code:


‭‭myLTRtext in RTL language‬


Where:
‭‭ - left-to-right override
‬‬ - pop directional formatting (a formatting character that cancels a previous bi-directional formatting character on the same line in plain text)

More info on more of these special characters can be found:
https://listserv.heanet.ie/cgi-bin/wa?A2=ind9605&L=HTML-WG&F=P&P=4668

Without these surrounding markers I've personally experienced some really strange layout bugs in IE.

10 November, 2009

Command line Spring application configuration

This is basically just a reminder for myself, no I wouldn't have to "invent" it all over again. Most of the time I'm writing web application but occasionally have need for command line app. To keep it simple and clean, here is the application-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<context:annotation-config />
<context:component-scan base-package="ee.myapp.commandline" />

<context:property-placeholder location="classpath:application.properties" />

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}"/>
</bean>
</beans>


And here is the main class to run it all:

public class CLI {
public static void main(String[] args) {
GenericApplicationContext context = new GenericApplicationContext();

ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
// scan for properties file
scanner.scan("conf");

BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions("application-context.xml");
context.refresh();
}
}



That way Spring nicely initialize all the bean defined in context and also load property placeholder and does annotation based component scan.

16 October, 2009

Serial Port Magic vol.3 (controlling pins)

Data is not the only thing that can go through serial port. Actually serial port can output some currency (3.. 12V or -3.. 12V) - getting interesting, hah! To look it a little closer you probably need multimeter to measure currency coming out of serial port pins.

I'm not going into detail to tell you what this and this pin is for. I have chosen DTR (Data Terminal Ready, nr.4) pin to play with - just look it up from picture. And you also have to look for Signal Ground - pin nr. 5. Those are the pins you're going to user to measure currency. For my Mac it is -6.3V. To change it to 6.3V you need couple of lines of code and to compile it. Now from command line just run
> ./setSerialSignal /dev/tty.usbserial 1 0
and the you go again. I haven't yet figured out how to use it, but thats a start all right.

Serial Port Magic vol.2 (loop-back cable)

Probably for now you have been surfing through entire Internet looking for way to emulate serial device. But the truth is - there is not common way to do it with software only. You have to do it hard way. And it's gonna cost you a little (10-15EUR).

To make a loop-back cable, first you need to go shopping for some stuff:
  1. USB/RS-232 adapter (TrendNet TU-S9) - works for Mac
  2. RS-232 female plug
  3. couple of inches thin wire



On the picture you can see the solution that worked for me. Just connect pins 2-3 and 7-8, you don't even need 1-4 but do it anyway. For testing ZTerm is good for Mac or what ever terminal client you like. Every thing is clear so far - good.

Not the thing with serial port is that two different applications try to read from is simultaneously, then only one of them actually receives the data and it's not guaranteed which one. Java library uses locking technic to allow only one app to access serial port. For my Mac locking files are located at /var/lock. Every time java app. opens serial port, it creates locking file into that folder and removes it after port is closed. To make one app to read from and another to write into serial port, what you do is first start reading app., then delete locking file and after that run you serial port writer. Simple, right!?

Serial Port Magic vol.1 (programming)


At some point you will have a need to do some hardware programming and thats where you meet Serial Port (RS-232). Don't be afraid - that doesn't necessarily mean low level C/C# coding. There are plenty of higher level API's for Java (java.comm and rxtx) and even for PHP and Python. So, let me tell you how to get started.

I have tried out RxTx library and it worked perfectly. Just follow the instructions on their wiki page and you should be pretty much safe. There are also some code samples that you could use. Couple of things you might run into are:
  • make sure you have RXTXcomm.jar in your classpath!
  • also make sure lock file directory has a writing access
And there you go. Simple as 1-2-3 :)

06 April, 2009

VirtualHost on Leopard

Here's how I created a virtual host on my Mac OS X 10.5.x.
1. Start with 'hosts' file, might be located at /private/etc/hosts. Add following line:
127.0.0.1    your.virtual.host

2. Add virtual host to Appace. Open file /private/etc/apache2/extra/httpd-vhosts.conf and add:

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<virtualhost *:80 >
DocumentRoot "/Users/username/Sites/mark-kirby"
ServerName mark-kirby.dev
</virtualhost>