Wednesday, January 4, 2017

Starting with Arduino

If you are just starting your Arduino journey, this could be a good place to start. As part of my job as a Senior Developer, I held an internal workshop for the IT department where Developers, Architects, Project managers, Devops and others could come and learn what you can do with Arduino. This resulted in a powerpoint presentation plus a number of guides I made to ease getting started. Please do comment if you find these useful, and if you have any additions, let me know! Enjoy.

Thursday, February 26, 2009

[VPN] How to install Cisco VPN client on Ubuntu

Here is a quick guide on how I set up Cisco VPN client.
  1. Install the "patch" tool if you haven't done already, eg. run "sudo apt-get install patch".
  2. Download the client: http://tuxx-home.at/vpn/Linux/vpnclient-linux-x86_64-4.8.01.0640-k9.tar.gz to whatever location.
  3. run "tar zxvf vpnclient-linux-x86_64-4.8.01.0640-k9.tar.gz"
  4. Go to the new dir, eg. "cd vpnclient"
  5. Download the patch that matches your kernel into the directory where your vpn client was extracted. In my case: http://projects.tuxx-home.at/ciscovpn/patches/vpnclient-linux-2.6.24-final.diff
  6. Run "patch < vpnclient-linux-2.6.24-final.diff" in the directory where you extracted the vpnclient.
  7. Install the vpnclient by running "sudo ./vpn_install" and follow the instructions.
  8. Start the vpn client: "sudo /etc/init.d/vpnclient_init start"
After installation you can add the VPN profiles you need (pcf files) to the cisco profile directory "/etc/opt/cisco-vpnclient/Profiles/".

Once everything has been set up, use "sudo vpnclient connect <your-vpn-profile>" to connect to the VPN.

That's it!

Enjoy!

Tuesday, January 6, 2009

[CVS] How to overwrite all files in HEAD/TRUNK with all files from a BRANCH.

If you are using CVS and have a branch that contains whatever code is in production, and you use HEAD/TRUNK for future development, you can sometimes end up in situations where you really want to overwrite whatever is in HEAD/TRUNK with the latest production version from your BRANCH.

In this and many other cases the following might come in hand...

The bottom line is that you need to execute the following four cvs commands:
Reset sticky tag:
   cvs up -A <Filename>
Update from branch:
   cvs update -r<YourBranchName> -p <Filename> > <Filename>
Add uncommitted files:
   cvs add <UnCommmittedFilenames>
Commit changes:
   cvs commit

In case that wasn't enough for you, here's a little more info that I hope will be understandable... Otherwise, just ask!

Preconditions:
- Run UNIX bash shell... :)
- filenames and pathnames can contain spaces (as the bash "for" will split the filename into separate files).
- Two directories exist, one with the development HEAD/TRUNK version called "/home/me/myproject_head" and one with the production BRANCH called "/home/me/myproject_branch".
- No new directories have been added/removed. If you have added or removed any directories you need to modify the bash commands below with something like "mkdir -p $i" (also remove the filename from $i) for creating the directories that doesn't exist.

Start out by removing all the files you have in your HEAD/TRUNK directory
for i in `find /home/me/myproject_head -type f \
   | grep -v CVS`; do rm $i;\
   done;

In the above case, I've added a grep -v for "CVS" as all files/directories containing this name should be excluded from the deletion, since we need these files if we later on want to commit (and we do!).

Now copy all files that you want to replace from the BRANCH directory to the HEAD directory.
Start out by running a "cd /home/me/myproject_branch".
for i in `find . -type f \ 
   | grep -v CVS | grep -v "org.eclipse" \
   | cut -b 3-`; do \
   cp /home/me/myproject_branch/$i `echo "/home/me/myproject_head/$i"`; \
   done;

In this case i have chosen not to copy the CVS directories (a MUST), however I've also chosen to exclude the org.eclipse from the copy, as I have directories that are eclipse specific that I don't want to copy. You can add more " | grep -v partialname" if you wish.

So, now we can work on the new files with the old cvs structure.

First we need to make sure no sticky tags exist:
for i in `find /home/me/myproject_head/ -type f \
   | grep -v CVS | grep -v "org.eclipse"`; do \
   cvs up -A $i; \
   done;

