Wednesday, 14 September 2011

Desolder an SMD

I've added 2 new Videos to show how simple desoldering an SMD from a XBox360 Motherboard is. Course you can use this method on every Board.

 

Friday, 22 July 2011

Run a code on exit

Sometimes you would like to run a code at close point of your application. The implementing is very easy and is just by adding a ShutdownHook to your application.

hier is the example:



public class RunAtEnd {
    public static void main(final String[] args) {

        System.out.println("Starting the program");

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("You've closed your program");
            }
        }));
        
        System.out.print("Waiting 5 seconds ");
        for (int i = 0; i < 5; i ++) {
            System.out.print(".");
            try {
                Thread.sleep(1000);
            }
            catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("");
    }
}


Monday, 16 May 2011

Reballing Profile Tool

I used a normal Stop Watch to do reflowing/reballing and found it very hard to use, So I decided to write a little tool with C# to manage the Reballing and Reflowing profiles.
this tool, has a section to define your profiles which you can freely select them from main window.
after selecting a Profile and clicking on Start button, a timer will start and shows the specifications defined for that Step.
It will automatically jump to next step if you didn't select the "Pause" in your profile definition.


Download It Here

Change History:

1.0 first Public version


Friday, 8 April 2011

Java HTTP Proxy

I've found this very useful and smart, although you cannot use it in a StressTest with many connections.

Link to Main Source

This is a multi-threaded HTTP proxy server implementation in Java. Ideally you'll just run it on your local workstation so you can watch HTTP requests going back and forth (because of the way the threading works in this code, I wouldn't recommend running it as a proxy server that serves multiple clients -- see the comments in the code for more detail).

You can either point this proxy to a direct network/Internet connection, or you can point it to another proxy server (if that's how you're set up). Even though the jProxy class has a 'main' method that allows you to run it all by itself, I also tried to structure the methods in the class so you can easily call it from other classes. I didn't spend the time to javadoc any of the comments, but the code should be commented well enough that you can understand what's going on by reading through it.

jProxy.java

Thursday, 24 February 2011

Maven Quick Reference Card

I use normally the Content Assist in M2Eclipse Plugin to enter the maven commands, but if you use your own xml editor, a new Maven Quick Reference Card directly from Apache makes the life much easier. it contains the most basic items.

http://maven.apache.org/guides/MavenQuickReferenceCard.pdf

hope you enjoy using it.

Wednesday, 16 February 2011

Convert JUnit3 Tests modules to JUnit4

I needed to convert many test files to JUnit4, after a while, I considered that is a really painful task to do it manually. So I wrote a little program to automate the process.
I tested this application on a huge number of files wrote by various Persons and having various formats, therefore I hope that I works on every possible JUnit module.
Please send me a short comment if you found a case, that I didn't included in it.

you can call the application by entering this command on Command Line:


java -jar JUnit4Converter.jar -f <your JUnit3 Java file>

this will printout the converted file to Console, if you wanted to do an Inplace Conversion, add "-i" to commands.


java -jar JUnit4Converter.jar -i -f <your JUnit3 Java file>

You can access the application on Github

Monday, 14 February 2011

Read multiple files from Resource JAR or Disk

following to my further Post about loading one file from a JAR file or Disk, here is a method which loads directly multiple files. it will decide base of given URL, if it must load those files from Disk or a Resource JAR file.
In my sample, I wanted to be more detailed and load just XML files.



    /**
     * Loads multiple xml files from Disk or Resource JAR file.
     *
     @param clazz current class
     @param path package path of resources
     @return the resource listing
     @throws URISyntaxException the URI syntax exception
     @throws IOException Signals that an I/O exception has occurred.
     */
    List<InputStream> loadMultipleResources(final Class<?> clazz, final String paththrows URISyntaxException, IOException {
        final List<InputStream> listOfFiles = new ArrayList<InputStream>();

        // it is a normal directory, so just find and list files with XML extension
        URL directoryUrl = clazz.getClassLoader().getResource(path);
        if (directoryUrl != null && directoryUrl.getProtocol().equals("file")) {
            final File[] files = new File(directoryUrl.toURI()).listFiles(
                    new FilenameFilter() {
                        @Override
                        public boolean accept(final File dir, final String name) {
                            return name.endsWith(".xml");
                        }
                    });

            for (final File f : files)
                listOfFiles.add(new FileInputStream(f));

            return listOfFiles;
        }

        if (directoryUrl == null) {
            final String packageName = clazz.getPackage().getName();
            directoryUrl = clazz.getResource(packageName);
        }

        // the given path is a JAR file, so extract all XML Files from classpath and return their content as stream
        if (directoryUrl.getProtocol().equals("jar")) {
            final String jarPath = directoryUrl.getPath().substring(5, directoryUrl.getPath().indexOf("!"));
            final JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
            final Enumeration<JarEntry> entries = jar.entries();
            while (entries.hasMoreElements()) {
                final String name = entries.nextElement().getName();
                if (name.startsWith(path&& name.endsWith(".xml")) { // filter according to the path
                    String entry = name.substring(path.length());
                    final int checkSubdir = entry.indexOf("/");
                    if (checkSubdir >= 0) {
                        entry = entry.substring(0, checkSubdir);
                    }
                    final InputStream inputStream = clazz.getClassLoader().getResourceAsStream(name);
                    
                    listOfFiles.add(inputStream);
                }
            }

            return listOfFiles;
        }

        throw new UnsupportedOperationException("Cannot list files for URL " + directoryUrl);
    }


Wednesday, 12 January 2011

Printing the Objects which has no toString method using Reflection

once you want to use toString method in your classes, you will quickly see that all Object without defined toString method, will just showed by their memory address.
Although you can walk through your classes and add a proper toString method to each of them, you will be stopped once you use a thirdparty or generated object.
I will show you here how you can simply printout your object none less. this method uses Reflection to iterate through attributes of a class and prints out its value.
I found later, using ReflectionToStringBuilder is more comfortable to write my own.
so here is the solution:

first write a class which extends ToStringStyle to customize appearance of fields (e.g. use Tabs, how to printout Array and so on)



public class PrintObjectStyle extends ToStringStyle {
    private final static ToStringStyle instance = new PrintObjectStyle();

    public PrintObjectStyle() {
        setArrayContentDetail(true);
        setUseShortClassName(true);
        setUseClassName(true);
        setUseIdentityHashCode(false);
        setArrayStart("\n\t{");
        setArrayEnd("\n\t}");
        setArraySeparator("\n\t");
        setFieldSeparator(", " + SystemUtils.LINE_SEPARATOR + "  ");
    }

    public static ToStringStyle getInstance() {
        return instance;
    }

    ;

    @Override
    public void appendDetail(StringBuffer buffer, String fieldName, Object value) {
        if (!value.getClass().getName().startsWith("java")) {
            buffer.append(ReflectionToStringBuilder.toString(value, instance));
        }
        else {
            super.appendDetail(buffer, fieldName, value);
        }
    }

    @Override
    public void appendDetail(StringBuffer buffer, String fieldName, Collection value) {
        appendDetail(buffer, fieldName, value.toArray());
    }
}



now you can call this line everywhere that you want to printout an Object.



System.out.println(ReflectionToStringBuilder.toString(myObject, PrintObjectStyle.getInstance()));


Thursday, 6 January 2011

Desoldering a XBox 360 Capacitor

If you want to reflow your XBox360 using a Hotair Gun, you have to protect all capacitors, otherwise they will blow out and must be renewed:


I show you in this film how easy you can desolder them.