python to run simultaneously
I am trying to create 86 instances of task.py to run simultaniously. any
help please.
import sys
import subprocess
for file in range(86):
subprocess.call([sys.executable,'task.py',str(file)+'in.csv',str(filen)+'out.csv'])
Bolk
Thursday, 3 October 2013
Wednesday, 2 October 2013
php dynamically generate json
php dynamically generate json
i am trying to combine AngularJS with a php backend. Right now i am trying
to generate a json with php to return it to a http request to angular. So
far i created this php.
$dbhost = "localhost";
$dbport = "5432";
$dbname = "fixevents";
$dbuser = "postgres";
$dbpass = "123";
$connect = pg_connect("host=" . $dbhost . " port=" . $dbport . " dbname="
. $dbname . " user=" . $dbuser . " password=" . $dbpass);
$query = "SELECT contact_firstname, contact_lastname, contact_id,
contact_email FROM contact WHERE user_id = 1";
$result = pg_query($connect, $query);
$comma = '';
$json = '[';
while ($row = pg_fetch_array($result)) {
$json .= $comma . '{';
$json .= 'contact_firstname:"' . addslashes($row['contact_firstname'])
. '",';
$json .= 'contact_lastname:"' . addslashes($row['contact_lastname']) .
'",';
$json .= 'contact_id:' . addslashes($row['contact_id']) . ',';
$json .= 'contact_email:[';
$contact_email = explode(',,,', addslashes($row['contact_email']));
$comma_email = '';
foreach($contact_email as $email) {
$json .= $comma_email . '"' . $email . '"';
$comma_email = ',';
}
$json .= ']';
$json .= '}';
$comma = ',';
}
$json .= ']';
echo $json;
But i read some comments by greater minds than mine :) and they said
creating the json manually is not the best idea. Can anyone tlel me how to
generate this json is a more stylish way? I saw something about
json_endode and array but i dont know how to add a list inside a list. I
have a list and inside each list item i have another list with emails
because 1 contact can have more emails. My generated JSON right now looks
like this
[{contact_firstname:"Daniel",contact_lastname:"Pacuraru",contact_id:1,contact_email:["pacurarudaniel@gmail.com","hello@pacurarudaniel.com"]},{contact_firstname:"Someone",contact_lastname:"Else",contact_id:2,contact_email:["someone.else@gmail.com"]}]
Thank you, Daniel!
i am trying to combine AngularJS with a php backend. Right now i am trying
to generate a json with php to return it to a http request to angular. So
far i created this php.
$dbhost = "localhost";
$dbport = "5432";
$dbname = "fixevents";
$dbuser = "postgres";
$dbpass = "123";
$connect = pg_connect("host=" . $dbhost . " port=" . $dbport . " dbname="
. $dbname . " user=" . $dbuser . " password=" . $dbpass);
$query = "SELECT contact_firstname, contact_lastname, contact_id,
contact_email FROM contact WHERE user_id = 1";
$result = pg_query($connect, $query);
$comma = '';
$json = '[';
while ($row = pg_fetch_array($result)) {
$json .= $comma . '{';
$json .= 'contact_firstname:"' . addslashes($row['contact_firstname'])
. '",';
$json .= 'contact_lastname:"' . addslashes($row['contact_lastname']) .
'",';
$json .= 'contact_id:' . addslashes($row['contact_id']) . ',';
$json .= 'contact_email:[';
$contact_email = explode(',,,', addslashes($row['contact_email']));
$comma_email = '';
foreach($contact_email as $email) {
$json .= $comma_email . '"' . $email . '"';
$comma_email = ',';
}
$json .= ']';
$json .= '}';
$comma = ',';
}
$json .= ']';
echo $json;
But i read some comments by greater minds than mine :) and they said
creating the json manually is not the best idea. Can anyone tlel me how to
generate this json is a more stylish way? I saw something about
json_endode and array but i dont know how to add a list inside a list. I
have a list and inside each list item i have another list with emails
because 1 contact can have more emails. My generated JSON right now looks
like this
[{contact_firstname:"Daniel",contact_lastname:"Pacuraru",contact_id:1,contact_email:["pacurarudaniel@gmail.com","hello@pacurarudaniel.com"]},{contact_firstname:"Someone",contact_lastname:"Else",contact_id:2,contact_email:["someone.else@gmail.com"]}]
Thank you, Daniel!
Reading packets hex values
Reading packets hex values
We have a system which is capable of capturing network packets. Below is
how we can show all the hex values of each byte.
for(i = 0; i < h->caplen; i++)
printf("%02X ", p[i]);
We are looking ways into how to extract urls if exist and also some
packets have source IP address. Any best mechanism to help on this task ?
We have a system which is capable of capturing network packets. Below is
how we can show all the hex values of each byte.
for(i = 0; i < h->caplen; i++)
printf("%02X ", p[i]);
We are looking ways into how to extract urls if exist and also some
packets have source IP address. Any best mechanism to help on this task ?
Tuesday, 1 October 2013
To find height of a binary search tree
To find height of a binary search tree
/* * To find the Height of a BST tree */
public void findHeight(){
if(this.root == null){
System.out.println("BST Tree is Empty ");
}
else
findHeight(this.root);
}
public int findHeight(Tnode temp){
if(temp == null){
System.out.println("BST Tree is Empty ");
return -1;
}
else{
return 1 + Math.max(findHeight(temp.getLeft())
,findHeight(temp.getRight()) ) ;
}
}
Program is running infinitely.Not able to find the reason , It would be
helpfull ,if some one guides me
Thanks in advance
/* * To find the Height of a BST tree */
public void findHeight(){
if(this.root == null){
System.out.println("BST Tree is Empty ");
}
else
findHeight(this.root);
}
public int findHeight(Tnode temp){
if(temp == null){
System.out.println("BST Tree is Empty ");
return -1;
}
else{
return 1 + Math.max(findHeight(temp.getLeft())
,findHeight(temp.getRight()) ) ;
}
}
Program is running infinitely.Not able to find the reason , It would be
helpfull ,if some one guides me
Thanks in advance
C# Optional Parameters and Default Value
C# Optional Parameters and Default Value
I wrote a method that takes optional parameter
public void ExampleMethod(int maxValue = 20)
{
...
}
and i will use it as
int param = GetSomeValue();
ExampleMethod(param < 20 ? param : use_your_default_value_as_specified);
if it is less than 20, use param, else use your own default value
implemented in ExampleMethod (in this example it's 20).. How can i tell
that "use_your_default_value_as_specified" to compiler ?
I know i can do this by
int param = GetSomeValue();
ExampleMethod(param);
public void ExampleMethod(int maxValue)
{
if(maxValue > 20)
maxValue = 20;
}
but i want to send the correct value before execution of ExampleMethod
I wrote a method that takes optional parameter
public void ExampleMethod(int maxValue = 20)
{
...
}
and i will use it as
int param = GetSomeValue();
ExampleMethod(param < 20 ? param : use_your_default_value_as_specified);
if it is less than 20, use param, else use your own default value
implemented in ExampleMethod (in this example it's 20).. How can i tell
that "use_your_default_value_as_specified" to compiler ?
I know i can do this by
int param = GetSomeValue();
ExampleMethod(param);
public void ExampleMethod(int maxValue)
{
if(maxValue > 20)
maxValue = 20;
}
but i want to send the correct value before execution of ExampleMethod
How to change firefox startpage from Ubuntu's to Firefox's=?iso-8859-1?Q?=3F_=96_askubuntu.com?=
How to change firefox startpage from Ubuntu's to Firefox's? – askubuntu.com
Well, I installed Ubuntu GNOME Remix. Now I miss the "Restore Previous
Session" button that Firefox start page has. How do I get it back? This is
what I want:
Well, I installed Ubuntu GNOME Remix. Now I miss the "Restore Previous
Session" button that Firefox start page has. How do I get it back? This is
what I want:
Odds of choosing n members of a x sized subset of a y sized set.
Odds of choosing n members of a x sized subset of a y sized set.
Lets say I have a bag of 8 rocks. 3 rocks are red, the rest are black. I
choose, randomly, with replacement, 3 rocks. What are the odds that at
least one that I choose is red?
It seems in first pass that the odds if I draw just one time, is 3/8. If I
draw twice, then, would the odds be 6/8? Doesn't seem so, since drawing 3
times would by that reasoning given 9/8 > 1.0, so somewhere I've gone
wrong.
To expand to the general case, how do I determine the odds of choosing n
members of a x sized subset of a y sized set, if I draw z times with
replacement. The real world problem I'm really trying to solve involves
figures on the order of thousands.
Apologies if some of my terminology is off. Been a few years since I took
discrete...
Lets say I have a bag of 8 rocks. 3 rocks are red, the rest are black. I
choose, randomly, with replacement, 3 rocks. What are the odds that at
least one that I choose is red?
It seems in first pass that the odds if I draw just one time, is 3/8. If I
draw twice, then, would the odds be 6/8? Doesn't seem so, since drawing 3
times would by that reasoning given 9/8 > 1.0, so somewhere I've gone
wrong.
To expand to the general case, how do I determine the odds of choosing n
members of a x sized subset of a y sized set, if I draw z times with
replacement. The real world problem I'm really trying to solve involves
figures on the order of thousands.
Apologies if some of my terminology is off. Been a few years since I took
discrete...
Subscribe to:
Comments (Atom)