Then we replace the files in HEAD/TRUNK with the ones from the BRANCH in cvs:
for i in `find /home/me/myproject_head/ -type f \
   | grep -v CVS | grep -v "org.eclipse"`; do \
   cvs update -rMY_PROJECT_BRANCH_XX -p $i > $i; \
   done;

This states that we want to take all the files in our local HEAD/TRUNK version and overwrite them with the versions that exist in the "MY_PROJECT_BRANCH_XX" branch in cvs.


Finally, before we call commit we need to add all the files that exists in the BRANCH but haven't yet been added to HEAD/TRUNK. This requires that you execute "cd /home/me/myproject_head/"
for i in `cvs -nq up | grep "? " | cut -d " " -f2 `; do\
   cvs add $i; \
   done;

Now we are ready to commit:
cvs commit -m "REPLACED HEAD/TRUNK WITH BRANCH"

That's it... You should now have a working HEAD containing the same as the stuff in your BRANCH!

The example above can probably be simplified, however this is how I did... Feel free to comment if you have a more simple solution!

Enjoy!

Friday, November 21, 2008

[Spring 2.5] context:component-scan does not with @autowired in JUnit test.

A problem exists in Spring 2.5.1 (Maybe also later versions up until 2.5.4?) that cause context:component-scan not to detect the classes you wish to inject in your test classes. Instead you have to add a bean tag defining the bean that you wish to inject in your JUnit test case.

Example

applicationContext.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:aop="http://www.springframework.org/schema/aop"
 xmlns:context="http://www.springframework.org/schema/context"
 xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
  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
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
 <context:component-scan base-package="com.maaloe.spring" />
 <context:annotation-config/>
</beans>

TestCase:
package com.maaloe.spring;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import dk.telia.cas.command.CommandException;
import dk.telia.cas.dataobject.CPRInfo;
import dk.telia.cas2.test.AbstractSpringTest;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class MyServiceTest {

    @Autowired
    private MyTestService myTestService;

    @SuppressWarnings("unchecked")
    @Test
    public void test() {
        System.out.println("Test service class: " + myTestService.myToString());
    }
}

Service interface:
package com.maaloe.spring;

public interface MyTestService {
    String myToString();
}

Service Implementation:
package com.maaloe.spring;

import org.springframework.stereotype.Component;

@Component
public class MyTestServiceImpl implements MyTestService {
    public String myToString() {
        return "Ping...";
    }
}

The above does not work until you add:

<bean id="myTestService" class="com.maaloe.spring.MyTestServiceImpl"/>


to your applicationContext.xml file if you are running Spring 2.5.1.

Anyways... Simply fix it by upgrading Spring to 2.5.4.

Enjoy!

Wednesday, November 19, 2008

[Spring] @Autowired doesn't work in an abstract class

If your @AutoWired doesn't seem to work in an abstract class, it could be because you need to add @Component to the solid class that extends the abstract class.

So if you have an abstract class:
package com.maaloe.test;

import org.springframework.beans.factory.annotation.Autowired;

public abstract class MyAbstractClass {
  @Autowired
  TestService testService;
  public void test() {
    System.out.println("TestService: " + testService.myToString());
  }
}

and a solid class:
package com.maaloe.test;

import org.springframework.stereotype.Component;

@Component
public class MySolidClass extends MyAbstractClass {
  public void mytest() {
    super.test();
  }
}

Note that this abstract class does NOT have a @Component tag, as this is never used as a solid class, so even though it uses @Autowired for injecting its member variables, only the class extending the MyAbstractClass need to have the @Component tag.

I found this rather confusing... but that's apparently the way it works. :)

Heres' the TestService and the TestServiceImpl:
package com.maaloe.services;

public interface TestService {
  String myToString();
}

package com.maaloe.services.impl;

import org.springframework.stereotype.Component;

@Component
public class TestServiceImpl implements TestService {
  public String myToString() {
    return "TestService ping...";
  }
}

and finally, the applicationContext must contain:

<context:component-scan base-package="com.maaloe" />
<context:annotation-config/>


Enjoy...

Note that none of the above have been compiled, it's just written from my memory, so forgive me if it contains minor errors.

Please comment if you have anything to add!

Thursday, October 30, 2008

[JSF] How to get rid of "JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: )" on session timeout

While upgrading JSF from 1.1 to 1.2 (1.2_09) I found a lot of the following exceptions in tomcats catalina.out and localhost.log.

