Skip to main content

Posts

Google Search Operators

There is great power here. I know most of you are not taking advantage of these operators. 1. + (plus) - this will yield search results ordered by the number of occurrences of the specified word 2. - (dash) - this will yield search results that do not contain the specified word 3. " " (double quotes) - this will yield search results containing the exact word specified 4. . (dot) - is a wildcard representing a single character 5. * (asterisk) - is a wildcard representing a single word 6. | - traditional OR operator 7. site: - search within a specified domain 8. intitle: - this will search for the 1st specified word in page titles and the 2nd specified word in the text 9. allintitle: - this will search for texts in page titles only 10. inurl: - this will search for URLs containing the specified word 11. allinurl: - this will search for texts in URLs only 12. filetype: - this will search for texts containing files of the specified extension and the specified word 1...

Gmail Search Operators

These operators will give you more precise search results. 1. from: - mails from the name of the sender 2. to: - mails sent/to be sent to to the recipient 3. subject: - search mails containing the specified words in the subject 4. OR - traditional OR operator 5. - (dash or hyphen) - exclude messages containing the specified words 6. label: - search messages by label 7. has:attachment - search mails with attachments 8. filename: - search mails by filename of the attachments 9. " " (double quotes) - traditional operator for filtering exact specified words 10. () - used for grouping search expressions 11. in:anywhere - search for mails anywhere in your account 12. in:inbox - search for mails in your inbox 13. in:trash - search for mails in your trash folder 14. in:spam - search for mails in your spam folder 15. is:starred - search for starred mails 16. is:unread - search for unread mails 17. is:read - search for read mails 18. cc: - search mails that were ca...

Endianness of Java

In Java, multibyte data items or streams are stored in big endian order. Using Java to write bytes directly to the wire will require byte-order transformation if the recipient talks in little endian. The same is true if you are reading directly from the wire from a sender who talks in little endian. If you are using a byte array wrapped in ByteBuffer, byte[] data = new byte[] { 12, 19, 83, 05, -05, 55, -55 }; ByteBuffer byteBuffer = ByteBuffer.wrap(data); Transforming from big endian to little endian is easy, byteBuffer.order(java.nio.ByteOrder.LITTLE_ENDIAN); If you are unsure of the endianness of the underlying platform, just invoke the native order method. java.nio.ByteOrder.nativeOrder(); Aside from streams, operands in classes that are above 1 byte in size are in big endian order.

Java Lambda Expressions / Closures

Lambda expressions are just (anonymous) functions. f(x) = x can be expressed as x→x f(x, y) = x*x + y*y can be expressed as x, y→x*x + y*y In simple Java terms, 1. Return an int 23 with a void argument int j = { => 23 }.invoke(); 2. Closure with 1 argument, convert 23 kilograms to pounds double j = { double kilograms => kilograms*2.2D }.invoke(23); 3. Closure with 2 arguments, get the sum of the 2 squares int squareSum = { int x, int y => (x*x) + (y*y) }.invoke(2,3); 4. Closure returning an instance and invoking an instance method { new RocketLauncher() }.invoke().fire(); Every time a closure is created at compile time, an interface is automatically created for each expression having an invoke method with a signature depending on the number of arguments, then an anonymous subclass of this interface is constructed. Enjoy!

Tips for Reading Source Code

Reading time is longer than the writing time and most programmers will lose focus along the way (some even fall asleep) especially if they are reading monstrous legacy code. There are several reasons why, in no particular order, 1. Procrastination Programmer: [Wandering mind… Facebook… Twitter…] “Oh man, I have a brilliant idea, I’m going to read more on that… I’ll set aside this crap first and try to come up something innovative.” 2. Impatient Programmer: “I hate this crap, ugly legacy code, it sucks! Can I just have the documents and rewrite everything from scratch?” Project Manager: “Unfortunately, the source code is the only document we have.” 3. Interruptions Team mate: “Hey! Can I have 5 seconds from you? I’m getting a NullPointerException, this is weird, I had everything initialized!” Programmer: “Are you sure? Hold on, let me check that, you might have some methods returning nul...