Posts Tagged ‘howto’

Posted by Tatyana at 6 February 2012

Category: Dev, Java

Tags: , , , , , , , ,

Controllers in Spring MVC are desined to be shared between requests. Each controller has a default singleton scope so if you are using controllers you neeed to be aware of that. The easiest way to make sure your controller is thread-safe is to not to have class variables. F.ex. this example from Spring MVC tutorial:

@Controller
@RequestMapping("/editPet.do")
public class EditPetForm {

    private final Clinic clinic;

    public EditPetForm(Clinic clinic) {
        this.clinic = clinic;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(@RequestParam("petId") int petId, ModelMap model) {
        Pet pet = this.clinic.loadPet(petId);
        model.addAttribute("pet", pet);
        return "petForm";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(
            @ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {

        new PetValidator().validate(pet, result);
        if (result.hasErrors()) {
            return "petForm";
        }
        else {
            this.clinic.storePet(pet);
            status.setComplete();
            return "redirect:owner.do?ownerId=" + pet.getOwner().getId();
        }
    }
}

In this example we can have a serious issue regarding thread-safety: private variable clinic. If there will be a situation where to different requests access the controller simultaniously, one of them will instanciate the controller and begin to process a form, then the other one comes inn. The result from processing of the first request will be sent to the other one, thus the requests receive fail data or nothing.

The solution to the problem may be the following:
1. Annotate Controller with @Scope(“request”) or @Scope(“session”)
2. Move private variable into one of the methods or save it in session or model.

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 28 February 2011

Category: Dev, Flex

Tags: , , , ,

<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        <![CDATA[
            import mx.controls.Label;

            public function willShowResult(result:Label, myVar:String):Boolean {
                if (myVar== 'XXX') {
                    return false;
                }
                return true;
            }
        ]]>
    </mx:Script>

    <mx:columns>
        <mx:DataGridColumn
            dataField="myVar"
            headerText="My var"/>
        <mx:DataGridColumn
            dataField="result"
            headerText="My result">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Label text="{outerDocument.willShowResult(this, data.myVar) ? data.result : ' ' }"/>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>

</mx:DataGrid>
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 28 February 2011

Category: Java, Tip

Tags: , , , ,

If an autocomplete stopped working go

Window -> Preferences -> Java -> Editor -> Content Assist -> Advanced ->  check for “Other Java Proposals”

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 7 November 2010

Category: Game review, Tip

Tags: , , , , ,

This is how you gain access to the Nellis Air Force Base in New Vegas.

Once you start entering the area, you’ll get bombarded by the Boomers.

Overview picture:

This is how you enter the Nellis Air Force Base in New Vegas

Click the picture for full size image.

Refill with stimpacks, food, water, doctors bags when necessary.

And remeber to make the bet with George before you enter the area. If you have 60 speech or more you can lie to raise the wager to 700 after you’ve entered Nellis AFB and came back.

When you reach the gate you’ll be let in.

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 7 November 2010

Category: Game review, Game review

Tags: , ,

After finding the locations of the Brotherhood patrols, you’re asked to find the scouts and retrieve observations from them.

Locations are:
1) Near the NCR Correctional Facility
2) Near Nipton
3) Near Camp Forlorn Hope

Scout Locations

Scout Locations

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 25 October 2010

Category: Game review

Tags: , , , ,

This is a simple howto on how to beat the virus infection in the Brotherhood of Steel datastore.

1) Talk to Scribe Ibsen about the virus infection and ask if you could help him.

2) After much talking Scribe Ibsen will ask you to wait until he says the virus has jumped. Do a quicksave here just before Scribe Ibsen tells you the virus has jumped.

3) Place yourself in front of one of the terminals.

4) When Scribe Ibsen gives you GO, search for the virus in the computers. Do a systematic search. And remember what computers have the virus. If you fail the first attempt, reload the quicksave.

5) Go to the computers you had the virus in the previous attempt and isolate them there.

6) Continue the search for additional infected computers.

7) If unsuccessful, goto 4.