com.sun.faces.lifecycle.Phase doPhase SEVERE: JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: ) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@55d7b]

SEVERE: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.application.ViewExpiredException: viewId:/xxxx.jsf - View /xxxx.jsf could not be restored.
        at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:186)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)

Turns out that this usually happens if you have a request that refers to JSF ViewIds (the structure of the jsf page) that doesn't exist in the session on the server. For example, a users session could be timed out on the server, so when the user makes a request to the server with the ViewId, it no longer exist and you will most likely receive the above exception.
The reason why this suddenly shows up is that JSF 1.1 and 1.2 handles the session timeout differently. Now you actually have a chance to react upon the thrown exception whereas previously it was just ignored and the view tree was just regenerated from scratch.

Anyways... What you can do to avoid this is two things:
  • Handle the exception, for example by adding a filter that shows a nice page to the user
  • Insert the following in your web.xml:
      
        com.sun.faces.enableRestoreView11Compatibility    true
      
    
    This will cause JSF to behave as it did in 1.1

Tuesday, October 14, 2008

[Java] How to calculate the size of a Session running in Tomcat 6

If you want to be able to see the size of the sessions running in Tomcat, here's how...

Start out by downloading sizeofag.jar and place it in "/lib/". Then add "-javaagent:sizeofag.jar" to the "JAVA_OPTS" environment variable.

Now change the two manager ("/webapps/manager/") jsp files "sessionDetail.jsp" and "sessionsList.jsp" to show the size of the sessions.
Here's an example of the two files in Tomcat 6.

sessionDetail.jsp

sessionsList.jsp

See more info on calculating size of Java HTTP Sessions in this great article.

Update:There seems to be a problem with this approach. The Session size shown by sizeofag.jar is not the actual Session size as the Session contains a number of references to Tomcat and other classes that should not be considered when calculating the Session size. Thus, if you want to use this approach you should look at the difference in the size before and after you add attributes to the Session.

Friday, October 3, 2008

[Tomcat] How to troubleshoot/find deadlocks or hanging threads in tomcat.

Sometimes you have threads hanging, or even worse, Deadlocks in your applications installed in Tomcat.

In those, and many other cases you can use the unix command "kill -3 " to signal to Tomcat that it should dump all the threads that it is currently working with into "tomcat/logs/catalina.out".
You can usually find tomcats processId by running "ps -ef | grep tomcat":

Example output from "ps -ef | grep tomcat":
jam 6721 6560 0 08:55 ? 00:00:51 /usr/java/jdk/bin/java -Dcatalina.home=...

The column marked in bold is the processId.

The clever thing about "kill -3" is that it doesn't actually shut tomcat down, it just signals tomcat to dump its threads so you can run this command in a live production environment.

After dumping the threads, you can analyse which processes are in the state "WAIT" and contains you class name in the thread dump. If you can find any of these, that's a good place to start looking for problems!

Enjoy!

Wednesday, September 24, 2008

[Maven] Converting/Changing a project from using Ant to use Maven

As a developer I often meet old Java projects based on maven. As I very much prefer Maven over Ant, I try to convert to maven whereever it is possible and makes sense.

Here's how I usually convert a simple web (war) project from Ant to Maven.

Start out by installing maven and creating a new structure for your maven project in a different directory than the one containing your Ant project:
mvn archetype:create -DgroupId=com.maaloe.myproject -DartifactId=myproject -DarchetypeArtifactId=maven-archetype-webapp

Where com.maaloe.myproject matches whatever base package you use in your project structure and artifactId matches the name of your project

Now... The objective is to make the war file that Maven creates when running "mvn clean install" as similar to the one that Ant creates as possible, so we should compare the two war files by doing a "jar -tf projectname.war" on both projects.

The existing project in my case contains a build.xml file with three targets:
  1. "ant -Dmode=dev"
  2. "ant -Dmode=test"
  3.  "ant -Dmode=prod"
All the targets copies a property file "myproject/conf//ApplicationResources.properties" (mode being dev, test or prod) to the war file so make sure the correct environment properties are used when installing the war file.


In my case, the Ant war file looks like this:
>> jar -tf ninjaspwebinterface.war

