Thursday, 8 August 2013

Nested dictionary in python

Nested dictionary in python

Hi This is my first question on Stack Overflow. I have the following data
where first column are ID, second column are category, third column is
items and fourth column is price. I am try to find each ID's spend sum by
category(column2 from left): A sample output will be: like below. However,
I am stuck on the elif statement and says it has keyError:'A': I really do
not know what is wrong. If anyone knows please help me out. Thanks very
much.
***sample output***
Spending by B fuel - 19.60 grocery - 11.42



A|groceries|cereal|15.50 A|groceries|milk|14.75 A|tobacco|cigarettes|25.00
A|fuel|gasoline|54.90 B|fuel|propane|19.60 B|groceries|apple|11.42
C|tobacco|cigarettes|25.00



for line in fileinput.input(fo1):
#print line
line =str.rstrip(line)
line = line.split('|')
print line[0],line[1]
(name,category,items,price)=line
if line[0] in report2 and line[1] in report2:
report2[line[0]][line[1]] += float(price)
elif line[1] in report2[line[0]]:
report2[line[0]][line[1]]+=float(price)
else:
report2[line[0]][line[1]]=float(price)
print report2.keys
print report2.items()

Negative Margin in Firefox Using Bootstrap

Negative Margin in Firefox Using Bootstrap

I am using Twitter Bootstrap plugin, mainly just the grid system currently.
I am trying to put one row on top of another doing some stuff for
responsive design.
In Chrome this works perfectly:
<div class="container">
<div class="row">
<div class="content">
abcd
</div>
</div>
<div class="row" id="moveUpRow">
<div class="content">
efgh
</div>
</div>
</div>
CSS:
.row {
height: 200px;
}
#moveUpRow {
margin-top: -200px;
}
But in Firefox and IE they both ignore the negative margin. I have tried
top: -200px, but that just moves up the row and not all of the elements
below the row. Leaving big white space.
Any other solutions to this problem? Or any suggestions on how to "pull"
up any content below the row?

Simple Java Program Strange Output

Simple Java Program Strange Output

This is my program...
import java.lang.Math;
class SquareRoot
{
public static void main(String args[])
{
try
{
System.out.println("Enter A Number To Find its Square Root");
System.out.flush();
double x = (double) System.in.read();
double y;
y = Math.sqrt(x);
System.out.println("Square Root of " + x + " is " + y);
}
catch (Exception e)
{
System.out.println("I/O Error! Humein Maaf Kar Do Bhaaya");
}
}
}
If I enter 75 as input it shows.. Square Root of 55.0 is <55's square root>
On entering 23 it shows Square Root of 50.0. Where am I wrong? No problems
in compilation.
I am using DrJava IDE. JDK 7u25 Compiler. Windows 7 32 bit.

SSIS Performance drop when adding parameters

SSIS Performance drop when adding parameters

I'm using an OLE DB Source in SSIS to pull data rows from a SQL Server
2012 database:
SELECT item_prod.wo_id, item_prod.oper_id, item_prod.reas_cd,
item_prod.lot_no, item_prod.item_id, item_prod.user_id, item_prod.seq_no,
item_prod.spare1, item_prod.shift_id, item_prod.ent_id,
item_prod.good_prod, item_cons.lot_no as raw_lot_no, item_cons.item_id as
rm_item_id, item_cons.qty_cons
FROM item_prod
LEFT OUTER JOIN item_cons on item_cons.wo_id=item_prod.wo_id AND
item_cons.oper_id=item_prod.oper_id AND item_cons.seq_no=item_prod.seq_no
AND item_prod.lot_no=item_cons.fg_lot_no
This works great, and is able to pull around 1 million rows per minute
currently. A left outer join is used instead of a lookup due to much
better performance when using no cache, and both tables may contain
upwards of 40 million rows.
We need the query to only pull rows that haven't been pulled in a previous
run. The last run row_id gets stored in a variable and put at the end of
the above query:
WHERE item_prod.row_id > ?
On the first run, the parameter will be -1 (to parse everything).
Performance drops between 5-10x by adding the where clause (1 million rows
per 5-10 minutes). What is causing such a significant performance drop,
and is there a way to optimize it?

403 error while posting to Sharepoint REST social API

403 error while posting to Sharepoint REST social API

I am having a problem with Sharepoint Rest social API. Here's the code to
like a post I got from googling around
function likePost() {
var postId =
'1.0f435d74164149cfa76e19ad21dc7c2e.8a7874906a9348189f2fb83295b598d5.06ff4087162c48dcb43828e4ddf82c38.98b9fc73d5224265b039586688b15b98.8ec3fc561f084e6b98bfb117e9c23022.64.64.1';
$.ajax( {
url: "/_api/social.feed/Post/Like",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
},
data: JSON.stringify({
'ID': postId
}),
success: function (data) {
alert("Success");
var jsonObject = data.d.ID;
alert(jsonObject);
},
error: function (xhr, ajaxOptions, thrownError) {
alert("POST error:\n" + xhr.status + "\n" + thrownError);
}
});
}
However when I try this on my Sharepoint site, I always get 403 FORBIDDEN
error. Any help would be appreciated.

Can I obtain a pointer to a map value in golang?

Can I obtain a pointer to a map value in golang?

I'm trying to use Go's flag package to dynamically generate FlagSets and
collect the results in a map from flagname -> flag value.
My code looks like this:
import "flag"
fs := flag.NewFlagSet(strings.Join(commands, " "), flag.ExitOnError)
requiredFlags := []string{"flagA", "flagB"}
flags := make(map[string]string)
for _, f := range requiredFlags {
flags[f] = *fs.String(f, "", "")
}
This code compiles, but the map never gets updated after the FlagSet fs is
parsed, so the values of "flagA" and "flagB" are both "". So this makes
sense to me; flags is of type map[string]string after all, not
map[string]*string. Unfortunately, I can't seem to fix this problem using
pointers. I've tried every combination of referencing and dereferencing I
can think of and I either end up with a nil pointer dereference (runtime
error) or invalid indirect (compile time error).
How can I set up the map and FlagSet such that the map values are
populated after the FlagSet is parsed?

Wednesday, 7 August 2013

Creating a browser Exit popup

Creating a browser Exit popup

What I want to do is detecting the browser close event(on browser unload)
and open up a new pop up where we have some options like (give a feedback,
go to the page again , mail me a report etc). At the same time I want the
parent window alive till the user select an option in pop up window. I
tried following and it seems not working.
$(window).bind('beforeunload', function(event){
event.preventDefault();
});
Please give me the right direction for achieving this.