Sunday, 1 September 2013

Handle to last run process win32

Handle to last run process win32

How do I get HANDLE to last run process by user? My Application will be
running, has started one process using CreateProcess() or ShellExecute() ,
and then user comes and executes another, independent process, externally.
Forget about user must be doing this and that. We are sure user will run
one and only one application at exactly this point.
How do I get HANDLE to this process? I won't have its name or id or
anything else. All I know is it is being run after my application started
executing or rather after creating a process using one of the mentioned
method above.
Any Help is appreciated.

Saturday, 31 August 2013

Easy quest using SQL request with PHP. Transfer a lot of valors beteen tables in a variable or array.....how?

Easy quest using SQL request with PHP. Transfer a lot of valors beteen
tables in a variable or array.....how?

I have two SQL tables. The first one structure is simple. Just "ID of
user" and "Name". The second one is simple too. "ID of the comment" and
"The comment" and "ID of the creator". I want to show in my site all the
comments that correspond with the "ID of user"
The probleme is we have here a lot of ID and two different tables.
Somethink like that:
$1= $bdd->query("SELECT * FROM comments WHERE id_user=220281");
$2=$1->fetch();
But its imposible because id user is not on the comments table.
I hope you may help me. Thank you.

Inserting Data into MySql from php

Inserting Data into MySql from php

I'm new to php and have been going through tutorials, and have hit a
stump, where I can't seem to find what I'm doing wrong in my code, I
welcome any and all assist, the code below is meant to insert data
previously collected into a table that has those fields outline, in
phpmyadmin:
$SQL = "INSERT INTO users ( 'username', 'password', 'email_address',
'date_of_birth', 'first_name', 'last_name', 'phone', 'address', 'city',
'userlevel') values ('" + $username + "', '" + $password + "', '" +
$email_address + "', '" + $date_of_birth + "', '" + $first_name + "', '"
+ $last_name + "', '" + $phone + "', '" + $address + "', '" + $city + "',
'" + $userlevel + "')";
And then to run that code:
mysql_query($SQL); mysql_close($db_handle); print "Records added to the
database";
I'm not 100% sure whether its the layout or not, for inserting variable
data into MySql, also their is no errors about connecting to the database,
furthermore the print at the end of the function runs, therefore it is not
getting an error and stopping before running the code above.
Once again thank you and all assistance is welcome.

Java Graphics.drawRect being filled?

Java Graphics.drawRect being filled?

Im making a rectangle selector using the mouse, and i have a normal
drawRect rectangle surrounding it. When the width or height goes negative,
The Rectangle is filled. Is there any way to fix this? here is my code:
@SuppressWarnings("serial")
public class Pie extends JPanel{
public boolean running = true;
public Rectangle mouseRect;
public Rectangle rectBounds;
public int x1,y1,x2,y2;
public boolean showRect = false;
public Pie(){
setFocusable(true);
MAdapter mama = new MAdapter();
setDoubleBuffered(true);
this.addMouseListener(new MAdapter());
this.addMouseMotionListener(mama);
setBackground(Color.black);
Thread update = new Thread(){
public void run(){
while(running){
repaint();
try{Thread.sleep(2);}catch(InterruptedException e){}
}
}
};
update.start();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
//if(y2 < y1) y2 = y1;
if(showRect){
g.setColor(new Color(0,250,0,50));
g.fillRect(x1,y1,x2 - x1,y2 - y1);
g.setColor(new Color(0,255,0));
g.drawRect(x1 - 1,y1 - 1,x2 - x1 + 1,y2 - y1 + 1);
}
}
class MAdapter extends MouseAdapter{
public void mousePressed(MouseEvent e){
showRect = true;
x1 = e.getX();
y1 = e.getY();
x2 = e.getX();
y2 = e.getY();
}
public void mouseDragged(MouseEvent e){
x2 = e.getX();
y2 = e.getY();
rectBounds = new Rectangle(x1,y1,x2 - x1, y2 - y1);
}
public void mouseReleased(MouseEvent e){
showRect = false;
rectBounds = new Rectangle(x1,y1,x2 - x1, y2 - y1);
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
}
}
public static void main(String[] args){
JFrame f = new JFrame("Aber");
f.setSize(500,500);
f.setResizable(true);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.add(new Pie());
}
}
Is there anything im doing wrong? thanks in advance.

How to login correctly?

How to login correctly?

I have a login to facebook and if the user is not in my DB then I add him
after the login, but If he is already exists I shouldn't do anything.
My question is how should I deal with it?
To make one more query to the DB that checks if user exists - before
adding it.
To let WCF catch it with UpdateException, and throw it to the client.
Other option?