META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/com/
WEB-INF/classes/com/maaloe/
WEB-INF/classes/com/maaloe/myproject/
WEB-INF/classes/com/maaloe/myproject/modules/
WEB-INF/classes/com/maaloe/myproject/modules/user/
WEB-INF/classes/com/maaloe/myproject/tags/
WEB-INF/classes/com/maaloe/myproject/tags/utils/
WEB-INF/classes/com/maaloe/myproject/utils/
WEB-INF/classes/com/maaloe/myproject/webapp/
WEB-INF/classes/com/maaloe/myproject/webapp/actions/
WEB-INF/lib/
WEB-INF/admin-config.xml
WEB-INF/classes/ApplicationResources.properties
WEB-INF/classes/log4j.properties
WEB-INF/classes/com/maaloe/myproject/modules/user/User.class
WEB-INF/classes/com/maaloe/myproject/utils/Constants.class
WEB-INF/classes/com/maaloe/myproject/webapp/ActionServlet.class
WEB-INF/classes/com/maaloe/myproject/webapp/actions/LogonAction.class
WEB-INF/classes/com/maaloe/myproject/webapp/actions/LogonForm.class
WEB-INF/lib/activation.jar
WEB-INF/lib/commons-collections.jar
WEB-INF/lib/commons-httpclient-2.0.jar
WEB-INF/lib/commons-logging-api.jar
WEB-INF/lib/commons-logging.jar
WEB-INF/lib/log4j-1.2.8.jar
WEB-INF/lib/nls_charset12.jar
WEB-INF/lib/servlet.jar
WEB-INF/lib/struts.jar
WEB-INF/lib/project_utils.jar
WEB-INF/lib/xalan.jar
WEB-INF/lib/xercesImpl.jar
WEB-INF/lib/xml-apis.jar
WEB-INF/struts-bean.tld
WEB-INF/struts-config.xml
WEB-INF/struts-config_1_0.dtd
WEB-INF/struts-form.tld
WEB-INF/struts-html.tld
WEB-INF/struts-logic.tld
WEB-INF/struts-template.tld
WEB-INF/struts.tld
WEB-INF/web.xml
index.html
logon.jsp

There are several problems in creating a war file that matches the one Ant creates.
  1. We need to figure out what versions of the jar files in WEB-INF/lib/ to use as in most cases, this is not specified.
  2. WEB-INF/lib/project_utils.jar is not a jar file we can find in any maven repository, so we need to find a solution for this.
  3. As the existing Ant build.xml contains targets for deploying to both development, test and production environment, we need to make sure that out maven conversion adds the correct properties to the war file based on a maven target.

Let's adress the problems one at a time.

