jayaramprabhudurairaj a.k.a bicepjai

physics + math + coding + dancing + muscles = bicepjai

2013 Yamaha Stryker Oil Change

leave a comment

So finally i did my oil change and collected lot of information and learned a lot of practical difficulties. here it goes

  1. Part Details: As a novice and guy with no tools here is what i did
    1. Tools used:
      • Husky 65-piece 1/4 and 3/8 in drive mechanics tools set : this helped not only with this, but also with my removal back-rest adjustments ($40)
      • OEM oil filter cap wrench 65/67 mm from autozone ($5)
      • Oil drain pan and a funnel form autozone ($3+$2)
      • Stand: I used 4 yellowpages kind of book that was at my door for making my bike stand straight
    2. Oil: since this is my first oil change, i went fancy and used yamaha lube ($33.7)
    3. Parts Required:
      • If first oil change or as required, u might need a filter i used KN-204 ($7.81)
      • If you want gaskets to be changed, i bought yamaha-part-214-11198 ($7.81) i didnt use it, caz i used a new bolt, but i read some times u need to change it
      • I did some research and found that a 14mm Magnetic Oil Drain Plug might help get iron particles from the oil that makes engine’s health better, so i bought this ($27.28); read part fitting detail here
      • paper wipes or towels and be ready to get dirty with oil
    4. Details: there are so many threads out there and it might get confusing and frustrating. Engine Bolt is 14mm stem (very important) and 17 mm head (this is not that important matter). You can use what ever oil you want based on the chart given at the end of the owners manual.
    5. Refer this link for tips on changing oil like
      • which bolt to remove, dont remove the wrong one
      • how to warm engine before change
      • make sure to put some oil on edge of filter
      • dont start you engine when filter or bolt is removed
      • fill the engine with 3.75 quarts of oil (i used nearly 3.9 quarts)
    6. Tips:
      • When removing the filter make sure the pan is there under it caz it will also have some oil to drain.
      • you can put the drained oil in the container which had you new oil.
      • make sure you leave enough time, so that u dont see even drops of oil draining
      • Google how to discard the oil, its illegal to dump the oil
        Do not try to dispose oil in any water bodies
        caz its totally ok only if u are a big oil corporation
        who owns oil rigs in middle of freaking ocean

Written by bicepjai

October 12th, 2014 at 12:07 am

Posted in my-ride

Amazing revelation square numbers ! SIMPLE is the key

leave a comment

The idea is that (n+1)^2=n^2+2n+1, so to get (n+1)^2 from n2, just add 2n+1 to it. Then, to get (n+2)^2 from (n+1)^2 you add 2n+3, and so on.

Written by bicepjai

March 17th, 2014 at 5:14 am

Posted in photography

Arduino old MEGA1280 with new wifi shield r3

leave a comment


Make sure u read the section here !

Written by bicepjai

March 11th, 2014 at 4:19 am

Posted in photography

Arduino 1.5.5 with Ardino Due on mac 10.9.1

leave a comment

Trying to upload blink program on mac with write options selected under tools, i got

Sketch uses 1,116 bytes (3%) of program storage space. Maximum is 30,720 bytes.
Global variables use 11 bytes (0%) of dynamic memory, leaving 2,037 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_recv(): programmer is not responding
at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:129)
at processing.app.Sketch.upload(Sketch.java:1672)
at processing.app.Sketch.exportApplet(Sketch.java:1578)
at processing.app.Sketch.exportApplet(Sketch.java:1550)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2399)
at java.lang.Thread.run(Thread.java:695)
Caused by: processing.app.debug.RunnerException: Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
at cc.arduino.packages.Uploader.executeUploadCommand(Uploader.java:113)
at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:127)
... 5 more

I found that if I hold down the reset while plugging the usb cable into the arduino, with the computer already on that this solves the problem…

The pain is that you will have to do this every time you want to upload a new program, better than not working at all :-/

Written by bicepjai

February 13th, 2014 at 10:19 am

Posted in photography

update Arduino wifi shield on mac systems

leave a comment

I tried to update firmware on my arduino wifi shield. I faced some issues and thought i would shed light on how i tacked it. These are simple scripting mistakes which you might hack on. There are really good explanations  available on googling on how to accomplish firmware upgrade on wifi shied. some of the links were

  • http://ohmyfarads.wordpress.com/2013/11/11/updating-firmware-on-arduino-wifi-shield-for-dummies/
  • http://flashgamer.com/arduino/comments/how-to-update-the-official-arduino-wifi-shield
  • http://arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading

I use to keep not widely used mac apps in respective folders, i kept in under

hence when i ran scripts ArduinoWifiShield_upgrade_mac.sh  present in /Users/bicepjai/Projects/arduino/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/firmwares/wifishield/scripts

