Super kiran… I am so proud of u… Even in such difficult situations u r taking a very good stand
Thursday, November 15, 2012
Saturday, November 10, 2012
Q
పుస్తక రుద్రాక్ష శస్త్ర హస్త పుటి,
కామాక్షి పక్ష్మలాక్షి కలిత విపంక్షి విభాసి వైరించి!!
మనోజపం మరుతతుల్యవేగం
జితేంద్రియం బుద్ధి మతాన్బరిస్థం
వాతాత్మజం వానరయూధ ముఖ్యం
శ్రీరామ దూతం సిరసానమామి
Monday, November 5, 2012
Simulating network packet loss
At first i tried netem; however it errored out
[root@prithvivm3 ~]# /sbin/tc qdisc change dev eth0 root netem loss 0.1%
RTNETLINK answers: No such file or directory
i tried very hard, but couldnt fix this so tried packet loss using iptable
first i had to upgrade my current iptable
--> to install the iptables use the below command
# rpm -Uvh http://ftp.srce.hr/redhat/extras/el5/x86_64/iptables-1.3.5-5.3.el5_4.3.x86_64.rpm http://ftp.srce.hr/redhat/extras/el5/x86_64/iptables-ipv6-1.3.5-5.3.el5_4.3.x86_64.rpm
--> clear all rules of iptables # iptables --flush
--> run the below command to view all rules in iptables. the below should not return any rules
#/sbin/iptables -vnL INPUT --line-numbers
--> now use the below to add a new rule. here we are telling IPTables to drop 1 packet for every 10 packets statistically random
The above returns all rules configured. as we said flush before this it will return a single line. now run the below command to add a rule
# iptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP
--> save the above rule to ip tables file # /etc/init.d/iptables save
--> view all rules of iptables
#/sbin/iptables -vnL INPUT --line-numbers
--> it should be visible as below Chain INPUT (policy ACCEPT 5328 packets, 673K bytes) num pkts bytes target prot opt in out source destination 1 3510 480K DROP all -- * * 0.0.0.0/0 0.0.0.0/0 statistic mode random probability 0.100000
--> so we added our rule successfully
--> now restart the iproute table for the above rules to take affect
# /etc/init.d/iptables restart
to monitor the packets run the below command
watch 'iptables -vL'
the output will be as follows
Every 2.0s: iptables -vL Mon Nov 5 14:17:13 2012 Chain INPUT (policy ACCEPT 5680 packets, 702K bytes) pkts bytes target prot opt in out source destination 3726 496K DROP all -- any any anywhere anywhere statistic mode random probability 0.400000 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 7336 packets, 593K bytes) pkts bytes target prot opt in out source destination Chain LOGGING (0 references) pkts bytes target prot opt in out source destination Chain RH-Firewall-1-INPUT (0 references) pkts bytes target prot opt in out source destination
After having done the above .. i ran my client that tries to communicate to server on plain sockets.
Learning:
Initially i was expecting some issues... 'cos we are dropping packets that are going to the socket. So on server side i was expecting server to read some wrong data/ throw some array out of bound exception. however no such thing had happend. I am trying to understand it.
So... In transport layer two things happen
- The packets are checked for corruption; by CRC- cyclic redundancy check of the packet data
- packet sequencing;
- the CRC check is first done (at hardware lever in ether net card)
- then the packets are sent to the OS layer
- before which (i.e.. before the point 2 above) the packets are intercepted and acted upon
- Now the packet drop(by iptables rules) happens (ie.. in point 3 above) and then it reaches the OS layer
- OS layer now checks for sequencing and because packet drop (of point 4) has happened asks the tcpip to re-fetch the full packet.
- OS keep indefinitely asking for resend?
- or as OS is totally unaware of the packets it would just ignore.
Wednesday, October 3, 2012
Apache: fall-back mechanism
This is the recent requirement that i had faced w.r.t. virtual hosts.
- at a given location see if the static resource exist
- if it exist then serve form that location
- otherwise fallback to a default location
after a day of investigation… this was the solution i finally discovered
NameVirtualHost *:81
#telling virtual host to listen on this port
<VirtualHost *:81>
ErrorLog logs/rewrite-log
CustomLog logs/rewrite-log combined
DocumentRoot E:/proj/nono2_2_10_3/config/
LogLevel debug
<IfModule rewrite_module>
RewriteLog logs/rewrite.log
RewriteLogLevel 3
</IfModule>
RewriteEngine on
#if the file at the below path doesnt exist then the rule applies. Both these are part of the same rule
RewriteCond %{DOCUMENT_ROOT}httpd/templates-mobile/js/$3 !-f
#rule is to serve the files from default templates folder and skip the next rule (see s=1). Make this rule as the last rule(see L)
#note the $1,$2,$3 are interpreted from he below rule. Each ‘()’ represents $n. where n increments per bracket
# the above rewriteCond take $1,2,3 from this rule below
RewriteRule ^(/ui)(/tpl/js)(.+)$ %{DOCUMENT_ROOT}httpd/templates/js/$3 [L,S=1]
#serve from templates-mobile folder
RewriteRule ^(/ui)(/tpl/js)(.+)$ %{DOCUMENT_ROOT}httpd/templates-mobile/js/$3 [L]
</VirtualHost>
Hope this helps somebody…
Monday, September 3, 2012
Wednesday, August 22, 2012
Downloading a complete page from website
when working with css or js we often convenient to get the website page on our desktop. We generally endup saving as html, then saving each of the css and js files. I discovered an easier way to do the same.
This is supported in linux or cygwin (linux version on windows). Run this command
Command |
wget -E -H -k -K -p http://www.something.com |
Monday, July 23, 2012
Generating gradiants with out using images
This is written in JQuery. Below is the code.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" > </script>
<script> $(function(){ gradiant('div.newGradiant',[255,0,0],[0,0,0]); }); function gradiant(selector,rgb1,rgb2){ var $src = $(selector); var height = $src.height()*1; $src.css('background','yellow'); var x = $src.offset().left + $src.width(); var y = $src.offset().top; //var r=256,g=256;b=256; var r=rgb1[0],g=rgb1[1];b=rgb1[2]; var rr=rgb2[0],gg=rgb2[1];bb=rgb2[2]; for(var i=0;i<height;i++){ var tr= Math.round(r+((rr-r)*i/height)); var tg=Math.round(g+((gg-g)*i/height)); var tb=Math.round(b+((bb-b)*i/height)); var newColor = hex(tr)+hex(tg)+hex(tb); var div =('<DIV style="BORDER-BOTTOM: #ffffff 0px;' +' BORDER-LEFT: #ffffff 0px solid; BACKGROUND-COLOR: ' +'#'+ newColor +'; MIN-HEIGHT: 1px; HEIGHT:' +' 1px; FONT-SIZE: 1px; OVERFLOW: hidden; BORDER-TOP: ' +'#ffffff 0px; BORDER-RIGHT: #ffffff 0px solid"></DIV>'); $src.append($(div)); } } var hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"); function hex(x) { return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16]; } </script> <div class="newGradiant" style="width:100px; height:200px; background:yellow; border: 1px solid black"> |
This generates the gradiant as follows. The algo can be modified to take the edge rgb values and then do the magic. This is just a naive example ;)
Tested this on IE-7, IE-8, IE-9. Chrome 20.0, firefox 13.0 version.
The only issue i see is when we combine this with jQuery corner apis. The results are working in IE but not in chrome!!!
eclipse: deploying classpath jars into tomcat container
Aaaah! this is a big pain.. u will have all jars in classpath, and when u say run as server they dont get copied to the server. the Fix is simpl ( eclipse should have taken care of it by default.. however.. ).
- click on the poject,
- press ctrl + enter.
- Now u see a properties window of the project
- search for deployment assemble and click on it.
- Now in web-deployment assembly plane click on add button
- select java build path entities
- click on next. now select all jars (ctrl + a); then OK
- now click finish.
Deploy the stuff on tomcat and u will see classpath entities are being copied to the server
Sunday, July 8, 2012
Near Random number… 2
In continuation to my previous post.. i made a few more refinements and made the program more simple..
- The advantage of this new one is it allows the total digits we want to alter w.r.t the previous one.
- we can dictate the number of variants between consecutive integers
it reads as follows
import java.util.Random;
public class NearRandomIncrements2 {
private static final Random rand = new Random(99L);
private static final int maxVariants = 10;
private static final int maxVariableDigits = 10000;
private static int[] variantArr = new int[maxVariants];
private static int[] cummulativeArr = new int[maxVariants];
private static int sum;
static {
for (int i = 0; i < maxVariants; i++) {
int nextVariant = Math.abs(rand.nextInt()) % maxVariableDigits;
variantArr[i] = nextVariant;
sum += nextVariant;
cummulativeArr[i] = sum;
System.out.println(">>" + nextVariant + " cumm:" + cummulativeArr[i]);
}
}
public static void main(String[] s) {
long prev = 0;
for (long i = 0L; i < 40; i++) {
int index = (int) (i % (maxVariants));
long cycles = (i / (maxVariants)) + 1;
long newVal = cycles + cummulativeArr[index] + index;
if (newVal < 0) {
newVal = Long.MAX_VALUE + newVal + 1;
}
// if (newVal >= 0 && newVal < 100) {
System.out.println(i + " new no:" + newVal + " cycle:" + cycles + " variant:" + (newVal - prev));
// }
prev = newVal;
}
}
}
For the given maxVariable digits the random numbers generated are as follows
>>5722 cumm:5722
>>6916 cumm:12638
>>4859 cumm:17497
>>1273 cumm:18770
>>696 cumm:19466
>>3525 cumm:22991
>>5948 cumm:28939
>>9283 cumm:38222
>>5856 cumm:44078
>>9198 cumm:53276
The numbers remain the same on multiple runs also.
0 new no:5723 cycle:1 variant:5723
1 new no:12640 cycle:1 variant:6917
2 new no:17500 cycle:1 variant:4860
3 new no:18774 cycle:1 variant:1274
4 new no:19471 cycle:1 variant:697
5 new no:22997 cycle:1 variant:3526
6 new no:28946 cycle:1 variant:5949
7 new no:38230 cycle:1 variant:9284
8 new no:44087 cycle:1 variant:5857
9 new no:53286 cycle:1 variant:9199
10 new no:5724 cycle:2 variant:-47562
11 new no:12641 cycle:2 variant:6917
12 new no:17501 cycle:2 variant:4860
13 new no:18775 cycle:2 variant:1274
14 new no:19472 cycle:2 variant:697
15 new no:22998 cycle:2 variant:3526
16 new no:28947 cycle:2 variant:5949
17 new no:38231 cycle:2 variant:9284
18 new no:44088 cycle:2 variant:5857
19 new no:53287 cycle:2 variant:9199
20 new no:5725 cycle:3 variant:-47562
21 new no:12642 cycle:3 variant:6917
22 new no:17502 cycle:3 variant:4860
23 new no:18776 cycle:3 variant:1274
24 new no:19473 cycle:3 variant:697
25 new no:22999 cycle:3 variant:3526
26 new no:28948 cycle:3 variant:5949
27 new no:38232 cycle:3 variant:9284
28 new no:44089 cycle:3 variant:5857
29 new no:53288 cycle:3 variant:9199
30 new no:5726 cycle:4 variant:-47562
31 new no:12643 cycle:4 variant:6917
32 new no:17503 cycle:4 variant:4860
33 new no:18777 cycle:4 variant:1274
34 new no:19474 cycle:4 variant:697
35 new no:23000 cycle:4 variant:3526
36 new no:28949 cycle:4 variant:5949
37 new no:38233 cycle:4 variant:9284
38 new no:44090 cycle:4 variant:5857
39 new no:53289 cycle:4 variant:9199
if u observe no two numbers are related to each other; and to know the sequence we need to see atleast 30 consecutive numbers (say we have maxVariant by 10 numbers) So by putting the maxVariants a high number and giving the gerated numbers to a trusted client we may use this algo to generate proxies not loosing even one number in the seq bts 0-> Long.Max_Value
any better soln?
Thursday, July 5, 2012
Near random–Converting a sequence no to random no
Q: so the statement of the problem is as follows. I want to generate unique numbers from 1 to Max (say max is Long.MAX_LONG). The generated sequence should not be predictable. SO it means we need to generate uniq random nubers and ensuer they dont repeate. Remember we cannot use current time stamp + some increment number as we have limited range and we need to use it as affectively as possible.
So i wrote a func that transforms a function to (seemingly) random number. Its as follows.
public class NearRandomIncrements {
private static final long salt = 0xABCDEF12345628ACL;
private static final long salt2 = 0xeE72CC072837198DL;
public static void main(String[] s) {
long prev = 0;
for (long i = 1L; i > 0 && i < Long.MAX_VALUE; i++) {
long withSalt = Long.reverseBytes(Long.rotateLeft(i, 31) ^ salt);
long withSalt2 = Long.rotateLeft(withSalt, 17) ^ salt2;
long variation = withSalt2 - prev;
prev = withSalt2;
System.out.println(i + " " + withSalt2 + " variation:" + Math.abs(variation));
}
}
}
This genates the output as follows
1 4835434266867286493 variation:4835434266867286493
2 4763378871852614109 variation:72055395014672384
3 4835436465890542045 variation:72057594037927936
4 4763381070875869661 variation:72055395014672384
5 4835438664913797597 variation:72057594037927936
6 4763383269899125213 variation:72055395014672384
7 4835440863937053149 variation:72057594037927936
8 4763367876736336349 variation:72072987200716800
9 4835425470774264285 variation:72057594037927936
10 4763370075759591901 variation:72055395014672384
So if u closely observe based on variation we see a pattern; and we can predict the next number. But if u see the i=8 part; we see a new variation creeping in. So even if a person gets hold of the sequence he may predict only limited number of numbers only. The solution may not be perfect, but i think its a gud start. What do u think?
Wednesday, June 20, 2012
Q
Stop thinking too much. Its alright not to know the answers
Smile, you dont own all the problems in the world
Friday, June 15, 2012
Q
Money can’t buy Happiness,
But, its more comfortable to cry in a BMW than on a bycycle!
Thursday, June 14, 2012
Friday, June 1, 2012
Q
Happyness keeps you sweet,
Trails keep you Strong,
Sorrow keep u human,
Failure keeps you humble,
success keeps you glowing,
But only God keeps you going..
Sunday, April 29, 2012
Q
Tuesday, April 10, 2012
Sunday, April 1, 2012
Q
Its better to remain silent and be thought a fool than
open one’s mouth and remove all doubt
-Abraham lincoln
Wednesday, March 28, 2012
Q
What takes us back to the past are our memories. What takes us forward to our future are our dreams
Saturday, March 24, 2012
Q
The weak can never forgive
forgiveness is the attribute of the strong
Monday, March 12, 2012
Q
"You have to believe in yourself
when no one else does.
That's what makes you a winner."
- Venus Williams
Wednesday, March 7, 2012
recent polls
A cartoon from Andhra Jyothi.
When congress played bad politics to tackle AnnaHazare I felt very sorry for him. I thought UPA would again win power; ‘cos elections in India are mainly driven by money and liquor. Gud lesson to Congress.. I am happy with the results
Tuesday, March 6, 2012
Was stressed out…
was in a fight with a guy… was in turbulence since then… today i went and had spoke to him… now i feel relieved… !!!
Monday, March 5, 2012
WTF… Google cannot lead???
was reading the post… what is this? Google is following Apple? they cannot think for them selves and come up with something innovative? its a shame for the internet giant to follow his competitor.
Monday, February 27, 2012
Q
ఒక పొరపాటుకు యుగములు పొగిలేవు
ఊహల ఉయ్యాలవే మనసా నువ్వు తెగిన పతంగానివే
Q
శ్రీ రామ చంద్రం శ్రితపారిజాతం సీతా ముఖాంబో ఋహచంచరీకః |
సమస్థ కళ్యాణ గుణాభి రామః నిరంతరం మంగళ మాతనోతు ||
Friday, February 24, 2012
Phishing…
Few minutes back i got a msg from incomtax dept that i have refund of 30K. The From address was: refunds_prt0@incometaxindiafiling.gov.in. At first i was happy to see refund.. but then got doubt.. why would they do? atleast I cant believe that our govt really does work proactively. I got doubt and checked the further details on my gmail; checked the via link. Now I understood its fraud site.
i clicked onthe link provided on the email.. it displayed options from where took me to my standard charted bank.
Look at the address bar. its from some private ip. WOW! what an idea to do phishing! So they are actually proxying my bank details via their servers. If i enter my onlink bank details.. they intercept the data and get hold of my online details.
A novice user would definitely fall into the trap; so i wanted to alert pple on it. I went to my gmail and marked the mail as phishing.
hope this helps somebody…
Sunday, February 19, 2012
OMG Uti MF: i suspect the security of the site
I invest in UTI MF. Today i forgot my password and tried with forgot password on the website… it sent me my password in clear text. This shows that they might have stored the pwd in clear text/ encrypted form in the back end which are both wrong.. remember few days back Microsoft online store was hacked and the userid and pwd of millions of users was compromised..
Wednesday, February 1, 2012
wait a minute…
It was my sis marrage the last weekend and i was on leave for a total of 5 days. The days were hectic, strainous and i remember sleeping with a strained back to the end of the day; esp the last two days. We used to sleep at night 12:30 and get up by 3:00 am. I hardly had any sleep and was feeling the tiredness.
At marrage we represent the brides side. In india its like this; almost 90% of the preparations/ arrangements are to be done by the bride side people and so so much of work. To the end of the day we used to take hard comments from people for some lapse in the arraignments. We never mided.. we hardly had any time to mind them.. we were just buldozing… and racing with time. It was more like suspense thriller for us.. lt was like the last ball between india and pakistan match which decides who will win!
Finally things settled; the hard time went by; and we were finally at home and we were ruminating the history; how things changed.. what will happen next.. how we failed.. what we should have had done… bla bla bla. It was a refreshing experience.
It was the next day; and I had to prepare for the office, but i could feel the freshness in me; the feeling “let it happen what every may happen. I will see it in the situation. Nothing to worry. Let time decide whats next… etc etc etc…”. what a refreshing thought! how nice! but what actually brought this difference? I realized its the break from the work.. the complete break.. i was in my own world.. fully occupied… completely outside office world.. Now i realize.. may be i need frequent breaks.. which can keep me occupied.. take me away from office… I liked the feeling.. and i think i will cherish it..
lets see how it goes.. what new experiences i will have now? these days i m googling for google groups which are on travel..
till further post.. Adios..
Sunday, January 15, 2012
law of karma
Never try to play with other people around you
for you may never know that they play better than you
Saturday, January 14, 2012
Q
Great words by Adolf Hitler:
Dont share your secrets with anybody
‘cos if you-yourself cannot keep your secrets Dont expect somebody else to keep it for you.
Thursday, January 12, 2012
Java concurrency Qn
So here is the problem..
I need to make sure only 3 thread access a resource per second. I have n number of threads that make this request. Any solutions?