First of all, we need to figure out what dependencies exist in the Ant war file. Some is straight forward like "commons-httpclient-2.0.jar" as this exists on an existing repository (check http://www.mvnrepository.com/) so we can just add the following dependency to the pom.xml file:

 commons-httpclient
 commons-httpclient
 2.0


Others, like struts.jar, we have no idea what version is used. In those cases you can usually extract the struts.jar file (jar -xvf ) from the Ant war file and check the "META-INF/MANIFEST.MF" file. In this (text) file you can find the version (if the jar file was packages properly).
If you have the guts, you can upgrade to the latest release of the jar file, but that could go wrong.
In my case, the MANIFEST.MF contains:

Manifest-Version: 1.0
Implementation-Version: 1.0.2
Specification-Title: Struts Framework
Specification-Version: 1.0
...

Eg. Current ant war file depends on Struts 1.0.2, so we'll add the following to the pom.xml:

 struts
 struts
 1.0.2



Secondly, we need to figure out what to do with the "WEB-INF/lib/project_utils.jar" file as this is a local project jar file that we depend on. This such cases, we need to deploy this to a repository from where others can download the dependency when they need to compile the new version of the project build on Maven.
What I have done is to install "Artifactory". It's a simple application file that you install on a central server and then point your maven pom.xml file to your new repository. For more information on installing Artifactory, check here.
You can ofcourse just put the jar file in your local repository but then no one will be able to compile the project out of the box which is one of the main arguments I have for switching to Maven.

This is what I have added to the pom.xml file for Maven to download the jar files:

 
  central
  http://:8080/artifactory/repo
  
   false
  
 
 
  snapshots
  http://:8080/artifactory/repo
  
   false
  
 



Third point. We want to be able to handle the three targets for the three different environments. This can be done by adding a profile to Maven and then using the "maven-antrun-plugin" plugin. In my case I can write:

 
  
   
    environment
   
  
  
   
    
     maven-antrun-plugin
     
      
       test
       
        run
       
       
        
         
         
         
         
        
       
      
     
    
   
  
 


The above copies two property files from the conf// directory (log4j.properties and ApplicationResources.properties) to the target directory where it will be included in the war file.

Now, I can simply call Maven with the following command to package the development version of the project war:

mvn clean install -Denvironment=dev



Here's the full pom.xml file I used for the above project.

 4.0.0
 com.maaloe.myproject
 myproject
 war
 1.0
 MyProject Maven Webapp
 
  Maaloe.com
  http://dev.maaloe.com
 
 
  
   jm
   Jakob Maaloe
   jam@maaloe.com
   
    Developer
    Consultant
   
   +1
  
 
 
  
   javax.servlet
   servlet-api
   2.5
   provided
  
  
   javax.servlet.jsp
   jsp-api
   2.1
   provided
  
  
   javax.activation
   activation
   1.1
   provided
  
  
   log4j
   log4j
   1.2.15
  
  
   struts
   struts-ninja
   1.0.2
  
  
   commons-collections
   commons-collections
   3.2.1
  
  
   commons-httpclient
   commons-httpclient
   3.1
  
  
   xerces
   xercesImpl
   2.8.1
  
  
  
   project_utils
   project_utils
   0.1
  

  
   junit
   junit
   3.8.1
   test
  
 
 
  myproject
 
 
  
   central
   http://repo.maaloe.com:8080/artifactory/repo
   
    false
   
  
  
   snapshots
   http://repo.maaloe.com:8080/artifactory/repo
   
    false
   
  
 
 
  
   central
   http://repo.maaloe.com:8080/artifactory/repo
   
    false
   
  
  
   snapshots
   http://repo.maaloe.com:8080/artifactory/repo
   
    false
   
  
 
 
  
   
    
     environment
    
   
   
    
     
      maven-antrun-plugin
      
       
        test
        
         run
        
        
         
          
          
          
          
         
        
       
      
     
    
   
  
 


So, that's it for changing from Ant to Maven. I have marked some of the dependencies as provided as they actually don't need to be part of the war file, since the web container (Tomcat in my case) provides this.

Of course you may run in to problems that I haven't taking in to account, but the above hopefully gives you a few hints to the way I usually solves the conversion process.
Please, if you run in to interesting problems that you think others could benefit from, comment on the blog!

Thursday, September 18, 2008

[Spring 2.5] How to use injection in your web application.

If you want to utilize from the latest Spring injection features, here's how to enable spring in your classes.
The example below is just written from memory and has not been verified compile wise, etc. If you find something strange, please comment. :)


Start out by adding the Spring Listener to your web.xml:

   org.springframework.web.context.ContextLoaderListener


Now add an applicationContext.xml to the WEB-INF/ directory containing:



 
 


context:component-scan will tell spring to scan the "base-package" for spring injection.
Change "com.maaloe.test" to the root package of where the classes using spring are located.
context:annotation-config will enable spring annotations.


To make your classes compile, add the following to your pom.xml (or include the spring jars in your classpath if you still haven't seen the light).


   org.springframework
   spring
   2.5.1


   org.springframework
   spring-test
   2.5.1



That's it, you should now be able to use spring injection in your classes. First, the interface of the "service" class that contains the logic you wish to inject:
public interface MyServiceLogic {
   public void doLogic(Object someObject);
}


Now, the class implementing the actual logic:
import org.springframework.stereotype.Component;

@Component
public class MyServiceLogicImpl implements MyServiceLogic {
   public void doLogic(Object someObject) {
      // Do whatever you want your "service" to do.
   }
}

Use @Component to tell spring that this class uses injection. Several other annotations exist depending on the situation, such as @Service, @Repository.


Now, inject the MyServiceLogic instance in your class:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MyWebApplication {
   private MyServiceLogic serviceLogic;
   
   @Autowired
   public void setMyServiceLogic(MyServiceLogic serviceLogic) {
    this.serviceLogic = serviceLogic;
   }

   public void myApplicationMethod() {
      Object myObject = ....
      
      // Now you can use the serviceLogic object
      // as Spring makes sure that it's initialized.
      serviceLogic.doLogic(myObject);
   }
}

Again, @Component is used to enable injection, in this case via @AutoWire.
@AutoWire will tell spring to inject an implementation of the interface MyServiceLogic in the setMyServiceLogic() method.
This will only work if you just have one implementation of the MyServiceLogic interface. If you have several implementations, use: @Qualifier("beanId") where you inject the implementation to give Spring a hint on what class to inject.

If you want to test your classes containing Spring injections, check this

[Spring 2.5] How to create test case that calls class hierachy that uses spring injection

If you want to test a method on a class that uses a number of other classes, some utilizing spring, some not, you can use the following approach.
The example below is just written from memory and has not been verified compile wise, etc. If you find something strange, please comment. :)