Scribe Ibsen at the terminal

Scribe Ibsen at the terminal

More screenshots in the next post.

VN:F [1.9.13_1145]
Rating: 5.0/5 (3 votes cast)
Share

Posted by Tatyana at 24 July 2010

Category:

Tags: , , ,

I was trying to solve a problem of resetting a focus if the parent changes. I had different buttons that show the same .mxml-form but with different data. The problem was that I needed the focus to be on the first date-field whenever the form is shown so that the user can begin typing data right away.

<mx:HBox>
       <mx:Button id="noData" click="showPanelWithNoData()" />
       <mx:Button id="someData" click="showPanelWithSomeData()" />
       <mx:Button id="withData" click="showPanelWithData()" />

       <myCustomForm:DataForm width="100%" />
</mx:HBox>

So for each time one of the buttons is pushed I need the focus to be on myDate-field. To solve the problem I used “updateComplete“-property of the field.

DataForm.mxml

<?xml version="1.0" encoding="utf-8"?>
<DataForm
    xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
        <![CDATA[
            import mx.managers.FocusManager;

            private function resetFocus():void {
                if (focusManager != null && myDate.focusManager != null) {
                    focusManager.setFocus(myDate);
                }
            }
        ]]>
    </mx:Script>

    <mx:FormItem>
        <mx:TextField id="myDate"
            updateComplete="resetFocus()"/>
    </mx:FormItem>

</DataForm>
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 17 April 2010

Category:

Tags: , , ,

1. Use the == to check if the argument is a reference to this object.

2. Use the instanceof operator to check if the argument has the correct type.

3. Cast the argument to the correct type.

4. For each “significant” field in the class, check if that field of the argument matches the corresponding field of this object.

5. Always override hashCode when you override equals.

6. Don’t substitute another type for Object in the equals declaration.

7. Write unit-test.

   @Override
   public boolean equals(Object obj) {
      if(obj == this) {
         return true;
      }
      if(!(obj instanceof Person)) {
          return false;
      }
      Person p = (Person)obj;
      return p.name.equals(name)
             p.birthday.equals(birthday)
             p.personNumber == personNumber;
      }


Ref.”Effective Java” by Joshua Bloch

Enother example with hashCode and toString:

    @Override
    public boolean equals(Object obj) {
        if (obj == null || !obj.getClass().isInstance(this)) {
            return false;
        }
        Beregning b = (Beregning) obj;

        return new EqualsBuilder()
                .append(simulertPensjon, b.getSimulertPensjon())
                .append(linjer.size(), b.getLinjer().size()).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(simulertPensjon).append(linjer).hashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
        .append("simulertPensjon", simulertPensjon)
        .append("antall linjer", linjer.size()).toString();
    }
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by Tatyana at 25 February 2010

Category:

Tags: , , , ,

The book by Robert C. Martin “Clean Code” is a really very useful material for all programmers. You can disagree with him sometimes (as I do), but it still provides some useful notes that helped me to place my programmer experience and knowledge where they belong. Here I’ll provide some key notes that I did while reading the book and that I’d like to memorize.

What you as a programmer SHOULD DO:

1. Give everything meaningful, searchable and pronounceable names.
2. Use names that other programmers can understand. Remember that the code is for programmers, not customers.
3. Functions should be small and smaller than that.
4. Functions should do one thing. They should do it well. They should do it only.
5. The ideal number of arguments for a function is zero. Max 3.
6. Prefer exceptions to returning error codes. Create informative error messages.
7. Prefer meaningful names to comments.
8. Write JavaDoc only for public API’s.
9. Format your code. While working in a team use a single formatting style.
10. Test your code with clean tests. Remember that test code is just as important as production code.
11. Test just one concept per test.
12. Test should follow the FIRST rule:

    Fast -  tests should be fast.
    Independent - tests should not depend on each other
    Repeatable - tests should be repeatable in any environment
    Self-validating – the test should have a boolean output
    Timely - write unit tests before the production code.

