Squaring on both sides, we have:
Wednesday, October 5, 2011
A Gotcha with squaring on both sides..
Squaring on both sides, we have:
Tuesday, August 2, 2011
Dream of death
So, here I was, hanging from the top of a huge staircase, and i began to reflect..."Is that all there is to my life?, I wanted to do so much...None of what i am doing right now seemed significant - acads, job, publications - none of them mattered. I reflected on how i spend most of my time keeping myself busy, never realizing that this moment would come"...it all seemed pointless. Luckily, I managed to wake up and shake off my fear...Strangely though, in the last moments of the fall, i lost all fear. I dont recall why.
So, I've decided. From Aug, I am gonna devote 2 hrs to myself. Do whatever i wanted...even if it means to just sit, or stare blankly at the stars..
On a totally unrelated note, I think this will make a fine novel. A novel that describes the thoughts of this fictional character who is going to die within a minute.
Tuesday, May 24, 2011
Android Fix
Go to device manager.
Select the android device with an ! mark, right click, update driver.
Select "Browse my computer for driver software"
Select :Let me pick from a list of devices on my computer"
Select ADB bridge, install driver.
PS: If you're using vista or windows 7, make sure your environmental variables are set up, and most importantly, launch your command prompt as admin.
Run "fastboot oem unlock"
That should do it..
Saturday, January 15, 2011
Facebook hacker Cup Round 1A - Power Overwhelming
| Fig 1. Geometric representation |
Tuesday, January 11, 2011
A Gotcha with function minimization using genetic algorithms
Facebook Hacker Cup: A Geometric Approach to Double Squares Problem
201105652147483646125743187325100058258911482843225525014751491418583200771022907856104149351831215306625372654318160225592832521474836431538292481
private static int getNumSumSquares(int n)
{
if(n==0)
return 1;
int iterations = (int) Math.ceil(Math.sqrt((n * 1.0)/2));
double y;
int count = 0;
for(int x=0; x <= iterations; x++)
{
y = Math.sqrt(n - (x*x));
//check if y = int.
if(Math.floor(y) == y)
count++;
}
return count;
}
Wednesday, December 22, 2010
Open AL, Adobe Director - No sound in projector [FIX]
Tuesday, December 7, 2010
Recenberg 1/5th success rule applied to life..
Thursday, November 18, 2010
Flaw with patent law?
Wednesday, November 17, 2010
Kleiber's Law
Friday, October 8, 2010
Friday, September 24, 2010
Adding class attributes at runtime :O
/**
* A Utility class to support addition of new properties to a java bean
* at the runtime. Extend your class with this to make it bufferable. It is
* useful if you want to associate certain properties with an object and
* maintain the OOP nature of your code.
*
*This class extends
AbstractSerializableBean
* for serialization and property change support.
*
* @author Ragha
* @see AbstractSerializableBean
* @version 1.0
*/
public class Bufferable extends AbstractSerializableBean
{
private static final long serialVersionUID = 506835437375346326L;
/**
* This map is used to store property name and object as key-value pairs.
*/
private HashMapbuffer = new HashMap ();
/**
* This method is used as a getter for the associated property in the
* buffer.
*
*You must typically create the property using
* {@link #createPropertyInBuffer(java.lang.String) createPropertyInBuffer(...)} method
* before using this method.
*
* @param property The property to be used
* @return The value of the property.
* @throws java.lang.IllegalArgumentException If there is no such property.
*/
public Object getValueFromBuffer(String property)
throws IllegalArgumentException
{
if(buffer.containsKey(property))
return buffer.get(property);
else
{
throw new IllegalArgumentException("Property: '"+property+"' " +
"does not exist...");
}
}
/**
* This method can be used as a setter for the associated property.
* in the buffer.
*
*You must typically create the property using
* {@link #createPropertyInBuffer(java.lang.String) createPropertyInBuffer(...)} method
* before using this method.
*
* @param property The property value to be set
* @param Value The value to be set
* @throws java.lang.IllegalArgumentException If there is no such property
*/
public void putValueInBuffer(String property, Object Value)
throws IllegalArgumentException
{
if(buffer.containsKey(property))
buffer.put(property, Value);
else
{
throw new IllegalArgumentException("Property: '"+property+"' " +
"does not exist...");
}
}
/**
* Creates a new property in the buffer. Once the property is created,
* it can be get or set using the
* {@link #putValueInBuffer(java.lang.String, java.lang.Object) putValueInBuffer(...)} and
* {@link #getValueFromBuffer(java.lang.String) getValueFromBuffer(...)} methods
*
*It is recommended that you use Classname-property name as property
* string to avoid conflicts with other existing property names...
*
* @param property The property name to be associated with the buffer.
* @throws java.lang.IllegalArgumentException If the property name already exists.
*/
public void createPropertyInBuffer(String property)
throws IllegalArgumentException
{
if(buffer.containsKey(property))
{
throw new IllegalArgumentException("Property: '"+property+"' " +
"already exists...");
}
else
{
buffer.put(property, new Object());
}
}
/**
* This method can be used to check if a given property already exists.
* @param property The property to be checked.
* @return true, if the property exists.
*/
public boolean isPropertyInBuffer(String property)
{
return buffer.containsKey(property);
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Bufferable other = (Bufferable) obj;
if (this.buffer != other.buffer && (this.buffer == null || !this.buffer.equals(other.buffer))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 3;
hash = 79 * hash + (this.buffer != null ? this.buffer.hashCode() : 0);
return hash;
}
}
That's it...pretty straight forward isn't it..
/**
* This subclass enhances {@code AbstractBean} by implementing the
* {@code Serializable} interface. {@code AbstractSerializableBean} correctly
* serializes all {@code Serializable} listeners that it contains. Implementors
* that need to extends {@code AbstractBean} or one of its subclasses and
* require serialization should use this class if possible. If it is not
* possible to extend this class, the implementation can guide implementors on
* how to properly serialize the listeners.
*
* @see AbstractBean
* @author Ragha
*/
public class AbstractSerializableBean extends AbstractBean implements Serializable
{
private static final long serialVersionUID = -3459406004204097480L;
protected AbstractSerializableBean()
{
super();
}
private void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
for (PropertyChangeListener l : getPropertyChangeListeners()) {
if (l instanceof Serializable) {
s.writeObject(l);
}
}
s.writeObject(null);
}
private void readObject(ObjectInputStream s) throws ClassNotFoundException,
IOException {
s.defaultReadObject();
Object listenerOrNull;
while (null != (listenerOrNull = s.readObject())) {
if (listenerOrNull instanceof PropertyChangeListener) {
addPropertyChangeListener((PropertyChangeListener) listenerOrNull);
}
}
}
}
Predicting hand position on the keyboard by observing random text \m/
Character (Ordered by frequency) | Actual Finger on char | Finger (Ordered by length) |
H | Middle | Middle |
J | Ring | Ring |
G | Index | Index |
K | Little | Little |
You can try this on your own. Place your fingers on the keyboard (horizontally, any other orientation complicates the situation as relative length changes).
- I wasted your time...haha!
- You can predict the hand position based on random text...duh!
- Its cool!
- See 1
Thursday, August 12, 2010
P vs NP solved?
Saturday, July 24, 2010
Are some people more intelligent than others? - A Mathematical Perspective
Back to the original question: "Are some people smarter than others by birth?". According to bayes rule "NO". It is our experiences that lets us update probability distributions of likelihood of events/hypothesis. These probabilities guide our actions. If someone makes an intelligent choice despite this, then he/she just got lucky.
Einstein and Newton are intelligent because of their experiences. Some take their experiences for granted. For instance, most of us would just pick up and eat the apple if it fell on our head. Instead, newton reasoned as to why it happened. Is this an indicator of superior intellect? He decided to do a different action (reasoning instead of eating) which is a manifestation of past experience. He must have observed/experienced that its rewarding when you reason every small aspect.
Why do some people learn faster than others? Is it because of genetics? If so, it is again a propagation of ancestral experiences. It might be the case that they worked hard in their childhood (more experience), thereby improving their intellect. Hence, they don't have to work as hard as you to pick things up.
So, in conclusion: "All people are born with the same intellect. It is their experiences that define them. To some extent you decide your experiences, so you control how intelligent you want to be."
Tuesday, July 20, 2010
Validation framework for adobe director
oValidator = new(script "ValidationUtil")Predefined validators (functions) can be called by their string name using call(...) method.
isValid = oValidator.validate([ \
["txtField1", ["NonEmptyValidator"],"Please enter textField1"], \
["txtSSN", ["LengthValidator", 4],"Please enter 4 digit ssn"], \
["txtSSN", ["NumberValidator"],"Please enter a numeric value"]
)
-----------------------------------------------------New Validators can be added as an when needed. PRegEX_search(...) comes from PRegEx Xtra. Fortunately, it is free to download. This framework handles error notifications by showing alert messages whenever validation fails. Neat isn't it.
-- This class manages all the validation stuff --
-- @author : Raghavendra Kotikalapudi --
-- @email : ragha.unique2000@gmail.com --
-----------------------------------------------------
--Currently works only for text fields..
--Checks for validation on the given validator..
on isValidOnValidator me, memberName, lstValidatorAndParams
val = sprite(memberName).text
--Extract validator name..
validator = lstValidatorAndParams[1]
otherParams = lstValidatorAndParams
--Remove validator name...it now has params only.
otherParams.deleteAt(1)
--Achieves dynamic function calling..
return call(symbol(validator), me, val, otherParams)
end
--This is the main function to be called.
on validate me, lstMembersAndValidators
ret = true
repeat with lst in lstMembersAndValidators
if isValidOnValidator(me, lst[1], lst[2]) = false then
alert(lst[3])
ret = false
exit repeat
end if
end repeat
return ret
end
--Validates non emptiness..
on NonEmptyValidator me, str, lstOptionalParams
if voidP(str) then
return false
else if length(str) = 0 then
return false
else
return true
end if
end
--Validates of length of str in in the range (low, hi) inclusive
--lstOptParams has low, high pair
on LengthRangeValidator me, str, lstOptionalParams
len = length(str)
if len >= lstOptionalParams[1] and len <= lstOptionalParams[2] then return true else return false end if end --Validates for non existence of special symbols.. --i.e, str can contain a-z, A-Z or 0-9 on NoSpecialSymbolsValidator me, str, lstOptionalParams foundCount = PRegEx_Search([str], "~+|`+|!+|@+|#+|\$+|%+|\^+|&+|\*+|\(+|\)+|\{+|\}+|\[+|\]+|\++|\\+|\|+|:+|;+|/+|\<+|\>+|\?+|,+")
--If special char is found, validate to false
if foundCount > 0 then
return false
else
return true
end if
end
--Validates if the given str is a valid name or not, i.e., it should not contain
--special symbols or 0-9
on NameValidator me, str, lstOptionalParams
val = NoSpecialSymbolsValidator(me, str, lstOptionalParams)
if val = false then
return false
else
foundCount = PRegEx_Search([str], "[0-9]+")
--If number if found..
if foundCount > 0 then
return false
else
return true
end if
end if
end
Friday, July 2, 2010
Women and Their Craze for Possessions
Her Lexus, which she had just picked up the day before, was now completely ruined and would never be the same, no matter what the body shop did to it. When the woman finally wound down from her ranting and raving, the officer shook his head in disgust and disbelief. "I can't believe how materialistic you women are," he said. "You are so focused on your possessions that you don't notice anything else."
"How can you say such a thing?" asked the woman.
The cop replied, "Don't you know that your right arm is missing from the elbow down? It must have been torn off when the truck hit you."
"OH MY GOD!" screamed the woman. "Where's my new bracelet !!!"
Monday, June 7, 2010
Report generation in adobe director..
- Using adobe reader
- Interfacing it via. java program (this one almost worked)
- Wasted time with lots of useless xtras
- Create a HTML template of your report. For instance, if you wanted customer information report. You create a HTML template, fill in all the blanks with $1, $2, ... $n.
- From director, while generating the report, you first read in the template (preferably from root folder\templates\).
- Replace $1, $2, with appropriate values.
- Generate HTML file and open it with default browser.
-------------------------------------------------------------Sample usage is illustrated below:
--------------Report generation Utility class----------------
-------------------------------------------------------------
--Finds and replaces the first occurrence of 'aLookForString' with 'aReplaceString'
--in 'aString' and returns the new string
on findAndReplace me, aString, aLookForString, aReplaceString
n = aLookForString.length -1
is_ok = false
repeat while is_ok = false
place = offset(aLookForString, aString)
if (place = 0) then
is_ok = true
exit repeat
else
put aReplaceString into char place to (place+n) of aString
exit repeat
end if
end repeat
return aString
end
--Saves the text in given filename
on saveText me, text, filename
-- create the FileIO instance
fileObj = new(xtra "FileIO")
-- delete existing file, if any
openFile (fileObj,filename,2)
delete(fileObj)
-- create and open the file
createFile(fileObj,filename)
openFile(fileObj,filename,2)
-- check to see if file opened ok
if status(fileObj) <> 0 then
err = error(fileObj,status(fileObj))
alert "Error:"&&err
return FALSE
end if
-- write the file
writeString(fileObj,text)
-- close the file
closeFile(fileObj)
return TRUE
end
--Reads the text from a given filename
on readFromFile me, filename
-- create the FileIO instance
fileObj = new(xtra "FileIO")
-- open the file
openFile(fileObj,filename,1)
-- check to see if file opened ok
if status(fileObj) <> 0 then
err = error(fileObj,status(fileObj))
alert "Error:"&&err
return ""
end if
-- read the file
text = readFile(fileObj)
-- close the file
closeFile(fileObj)
--return the text
return text
end
oUtilClass = new(script "UtilClass")
--Read html from the template
html = oUtilClass.readFromFile(the moviepath & "\\Templates\\summary report.htm")
--Fill in data..
global strSelectedDate
html = oUtilClass.findAndReplace(html, "$1", someVar)
html = oUtilClass.findAndReplace(html, "$2", anotherVar)
filename = the moviepath & "print.html"
oUtilClass.saveText(html, filename)
--Invoke through a browser..
fileXtra4Obj = xtra("FileXtra4").new()
fileXtra4Obj.fx_FileRunApp(the moviepath & "run.bat")
Therefore, run.bat opens print.html with the default browser, which can then be printed, previewed by the courtesy of browser. Whats more, you also get to fiddle with niche layout settings at runtime. In other operating systems like linux, you just have to replace run.bat with a shell script.
Some Minor Tidbits
What if you wanted to generate a table at runtime? Here's what I'd do:
Generate HTML template from dreamweaver or MS word with one row of data in the table..
For example...
<html>
Some blah blah..
Name: $1 </br>
Age : $2 </br>
<table>
<tr>
<td> Subject </td>
<td> Marks </td>
</tr>
<tr>
<td> Some subject </td>
<td> 85 </td>
</tr>
</table>
</html>
Now, create a file template1_rows.txt containing the row data..<html>
<tr>Here's the big idea. Whenever you build a table, read in the row data template, fill it and append it to the main html. Here's an example. Highlighted code achieves dynamic table generation behavior.
<td> $1 </td>
<td> $2 </td>
</tr>
--Read html from the templateI know, it looks complicated. But atleast this is transparent and you exactly know whats going on. Moreover, this approach gives you unlimited formatting options, works and is free. Once you get a hand of it, it'll seem pretty simple.
html = oUtilClass.readFromFile(the moviepath & "\\Templates\\template1.htm")
--Fill in data..
global strSelectedDate
html = oUtilClass.findAndReplace(html, "$1", name)
html = oUtilClass.findAndReplace(html, "$2", age)
tableRows = ""
--Read in the row template..
rowTemplate = oUtilClass.readFromFile(the moviepath & "\\Templates\\template1_rows.htm")
--Generate table rows..
repeat with row=1 to numRows
tableRow = rowTemplate
tableRow = oUtilClass.findAndReplace(tableRow , "$1", subject)
--Append data to tableRows..
tableRows = tableRows & rowTemplate
end repeat
--Fill in table data..
html = oUtilClass.findAndReplace(html, "$3", tableRows)
filename = the moviepath & "print.html"
oUtilClass.saveText(html, filename)
fileXtra4Obj = xtra("FileXtra4").new()
fileXtra4Obj.fx_FileRunApp(the moviepath & "run.bat")
Controlling print behavior
If you don't want your table to break across pages, you can use . Beware, this only works with opera browser. So be sure to ship your software with opera. Even better, use opera portable (requires no installation), make appropriate changes to run.bat to invoke html with the shipped browser.
Comments and suggestions are welcome. If anyone has simpler and free approach, please let me know by posting comments.
Tuesday, June 1, 2010
Segmentation fault with c++ vector
I was working on "simple ecosystem" project. The code where new fishes are created and added to the ecosystem seg. faulted. Take a look, I cut down unnecessary things to keep this example simple.
for (vector::iterator it = vecPossiblePositions.begin(); it!=vecPossiblePositions.end(); ++it)
{
//create a new fish..
Fish *f = new Fish();
f->setPosition(it->getX(), it->getY());
//This method does a push_back
//operation on some vector
ecosystem->addEcosystemObject(f);
}
Fish *f = NULL;
for (vector::iterator it = vecPossiblePositions.begin(); it!=vecPossiblePositions.end(); ++it)
{
//create a new fish..
f = new Fish();
f->setPosition(it->getX(), it->getY());
//This method does a push_back
//operation on some vector
ecosystem->addEcosystemObject(f);
}
Enter teeki chawal
Here's what you need:
- Cooked rice
- Oil (obviously)
- Mirchi powder, jeera, salt, chopped onions, semi boiled and cut potato (one will do)
- Crushed tomatoes, c, carrots, beans, green peas, corn
- Heat a pan with lots of oil..
- Put jeera (one handful, needs to be more)
- Put onions and fry em' all at med flame
- Once onions are semi fried, put capsicum, potatoes and cook for like 7 mins
- Put remaining veggies and cook for another 7 mins.
- Add mirchi powder, and any other spices you fancy (Dhaniya powder, Hing, Garam masala will also do)
- Let it cook for another 5 mins..(At any point, if you notice that the veggies are burning, add a little bit of crushed tomato puree)
- Add 40% of the crushed tomatoes from the can.
- Cook for 10 mins.
- Now, taste the mixture, it should be slightly spicier, if not, add more spices. Also, at this point you should notice oil separating from the mixture
- Add cooked rice (cold one preferably), and stir for 3-5 mins..