import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = { "classpath:applicationContext.xml" })public class MyTest extends TestCase {   @Test   public void testComplexClassStructure() {      // Test the class that relies on a number of       // other clasases, some using spring, some not.   }}

To make sure you can use spring inside your test class, add the @RunWith(SpringJUnit4ClassRunner.class). This will wrap your test with the Spring test class.

In order to load the applicationContext.xml (enable annotations in packages, etc), use the @ContextConfiguration(locations = { "classpath:applicationContext.xml" })

Add @Test to specify a test case.

If you are using maven (what a stupid question, of course you are), you need to add the following to your pom.xml for the above to work:
 org.springframework spring 2.5.1 org.springframework spring-test 2.5.1

For examples on applicationContext.xml and injection using @AutoWire, check this

Monday, September 15, 2008

[Firefox] How to uninstall swfdec and use regular Adobe Shockwave Flash plugin instead

Swfdec has a tendency to cause flash movies to display as blank (black) on Firefox. Here's a solution to remove it.

The preferred way of removing the Swfdec is to open up the "Synaptic Package Manager", search for "Swfdec" and then remove "libswfdec-x.x-xx" and "swfdec-mozilla".
Now search for "flashplugin-nonfree" and install it. This should get flash running using the Adobe Shockwave flash plugin.

If the above did not work, try this:
  • Write "about:config" in address bar and click enter.
  • Change "plugin.expose_full_path" to "true".
  • Write "about:plugins" in address bar and click enter.
  • In the "Shockwave Flash" part of the page you should now be able to see the full path name to the "libswfdecmozilla.so" file.
  • Remove the "libswfdecmozilla.so" file from the path specified.
  • Remove the plugin database file. On my computer, it's located at: "~/.mozilla/firefox/z3tjq6i8.default/pluginreg.dat"
  • Now start firefox and browse to a location that contains flash files. I had problems playing the live feeds from here (click so why not try this to verify the installation.

Friday, September 12, 2008

[Ubuntu] How to reconfigure your xorg if everything got screwed up

I'm just facing a fact and I think most of us have been there. Every now and then I manage to completely screw up the x server because I just HAVE to try out something in the /etc/X11/xorg.conf.

If you weren't clever enough to make a backup xorg file, you can restore your config by running the excellent "dpkg-reconfigure" program.

sudo dpkg-reconfigure xserver-xorg

[Ubuntu] How to get your firewire camcorder to work in ubuntu

I'm using Kino for capturing video streams from my camcorder, but I couldn't figure out why Kino kept on displaying the message "raw1394 kernel module not loaded or failure to read/write /dev/raw1394".

It turned out to be two things, one, the module for Firewire needs to be loaded:

lsmod | grep 1394
sudo modprobe video1394
sudo modprobe dv1394

and second, the firewire device needs to be accessable by "normal" users, instead of just root:
sudo chmod a+rw /dev/raw1394

Enjoy!

[Ubuntu] How to get a projector to work with Ubuntu

If your projector doesn't work with Ubuntu, try this:

sudo dpkg-reconfigure xserver-xorg

Usually you just have to accept whatever it asks you.

Thursday, September 4, 2008

How to avoid mail spam where spammers use from field to bounce mails to you. (SPF record)

If you get a large amount of spam, and most of the spam consists of bounces where the spammer insert you in the from and reply-to fields, eg. you get any replies from the mailserver, you can protect yourself by adding an SPF (Sender Policy Framework) record to your domain DNS information.

The idea is that you specify from what domains you send e-mails. This is published to any server that tries to send e-mails to your mailserver. If the from doesn't match the domain you specify, then it will be rejected. You can find more information on the spf record structure here:

The example below sets that the domain is maaloe.com and my mail provider surf-town.net is added as include since i send my mails via their servers.

v=spf1 v=spf1 a:maaloe.com include:spf.surf-town.net -all

Once you have set up the SPF record you can test it here.

Wednesday, September 3, 2008

[Ubuntu] Ubuntu 32 Bit shows too little memory (only registers 3GB instead of 4GB, 5GB, &GB or worse)

While installing Ubuntu 8.04 i found that it didn't register the 6 GB installed memory I have in my desktop.
BIOS shows 6 GB alright, but Ubuntu only shows 3 GB.

I found that the following solves the problem in Ubuntu

Install linux-headers-server and linux-server packages:

sudo apt-get install linux-headers-server linux-server


Then restart your system...

Now meminfo will show 6 GB:

zyb3r@xyz~$ cat /proc/meminfo
MemTotal: 6087608 kB
...

Friday, August 29, 2008

ServerMonitor: Small Groovy scripts to easy monitor your servers health & WebPageIncludeGadget: Google gadget for including ServerMonitor on igoogle.

Two tools have been released:



1. ServerMonitor: Monitor the health of the services running on your server.
2. WebPageIncludeGadget: A google gadget to include a webpage (for example the ServerMonitor) on your igoogle main page.

Used together you get a pretty powerfull solution for people running igoogle, as you constantly get an update on how your services are running.

ServerMonitor can be downloaded from here.

To install ServerMonitor from:

- Tar archive, download archive, extract the files in a directory, run the install.sh script and follow the instructions.
- Source, download the source from the svn repository, run the compile.sh script to compile and then run install.sh and follow the instructions.


WebPageIncludeGadget can be downloaded from here.
To install WebPageIncludeGadget, follow these instructions.

Enjoy, and please comment on it to allow me to improve the projects.

Tuesday, August 26, 2008

[UNIX] Change sshd port to avoid most brute force attempts (Ubuntu example)

In order to change your ssh port in ubuntu via command line, edit /etc/ssh/sshd_config:


sudo vi /etc/ssh/sshd_config


Now, change the Port line:


...
# What ports, IPs and protocols we listen for
Port 22
...


to "Port 21234" or whatever you want it changed to.
Now restart the ssh daemon:


sudo /etc/init.d/ssh restart


You may also need to verify that the port isn't already reserved for something else in "/etc/services".

Remember to open up an router/switch in front of your server, otherwise you'll never be able to contact your server on the new port.

Most other distributions have similar location for the ssh port, you just have to look for it.

Monday, August 25, 2008

[Bash] How to change/replace text in multiple files using bash script

This script will look for files based on their name and in all found files it will replace one text with another text.

Example: You want to change the text ".NET rules" with "Java rules" (remember girls'n guys, just an example) in a number of all named "Test.java". To do this, run the script and specify the "Test.java" as the input files, ".NET rules" as search string and "Java rules" as replacement string

You can use this as a script by copying the code below into a new file ".sh" and then run the script using "sh .sh" (requires the permissions to be set correctly using "chmod u+x .sh").



#!/bin/bash
echo "#############################################################"
echo "This script will look for files with a name that contains "
echo "a specific string and inside files with that name, it will "
echo "replace all occurences of another specific string with a "
echo "third specified string".
echo ""
echo ""
echo "Please write the string that identifies the name (or part of "
echo "the name) of the files you wish to replace text in, example: pom.xml "
echo ""
read -e FILE_STRING

echo ""
echo "Please write the string that you wish to replace, "
echo "example 3.3.2-SNAPSHOT:"
echo ""
read -e SEARCH_STRING

echo ""
echo "Please write the string that you wish to replace [$SEARCH_STRING]"
echo "with, example 3.4-SNAPSHOT:"
echo ""
read -e REPLACE_STRING

echo "Searching....."
echo ""

for i in `find . -name "*$FILE_STRING*"`
do
echo -n "---------- Parsing file [$i] .... "
SED_STRING="s/$SEARCH_STRING/$REPLACE_STRING/g"
perl -i -pe $SED_STRING $i
echo " Done! ----------"
done;

echo "#############################################################"