What you as a programmer should AVOID:
1. Avoid encoding
2. Avoid duplicate code. Watch out not only duplicate functions but also duplicate functionality.
3. Avoid noisy, redundant, uninformative comments. Remember that one of the more common motivations for writing comments is bad code.

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 20 December 2009

Category: c++, Dev

Tags: , , ,

Open Visual Studio command prompt.

Go to the folder you installed the source files in.

Execute configure with the wanted options.

S:\Qt\2009.04\qt>configure -debug-and-release -fast -no-webkit -opensource

This is the Qt for Windows Open Source Edition.

You are licensed to use this software under the terms of
the GNU General Public License (GPL) version 3
or the GNU Lesser General Public License (LGPL) version 2.1.

Type '3' to view the GNU General Public License version 3 (GPLv3).
Type 'L' to view the Lesser GNU General Public License version 2.1 (LGPLv2.1).
Type 'y' to accept this license offer.
Type 'n' to decline this license offer.

Do you accept the terms of the license?

Wait.

Then execute nmake and wait.

“configure” command line options

Usage: configure [-buildkey <key>]
 [-release] [-debug] [-debug-and-release] [-shared] [-static]
 [-no-fast] [-fast] [-no-exceptions] [-exceptions]
 [-no-accessibility] [-accessibility] [-no-rtti] [-rtti]
 [-no-stl] [-stl] [-no-sql-<driver>] [-qt-sql-<driver>]
 [-plugin-sql-<driver>] [-system-sqlite] [-arch <arch>]
 [-D <define>] [-I <includepath>] [-L <librarypath>]
 [-help] [-no-dsp] [-dsp] [-no-vcproj] [-vcproj]
 [-no-qmake] [-qmake] [-dont-process] [-process]
 [-no-style-<style>] [-qt-style-<style>] [-redo]
 [-saveconfig <config>] [-loadconfig <config>]
 [-qt-zlib] [-system-zlib] [-no-gif] [-qt-gif] [-no-libpng]
 [-qt-libpng] [-system-libpng] [-no-libtiff] [-qt-libtiff]
 [-system-libtiff] [-no-libjpeg] [-qt-libjpeg] [-system-libjpeg]
 [-no-libmng] [-qt-libmng] [-system-libmng] [-no-qt3support] [-mmx]
 [-no-mmx] [-3dnow] [-no-3dnow] [-sse] [-no-sse] [-sse2] [-no-sse2]
 [-no-iwmmxt] [-iwmmxt] [-direct3d] [-openssl] [-openssl-linked]
 [-no-openssl] [-no-dbus] [-dbus] [-dbus-linked] [-platform <spec>]
 [-qtnamespace <namespace>] [-qtlibinfix <infix>] [-no-phonon]
 [-phonon] [-no-phonon-backend] [-phonon-backend]
 [-no-webkit] [-webkit]
 [-no-scripttools] [-scripttools]
 [-graphicssystem raster|opengl]

Installation options:

 You may use these options to turn on strict plugin loading:

 -buildkey <key> .... Build the Qt library and plugins using the specified
 <key>.  When the library loads plugins, it will only
 load those that have a matching <key>.