i got path errors,  this can be fixed by tweaking the following variables which is pretty much the beginning of the script


the output will be something like

scripts$ sudo bash ArduinoWifiShield_upgrade_mac.sh -a /Users/bicepjai/Projects/arduino/Arduino.app -f all

Arduino WiFi Shield upgrade
Disclaimer: to access to the USB devices correctly, the dfu-programmer needs to be used as root. Run this script as root.

****Upgrade HD WiFi module firmware****
167732 bytes used (66.05%)
Remove the J3 jumper then press the RESET button on the shield then type [ENTER] to upgrade the firmware of the shield..
****Upgrade WiFi Shield firmware****
261594 bytes used (103.01%)

Done. Remove the J3 jumper and press the RESET button on the shield.Thank you!

Make sure, when you are updating using “all” option, you do a reset without removing the jumper after the module update, so that you can also update the shield.

Written by bicepjai

February 13th, 2014 at 9:26 am

Posted in photography

Bit Count: Parallel Counting – MIT HAKMEM

leave a comment

Find the number of set bits in a given integer.
Parallel Counting: MIT HAKMEM Count

HAKMEM (Hacks Memo) is a legendary collection of neat mathematical and programming hacks contributed mostly by people at MIT and some elsewhere. This source is from the MIT AI LABS and this brilliant piece of code orginally in assembly was probably conceived in the late 70’s.

int BitCount(unsigned int u)
unsigned int uCount;

uCount = u – ((u >> 1) & 033333333333) – ((u >> 2) & 011111111111);
return ((uCount + (uCount >> 3)) & 030707070707) % 63;

Lets take a look at the theory behind this idea.

Take a 32bit number n;
n = a31 * 231 + a30 * 230 +…..+ ak * 2k +….+ a1 * 2 + a0;

Here a0 through a31 are the values of bits (0 or 1) in a 32 bit number. Since the problem at hand is to count the number of set bits in the number, simply summing up these co-efficients would yeild the solution. (a0 + a1 +..+ a31 ).

How do we do this programmatically?

Take the original number n and store in the count variable.

Shift the orignal number 1 bit to the right and subtract from the orignal.
count = n – (n >>1);

Now Shift the original number 2 bits to the right and subtract from count;
count = n – (n>>1) – (n>>2);

Keep doing this until you reach the end.
count = n – (n>>1) – (n>>2) – … -( n>>31);

Let analyze and see what count holds now.
n = a31 * 231 + a30 * 230 +…..+ ak * 2k +….+ a1 * 2 + a0;

n >> 1 = a31 * 230 + a30 * 229 +…..+ ak * 2k-1 +….+ a1;
n >> 2 = a31 * 229 + a30 * 228 +…..+ ak* 2k-2 +….+ a2

n >> k = a31 * 2(31-k) + a30 * 2(30-k) +…..+ ak * 2k;

n>>31 = a31;

