Tag: man

  • Impolite Japanese

    Got a warning ticket yesterday for parking in a “handicap” zone. (Well, it is convenient to park there, I admit). But look at the ticket content, you’ll be shocked !

    Handicap Parking Ticket

    Here’s how it translates (tried my best, since this is native Japanese and had to look up the dictionary many times)
    This parking place is for [physically handicapped], not [mentally handicapped] person like you. Can make out from a car like yours, a person like you won’t understand. You really think your car is too cool? Aren’t you ashamed to act like a complete idiot? Did you ever see your ugly face in the mirror? Pity you do not understand, thus I noted your car number, model and informed to the nearest police station. Don’t ever park in parking reserved for handicap again !

    Pretty rude and forthcoming for a Japanese, don’t you think?

    I wonder why didn’t this person put his number or contact in case I wish to “consult” to remedy my pitiful situation. No Pity

  • Spring IoC, DI quick tutorial

    There has been an (evident) craze amongst Java community with contrived terms such as IoC (Inversion of Control), DI (Dependency Injection) mainly through Spring. I initially found the connotation “Don’t call me, I’ll call you” a bit difficult (yeah, it’s bending your head upside down) to understand, but after spending few hours around Spring documentation, I get the gist.

    To a layman (Java layman, of course) it is helpful to picture that each Java program is a set of one or more classes, which act together. Essentially, this means classes are “dependent” on some classes in order to be fully functional. Usually, the class requiring functionality of another class instantiates the class, and uses it. This is called coupling because class instantiates the object of required class. What if we always got an “instantiated” instance of required class, and our class did not have to worry of instantiation? – This is called IoC (Inversion of Control) principle in Spring, and it achieves this by providing ready-to-use instance (injecting dependency) to your class. This has some important uses, since now you don’t worry of creating connections to databases, loggers to log4j, or sessions for JMS queues. Spring will create these for you, and your class can focus on the actual purpose – using the pre-instantiated ready-to-use object.

    Get it? OK, to simplify it further, let us assume you have a class A having one field – log. You want to use log to log information, but your class nowhere has the logic to instantiate or initialize log. You accept a pre-instantiated log through constructor, or getter/setter methods, and you will have a ready-to-use log instance passed to your class via Spring!

    I won’t go into details of Spring further, since Spring’s own documentation on http://static.springsource.org/spring/docs/2.5.x/reference/index.html is the definitive source to look into.

  • Getting out of telnet

    You telnet an ip, port but you cannot get out? Ctrl+C doesn’t work, Esc doesn’t work !
    Duh, Ctrl+C, Esc are the commands sent directly to the ip, port you just telnet-ed, so telnet doesn’t see them at all !

    For this you need to return back to telnet prompt, so hit
    Ctrl+] (yes, Ctrl and right square bracket)
    telnet> quit
    Connection closed.

    Hope this helps

  • Outlook export to Thunderbird

    There is no straight (should I say “easy”) way to export Outlook mails to Thunderbird. Using Thunderbird’s import from Outlook did not work since quite a few emails came up as raw HTML, and I had to manually change Automatic encoding detection to OFF, Universal to see the contents each time.
    A sure-shot (well… which took me 99% of the) way was Outlook –> Import into Outlook Express –> Import into Thunderbird. This worked, but with one sad issue – non-English attachment names are not as original. If you can live with that, then this is the surest way to go !

    Few references which helped-
    Import .pst files – MozillaZine KB

  • Extremely useful tips for Java

    1. A .java class can contain only one top-level public class.  All other top level classes in same .java file cannot be private or protected or public, only default (package-level access) is allowed.
    2. If no package is specified for class, it belongs to unnamed package – which cannot be imported.
    3. Unlike Linux utilities, long parameters or short parameters to java(c) need just a space before parameter value. e.g. -classpath <classpath> or -cp <classpath> are same. There is no -classpath=<classpath> syntax in java(c) command line.
    4. 8 primitive types (byte, short, int, long, float, double, char, boolean), special type void, and base type for all objects – java.lang.Object.
    5. null is not a keyword, type. It is a value.
    6. String objects created using short-hand String A= "a string";
      syntax creates Strings on pool in heap. A is pointer (32-bit to max. 64-bit) to a String object “a string” on heap memory allocated to your program. Using short-hand syntax to “a string” on String B= "a string"; will point to same string object on heap.
    7. Object gets garbage-collected, not it’s reference.
    8. Garbage collection is indeterminate. You cannot guarantee freeing of memory by forcing System.gc()
    9. finalize method is invoked only once before being removed from memory. Always call super.finalize() if you override it.
    10. Parameters (primitive, references) are always passed-by-value. There is no pass-by-reference in Java. The references passed can be used to modify the object the reference points, but not the reference itself is not modified.
    11. Return values from function are also passed by value, never by reference.
    12. Compound operators (+=, -=, *= etc) automatically cast. Compiler never throws any error on data mismatch.
    13. & (and) results in 1 if both are 1, | (or) results in 0 if both are 0, ^ (xor) results in 1 if either operand is 1
    14. char supports increment, decrement operators.
    15. The default isequal() implementation of Object tests for reference equality, which is same as ==.
    16. When using operators, Java automatically promotes values to int or higher. For values below int – byte, short – an explicit cast is required.
    17. extends comes first then implements
    18. Java tokenizes your source into separators (tab or space), keywords, operators, literals, identifiers (variable names).
    19. new zeroes Object’s fields (instance variables), hence explicit initialization can be skipped.
    20. import static allows importing static variables like System.out into your program. Hence, you can simply use out without prefixing it with class name System.
    21. local variables must be initialized before using. Though method parameters are local variables too, since methods are called with parameters, they are initialized.
    22. arrays are fixed size data structures, where as collections are dynamically sized data structures.
    23. For multidimensional arrays, it is easier to imagine the first dimension as a single row containing the other dimensions.
    24. Array initialization always requires dimension to be provided when initializing through new (caught at compile time). If using array initializer, you can specify {} empty braces, but accessing any index at runtime will only result in index out of bounds exception.
    25. There is always a default constructor – empty body – available for your class only if you do not declare any constructor.
    26. super, this must be the first line in constructor. this() or super() both cannot be placed.
    27. Parent class constructor super() is always called. For this reason, you need to have an empty constructor always in parent class.
    28. Method signature is composed of method name and parameters. Modifiers, return type, exception list has nothing to do with it. Access-specifiers however control visibility.
    29. Javabean properties are get-, set- methods provided over a field in Javabean style.
    30. Variable length parameters always come at the end of the list, and they can be empty (meaning nothing was passed). Being at end of the list automatically implies that only variable length parameters is allowed. (Java 5.0)
    31. Overloading means providing different method signatures in same or inheriting class. Overriding means providing same return type, method signature in inheriting class.
    32. Covariant return types means overriding method returns a subclass of return type in parent class. (Java 5.0)
    33. Method hiding means overriding of static methods.
    34. Abstract method has no body. Interface methods are all abstract, while Abstract class can contain zero or more abstract methods.
    35. All abstract method of Interface are public, it’s fields are public, static and final. No static methods are allowed.
    36. Abstract method compiles with static modifier, but generates runtime error if directly accessed. If abstract static method is overridden in child class, child class works fine.
    37. Enum constructors are invoked for each element.
    38. Anonymous inner class can have only one instance. Local inner class can have multiple instances.
    39. Static nested class is similar to any top-level class.
    40. Static fields in class always need default value; otherwise code does not compile.
    41. false is boolean, 0 is not false, it is int zero
    42. switch…case does not allow case null, since a constant (and final) expression is required for case
    43. You can put break in default for switch
    44. enum classes can have main method
    45. for(;;) is a valid for-loop. It never finishes, since it is an infinite loop.
    46. In enhanced for loop, the variable used for iteration must be declared only in for loop, not outside it.
    47. Java complains if you have unreachable while loop code e.g while(false) is not allowed. However, contrarily if(false) is allowed!
    48. Variables declared inside do…while loop are not available in while to test for condition!
    49. It is a good idea to add labels to your loops to enhance readability
    50. Assertion is put in places in your code where you think it should be always true
    51. Though not a good design, but assertions do allow modification on variables while asserting them e.g. assert ++i
    52. try…catch – catch can never have an exception which is a subclass of previous catch clause. It throws compile error.
    53. Checked exceptions always derive from Exception, runtime exceptions derive from RuntimeException, errors derive from Error. Java enforces checked exceptions are either handled or thrown. For runtime, error there is no such rule, even if RuntimeException derives from Exception.
    54. try… must have either catch or finally atleast, otherwise compile gives error
  • Brainteasers

    1. How many degrees angle between hour, minute hand when time is 3:15?
      7.5°
      360° full circle, therfore (360°/12 hrs) = 30° /hour.
      At 3:15,  minutes hand points to the 3, hour hand is ahead of 3 by 1/4th (15/60),  which is 7.5° apart. (30°/4)=7.5°
    2. Why are manhole covers round?
      – Round covers can be easily rotated
      – It’s easier to dig a circular hole
      – Round castings are easier to machine using a lathe
      – Easier to manufacture than custom-made covers
    3. How will you generate random number between two given numbers
      Assuming n1, n2 random number between them would be n1 + Math.random() * (n2 – n1)
    4. How will you sort a million integers?
      Split them into meaningful subsets, sort each subset, merge subset back
      http://neopythonic.blogspot.com/2008/10/sorting-million-32-bit-integers-in-2mb.html
    5. How many windows will be open in a 100 window room if you go around  a 100 times toggling each window you come across? All windows are closed initially.
      100 windows,  all closed.
      1st round, you toggle all windows i.e. all windows are opened
      2nd round, you close all even-numbered windows – 2, 4, 6, …
      3rd round, you open, close odd numbered winodws – 3, 6, 9,…
      So after 100 times, windows open are windows who have been toggled odd number of times. For e.g. consider window 12, round 1 will make it open, 2 will make it closed, 3 will make it open, 4 closed, then directly 12 will make it open. Consider again, window 20 – 1 (open), 2 (close), 4 (open), 5 (close), 10 (open), 20 (close). Consider 7 – 1 (open), 7 (close). So window 12 got touched 5 times, window 20 got touched 6 times, window 7 touched 2 times.
      So, in order to find “open” windows between 1-100, we have to find number having “odd” number of factors, which means numbers who have one repeated factor i.e.  factor by same factor gives the number e.g. 16 has 1, 2, 4, 8, 16 – open window. It has 4 which means 4×4= 16. Consider 20 has 1, 2, 4, 5, 10, 20. No factor is repetitive.
      Therefore, let us find numbers which are below 100, but are having square products, similar to 4×4 = 16 starting with 1, which gives 12=1, 22=4, 32=9, 42=16, 52=25, 62=36, 72=49, 82=64, 92=81, 102=100
      So open windows are 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 = 1o open windows
    6. A party of four travelers comes to a rickety bridge at night. The bridge can hold the weight of at most two of the travelers at a time, and it cannot be crossed without using a flashlight. The travelers have one flashlight among them. Each traveler walks at a different speed: The first can cross the bridge in 1 minute, the second in 2 minutes, the third in 5 minutes, and the fourth takes 10 minutes to cross the bridge. If two travelers cross together, they walk at the speed of the slower traveler. What is the least amount of time in which all the travelers can cross from one side of the bridge to the other?
      Obvious (but incorrect)
      Incorrect answer

      Not  so obvious (correct answer)
      Correct answer

    7. Next…

    A party of four travelers comes to a rickety bridge at night. The bridge can hold the weight of at most two of the travelers at a time, and it cannot be crossed without using a flashlight. The travelers have one flashlight among them. Each traveler walks at a different speed: The first can cross the bridge in 1 minute, the second in 2 minutes, the third in 5 minutes, and the fourth takes 10 minutes to cross the bridge. If two travelers cross together, they walk at the speed of the slower traveler.

    What is the least amount of time in which all the travelers can cross from one side of the bridge to the other?

  • What do you see?

    What do you see?

    It’s not just an old woman, or a man… if you look carefully.

  • Interesting alternatives to databases in opensource

    I stumbled upon this url. The list of various options on databases is pretty amazing.

    http://www.webresourcesdepot.com/25-alternative-open-source-databases-engines/

    It’s a definite read. I never knew so many existed.

  • Got my bike license – 大型二輪免許を一発合格しました

    Hurray ! I received my bike license today in Japan ! In my first attempt itself ! Wish me congratulations !

    Bike license in Japan
    My bike license in Japan

    Ok some background – I had a bike license from my country. I had not converted it to International License, so I had to opt only for conversion into Japanese license – 外国免許切り替え. I do have a car license obtained in Japan, so I was exempted from written test (which by the way is too difficult, trust me). Instead, I simply had to appear an actual driving test (which is again difficult, mind you). I was required to produce a translated copy of my original license from my country, which can be done in 30 mins in JAF offices. Rest are your passport (both old, new ones), an application form, few stamps which you can buy right there. I live in Tsukuba, so I had to goto Ibaragi License Center, which is situated in Mito. You can go during weekdays, from 09:00AM. Believe me, you better arrive early. There is plenty of crowd, for all sorts of licenses, and usually you have to spend almost whole day there, in case you pass the test and obtain the license. I spent close fo 6 hours today, but in the end I was a happy guy.

    Once they receive your application, they ask you few questions about your original license – How did you obtain it? Where did you practice? What kind of test did you appear for this license? How many cc bike? Learner’s license? etc. Unless there are any problems, you are then handed over a course map, and timings when your test will start. Mind you, the course map is given so that you “memorize” it, period. You are required to drive the exact course map, observing lane rules, traffic signs, signal, right or left indication, speed or slow. The usual advice is that you have some 45 mins in hand before your test starts. Thus, you should actually take the course map in hand, and walk the entire course by foot atleast once. I did that, making a mental note of the lanes, the distance around which I should turn on the indicator, and so on – till I burnt the course map into my brain cells !

    The most difficult are – Ipponbashi, and Slalom – for me. And I did literally walk on foot imagining I was on bike before my test started.

    I believe I was the only one appearing a bike test today – why I was alone sitting in the waiting room till my turn came. The instructor was kind enough to walk me (verbally) through the course map once again. He also gave me a brief about the bike – Honda CB750 – and for my own safety, in case I should fall, had me wear elbow, knee, body protector before the test.

    When the actual test started, the instructor actually sits in a watchtower, from which he had a complete view of the course. Once he gave a go, I just drove the same path I had walked on foot earlier. I was particularly careful about slow down sign, lane change, and making sure that I move my head from left to right wide enough to show that I am taking visual confirmations before proceeding. At one point when making a turn I did step down, but I guess that was OK, because if I’d had done the same on Ipponbashi or Slalom, or even S-letter, or Crank, I am out without any further discussion. Phew, I did feel once the bike will stop during Crank, but I was lucky enough to make it till the final stop.

    In the end, the instructor appraised my driving skills, and gave me the golden word – “合格” !

  • Japanese samurai language

    Japanese language is often interesting, when it comes to dialects. Try out standard Japanese into many other (un)known dialects here.