Configure options:

 The defaults (*) are usually acceptable. A plus (+) denotes a default value
 that needs to be evaluated. If the evaluation succeeds, the feature is
 included. Here is a short explanation of each option:

 -release ........... Compile and link Qt with debugging turned off.
 *  -debug ............. Compile and link Qt with debugging turned on.
 +  -debug-and-release . Compile and link two Qt libraries, with and without
 debugging turned on.

 -opensource ........ Compile and link the Open-Source Edition of Qt.
 -commercial ........ Compile and link the Commercial Edition of Qt.

 -developer-build ... Compile and link Qt with Qt developer options
 (including auto-tests exporting)

 *  -shared ............ Create and use shared Qt libraries.
 -static ............ Create and use static Qt libraries.

 -ltcg .............. Use Link Time Code Generation. (Release builds only)
 *  -no-ltcg ........... Do not use Link Time Code Generation.

 *  -no-fast ........... Configure Qt normally by generating Makefiles for all
 project files.
 -fast .............. Configure Qt quickly by generating Makefiles only for
 library and subdirectory targets.  All other Makefiles
 are created as wrappers which will in turn run qmake

 -no-exceptions ..... Disable exceptions on platforms that support it.
 *  -exceptions ........ Enable exceptions on platforms that support it.

 -no-accessibility .. Do not compile Windows Active Accessibility support.
 *  -accessibility ..... Compile Windows Active Accessibility support.

 -no-stl ............ Do not compile STL support.
 *  -stl ............... Compile STL support.

 -no-sql-<driver> ... Disable SQL <driver> entirely, by default none are
 turned on.
 -qt-sql-<driver> ... Enable a SQL <driver> in the Qt Library.
 -plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to at run
 time.
 Available values for <driver>:
 mysql
 psql
 oci
 odbc
 tds
 db2
 +                         sqlite
 sqlite2
 ibase
 (drivers marked with a '+' have been detected as
 available on this system)

 -system-sqlite ..... Use sqlite from the operating system.

 -no-qt3support ..... Disables the Qt 3 support functionality.

 -no-opengl ......... Disables OpenGL functionality

 -platform <spec> ... The operating system and compiler you are building on.
 (default %QMAKESPEC%)

 -xplatform <spec> .. The operating system and compiler you are cross
 compiling to.

 See the README file for a list of supported operating
 systems and compilers.

 -qtnamespace <namespace> Wraps all Qt library code in 'namespace name {...}
 -qtlibinfix <infix> Renames all Qt* libs to Qt*<infix>

 -D <define> ........ Add an explicit define to the preprocessor.
 -I <includepath> ... Add an explicit include path.
 -L <librarypath> ... Add an explicit library path.
 -l <libraryname> ... Add an explicit library name, residing in a
 librarypath.

 -graphicssystem <sys> Specify which graphicssystem should be used.
 Available values for <sys>:
 *                         raster - Software rasterizer
 opengl - Using OpenGL accelleration, experimental!
 -help, -h, -? ...... Display this information.

Third Party Libraries:

 -qt-zlib ........... Use the zlib bundled with Qt.
 +  -system-zlib ....... Use zlib from the operating system.
 See http://www.gzip.org/zlib

 -no-gif ............ Do not compile the plugin for GIF reading support.
 +  -qt-gif ............ Compile the plugin for GIF reading support.
 See also src/plugins/imageformats/gif/qgifhandler.h

 -no-libpng ......... Do not compile in PNG support.
 -qt-libpng ......... Use the libpng bundled with Qt.
 +  -system-libpng ..... Use libpng from the operating system.
 See http://www.libpng.org/pub/png

 -no-libmng ......... Do not compile in MNG support.
 -qt-libmng ......... Use the libmng bundled with Qt.
 +  -system-libmng ..... Use libmng from the operating system.
 See See http://www.libmng.com

 -no-libtiff ........ Do not compile the plugin for TIFF support.
 -qt-libtiff ........ Use the libtiff bundled with Qt.
 +  -system-libtiff .... Use libtiff from the operating system.
 See http://www.libtiff.org

 -no-libjpeg ........ Do not compile the plugin for JPEG support.
 -qt-libjpeg ........ Use the libjpeg bundled with Qt.
 +  -system-libjpeg .... Use libjpeg from the operating system.
 See http://www.ijg.org