You can quickly see that: (Hint: 2k – 2k-1 = 2k-1
count = n – (n>>1) – (n>>2) – … -( n>>31) =a31+ a30 +..+a0;
which is what we are looking for;

int BitCount(unsigned int u)
unsigned int uCount=u;
uCount -= u;

This certainaly is an interesting way to solve this problem. But how do you make this brilliant? Run this in constant time with constant memory!!.

int BitCount(unsigned int u)
unsigned int uCount;

uCount = u – ((u >> 1) & 033333333333) – ((u >> 2) & 011111111111);
return ((uCount + (uCount >> 3)) & 030707070707) % 63;

For those of you who are still wondering whats going? Basically use the same idea, but instead of looping over the entire number, sum up the number in blocks of 3 (octal) and count them in parallel.

After this statement uCount = n – ((n >> 1) & 033333333333) – ((n >> 2) & 011111111111);
uCount has the sum of bits in each octal block spread out through itself.

So if you can a block of 3 bits

u = a2*22 + a1*2+ a0;
u>>1 = a2*2 + a1;
u>>2 = a2;

u – (u>>1) – (u>>2) is a2+a1+a0 which is the sum of bits in each block of 3 bits.

The nexe step is to grab all these and sum them up:

((uCount + (uCount >> 3)) will re-arrange them in blocks of 6 bits and sum them up in such a way the every other block of 3 has the sum of number of set bits in the original number plus the preceding block of 3. The only expection here is the first block of 3. The idea is not to spill over the bits to adjacent blocks while summing them up. How is that made possible. Well, the maximum number of set bits in a block of 3 is 3, in a block of 6 is 6. and 3 bits can represent upto 7. This way you make sure you dont spill the bits over. To mask out the junk while doing a uCount>>3. Do and AND with 030707070707. THe only expection is the first block as I just mentioned.

What does ((uCount + (uCount >> 3)) & 030707070707) hold now?
Its 2^0 * (2^6 – 1) * sum0 + 2^1 * (2^6 – 1) * sum1 + 2^2 * (2^6 – 1) * sum2 + 2^3 * (2^6 – 1) * sum3 + 2^4 * (2^6 – 1) * sum4 + 2^5 * (2^3 – 1) * sum5
where sum0 is the sum of number of set bits in every block of 6 bits starting from the ‘low’ position.
What we need is sum0 + sum1 + sum2 + sum3 + sum4 + sum5;
2^6-1 is 63. Clearly a modulo with 63 will get you what you want.

Remember, that this works only with 32 bits numbers, For 64-bit numbers (well I will wait for comments or do this in the next post).

Written by bicepjai

August 20th, 2012 at 11:43 pm

Posted in photography

Implementation of Ukkonen’s algorithm to build a prefix tree in O(n)

leave a comment

Written by bicepjai

August 20th, 2012 at 6:47 am

Posted in fun,puzzled-math,techie

Difference between Vector and ArrayList in java !!

leave a comment

java.util.Vector came along with the first version of java development kit (JDK). java.util.ArrayList was introduced in java version1.2, as part of java collections framework. As per java API, in Java 2 platform v1.2,vector has been retrofitted to implement List and vector also became a part of java collection framework.

All the methods of Vector is synchronized. But, the methods of ArrayList is not synchronized. All the new implementations of java collection framework is not synchronized.

Vector and ArrayList both uses Array internally as data structure. They are dynamically resizable. Difference is in the way they are internally resized. By default, Vector doubles the size of its array when its size is increased. But, ArrayList increases by half of its size when its size is increased.

Therefore as per Java API the only main difference is, Vector’s methods are synchronized and ArrayList’s methods are not synchronized.

Vector or ArrayList? Which is better to use in java?

In general, executing a ‘synchronized’ method results in expensive performance than a unsynchronized method. Keeping the difference in mind, using Vector will incur a performance hit than the ArrayList. But, when there is a certain need for thread-safe operation Vector needs to be used.

Is there an alternate available in java for Vector?
ArrayList can be synchronized using the java collections framework utility class and then ArrayList itself can be used in place of Vector.

When there is no need for synchronized operation and you still look for better performance ‘Array’ can be used instead of ArrayList. But the development is tedious, since it doesn’t provide user friendly methods.

When you use Vector or ArrayList, always initialize to the largest capacity that the java program will need. Since incrementing the size is a expensive operation

Written by bicepjai

August 15th, 2012 at 2:50 am

Posted in fun,techie

swap variables without 3rd

leave a comment

class swap {
        public static void main(String[] args) {
                Scanner in = new Scanner(System.in);
                System.out.println("num1: ");
                int num1 = in.nextInt();
                System.out.println("num2: ");
                int num2 = in.nextInt();
                num1 = num1 + num2;
                num2 = num1 - num2;
                num1 = num1 - num2;
                System.out.println("aftr swap,num1= "+num1+"& num2= "+ num2);

Written by bicepjai

August 9th, 2012 at 7:52 am

Posted in puzzled-math,techie

Missing Number – Bit Manipulation

leave a comment

Question: I came across in “Cracking the Coding Interview 4th edition” 5.7.

An array A[1…n] contains all the integers from 0 to n except one. In this problem, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is “fetch the jth bit of A[i ]”, which takes constant time. Find the missing integer in O(n) time.

This was confusing and online materials didnt seem to cover all the conditions. so i decided to make up the lost part in explanation. Solution depends upon the following factors.

  • (Total number of elements + 1) in the array is even or odd
  • The starting element’s respective position is 0 or 1

you can workout an example for the  LSB which would apply for rest of the bits

if (n+1 is even)
if( current_array[0]’s LSB = 0 or current_array[0]’s LSB = 1 ) )
if (nof_zeros > nof_ones) missing bit is 1
else  missing bit is 0

else [ if (n+1 is odd) ]
if ( current_array[0]’s LSB = 0 ) )
if (nof_zeros > nof_ones) missing bit is 1
else  missing bit is 0
else [ if ( current_array[0]’s LSB = 1 ) ) ]
if (nof_zeros – nof_ones == 0 or 2) missing bit is 1
else  missing bit is 0

You can remove all the other elements having current bit 0 or 1 and do the above check for the other bits,
giving us solution in  O(n)

workout an example with octal numbers and everything will be clear !

Written by bicepjai

August 1st, 2012 at 10:07 am

Posted in fun,puzzled-math,techie