Loading a table into PostgreSQL with a foreign key produces an error

Loading a table into PostgreSQL with a foreign key produces an error

I am using SymmetricDS database replication software to replicate tables
across databases.
I have this XML defined table for PostgreSQL which I've created:
<table name="ServiceItem">
<column name="ServiceItemID" type="INTEGER" required="true"
primaryKey="true"/>
<column name="ParentItemID" type="INTEGER" />
<foreign-key name="FK_ServiceItem_ServiceItem" foreignTable="ServiceItem">
<reference local="ServiceItemID" foreign="ParentItemID" />
</foreign-key>
</table>
I expect that all parentItemID values MUST exist in the ServiceItemID
column, that's the point of a foreign key.
But I get this error from SymmetricDS when I load it:
[] - JdbcSqlTemplate - ERROR: there is no unique constraint matching given
keys
for referenced table "ServiceItem". Failed to execute: ALTER TABLE
"ServiceItem"
ADD CONSTRAINT "FK_ServiceItem_ServiceItem" FOREIGN KEY ("ServiceItemID")
REFERENCES "ServiceItem" ("ParentItemID")
If I remove the foreign key, everything works as expected. This error
message is confusing me and I'm not sure what I am doing wrong. What does
it mean?

How to redraw my d3.js chart with data from html form?

How to redraw my d3.js chart with data from html form?

I have written small web page that creates a graph with alarms
distribution over 24 hour period, with alarm count being a variable that
drives how many alarms will be send in this period.
After that I have written a small form that will have the alarm count
variable in a input field
<input id="alarm_count_input" type="number"/>
Now I would like to be able to redraw the d3.js graph without page reload,
taking alarm count that user submits with the form / input field.
JsFiddle : http://jsfiddle.net/L42LU/
Code :
<script type="text/javascript">
$(function(){
........
function createDataForD3( alarm_cnt, array) {
var data = [];
for(var i = 0, n=array.length; i< n; i++)
{
data.push({ "hour": i,
"alarms": getRatioForHour(i, array) * alarm_cnt
});
}
return data;
}
var schedule = [1, 1, 1, 1, 4, 1, 1, 3, 2, 3, 4, 1, 1, 1, 1, 1, 6, 1, 1,
1, 1, 1, 1, 1];
var alarm_count = 1000;
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 0.85 * document.width - margin.left - margin.right,
height = 0.9 * document.height - margin.top - margin.bottom;
var x_extent = [-0.5, 23.5];
var y_extent = [0, Math.round(
getMaxAlarmCountForHourInArray(alarm_count,
schedule)[1] * 1.2 ) ];
var x_scale = d3.scale.linear()
.range([0, width])
.domain(x_extent);
var y_scale = d3.scale.linear()
.range([ height, 0])
.domain(y_extent);
var data = createDataForD3( alarm_count , schedule);
var xAxis = d3.svg.axis()
.scale(x_scale)
.orient("bottom")
.ticks(24);
var yAxis = d3.svg.axis()
.scale(y_scale)
.orient("left");
var line = d3.svg.line()
.x(function(d) { return x_scale(d.hour) ; })
.y(function(d) { return y_scale( Math.round( d.alarms)) ; });
var svg = d3.select("body")
.append("svg")
.attr("class", "chart")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top +
")");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("y", margin.bottom)
.attr("x", (width) / 2)
.text("Hour");
svg.append("g")
.classed("x grid ", true)
.attr("transform", "translate(0,"+height+")")
.call(xAxis
.tickSize(-height,0,0)
.tickFormat("")
);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 8)
.attr("x", -20)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Alarms per hour");
svg.append("g")
.classed("y grid", true)
.call(yAxis
.tickSize(-width,0,0)
.tickFormat("")
)
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line);
svg.append("g")
.selectAll("circle")
.data(data)
.enter()
.append("circle");
d3.selectAll("circle")
.attr("cx", function(d){ return x_scale(d.hour); })
.attr("cy", function(d){ return y_scale(d.alarms); })
.attr("r", 6);
$("#alarm_count_input").val(alarm_count);
});
</script>
<form id="form1" role="form" onSubmit="return false;">
<div class=form-group">
<label for="alarm_count_input" >Alarm count</label><br>
<input id="alarm_count_input" class="form-control" type="number"
placeholder="Alarm count" min="0" max="999999" step="1" />
</div>
</form>
</body>