Qt for Windows only:

 -no-dsp ............ Do not generate VC++ .dsp files.
 *  -dsp ............... Generate VC++ .dsp files, only if spec "win32-msvc".

 -no-vcproj ......... Do not generate VC++ .vcproj files.
 *  -vcproj ............ Generate VC++ .vcproj files, only if platform
 "win32-msvc.net".

 -no-incredibuild-xge Do not add IncrediBuild XGE distribution commands to
 custom build steps.
 +  -incredibuild-xge .. Add IncrediBuild XGE distribution commands to custom
 build steps. This will distribute MOC and UIC steps,
 and other custom buildsteps which are added to the
 INCREDIBUILD_XGE variable.
 (The IncrediBuild distribution commands are only added
 to Visual Studio projects)

 -no-plugin-manifests Do not embed manifests in plugins.
 *  -plugin-manifests .. Embed manifests in plugins.

 -no-qmake .......... Do not compile qmake.
 *  -qmake ............. Compile qmake.

 -dont-process ...... Do not generate Makefiles/Project files. This will
 override -no-fast if specified.
 *  -process ........... Generate Makefiles/Project files.

 -no-rtti ........... Do not compile runtime type information.
 *  -rtti .............. Compile runtime type information.

 -no-mmx ............ Do not compile with use of MMX instructions
 +  -mmx ............... Compile with use of MMX instructions
 -no-3dnow .......... Do not compile with use of 3DNOW instructions
 +  -3dnow ............. Compile with use of 3DNOW instructions
 -no-sse ............ Do not compile with use of SSE instructions
 +  -sse ............... Compile with use of SSE instructions
 -no-sse2 ........... Do not compile with use of SSE2 instructions
 +  -sse2 .............. Compile with use of SSE2 instructions
 +  -direct3d .......... Compile in Direct3D support (experimental - see
 INSTALL for more info)
 -no-openssl ........ Do not compile in OpenSSL support
 +  -openssl ........... Compile in run-time OpenSSL support
 -openssl-linked .... Compile in linked OpenSSL support
 -no-dbus ........... Do not compile in D-Bus support
 +  -dbus .............. Compile in D-Bus support and load libdbus-1 dynamicall
 y
 -dbus-linked ....... Compile in D-Bus support and link to libdbus-1
 -no-phonon ......... Do not compile in the Phonon module
 +  -phonon ............ Compile the Phonon module (Phonon is built if a decent
 C++ compiler is used.)
 -no-phonon-backend . Do not compile the platform-specific Phonon backend-pl
 ugin
 *  -phonon-backend .... Compile in the platform-specific Phonon backend-plugin
 -no-webkit ......... Do not compile in the WebKit module
 +  -webkit ............ Compile in the WebKit module (WebKit is built if a
 decent C++ compiler is used.)
 -no-scripttools .... Do not build the QtScriptTools module.
 *  -scripttools ....... Build the QtScriptTools module.
 -arch <arch> ....... Specify an architecture.
 Available values for <arch>:
 *                         windows
 windowsce
 boundschecker
 generic

 -no-style-<style> .. Disable <style> entirely.
 -qt-style-<style> .. Enable <style> in the Qt Library.
 Available styles:
 *                         windows
 +                         windowsxp
 +                         windowsvista
 *                         plastique
 *                         cleanlooks
 *                         motif
 *                         cde
 windowsce
 windowsmobile

 -loadconfig <config> Run configure with the parameters from file configure_
 <config>.cache.
 -saveconfig <config> Run configure and save the parameters in file
 configure_<config>.cache.
 -redo .............. Run configure with the same parameters as last time.

Qt for Windows CE only:

 -no-iwmmxt ......... Do not compile with use of IWMMXT instructions
 +  -iwmmxt ............ Do compile with use of IWMMXT instructions (Qt for
 Windows CE on Arm only)
 *  -no-crt ............ Do not add the C runtime to default deployment rules
 -qt-crt ............ Qt identifies C runtime during project generation
 -crt <path> ........ Specify path to C runtime used for project generation.
 -no-cetest ......... Do not compile Windows CE remote test application
 +  -cetest ............ Compile Windows CE remote test application
 -signature <file> .. Use file for signing the target project
 -opengl-es-cm ...... Enable support for OpenGL ES Common
 -opengl-es-cl ...... Enable support for OpenGL ES Common Lite
 -opengl-es-2 ....... Enable support for OpenGL ES 2.0
 *  -phonon-wince-ds9 .. Enable Phonon Direct Show 9 backend for Windows CE
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share