Thursday 3 October 2013

Background task - how to stop in a controlled manner?

Background task - how to stop in a controlled manner?

I'm developing a WPF application that will have an "indexing service"
running as a background task. The indexing service will utilise a
FileSystemWatcher that monitors a folder - when a file changes the
indexing service will read in the file contents and update an index (I'm
using Lucene.Net). My indexing service is a singleton, and will be started
during application startup like this:-
new TaskFactory().StartNew(_indexingService.StartService);
The StartService() method looks something like this:-
private readonly ManualResetEvent _resetEvent = new ManualResetEvent(false);
public void StartService()
{
var watcher = new FileSystemWatcher
{
// Set the properties
};
watcher.Changed += UpdateIndexes();
_resetEvent.WaitOne();
}
When the application is closing, I intend to call this method, which I
understand will end the indexing service background task:-
public void StopService()
{
_resetEvent.Set();
}
First of all, is this the right "pattern" for starting and stopping a
background task that should run for the lifetime of an application?
Second, how "graceful" would this shutdown be? Let's say that the watcher
Changed event handler has fired and is iterating through the files,
reading them and updating the indexes. If the task was stopped, will this
processing be aborted mid-flow, or will the event handler method run to
completion first?

Wednesday 2 October 2013

Opencv246 Visua Studio 2012 ! on windows 7

Opencv246 Visua Studio 2012 ! on windows 7

I am desperate for an Answer with Opencv246, with Visual Studio 2012, on
Windows 7.
To Display an Image and on compiling this I am getting 212 syntax errors
for operations.hpp file. Please help
using namespace cv;
#include <stdio.h>
#include <algorithm>
#include<string>
#include<opencv2\opencv.hpp>
#include<opencv2\core\operations.hpp
void main()
{
Mat img;
img = imread("test.jpg");
namedWindow("t");
imshow("t",img);
cvWaitKey(0);`
}

Meteor publish - How to publish data and check using profile information

Meteor publish - How to publish data and check using profile information

My question is really simple but unfortunately I didn't found anywhere.
I have a collection of maps for example and I'm using
Meteor.user().profile.mapsId to check if that user is allowed to see that
maps.
First approach:
server/server.js
Meteor.publish('map', function (mapOwner) {
var user = Meteor.user();
var mapId = user.profile.mapId;
return Map.find({mapOwner: mapId});
});
Didn't work because publish don't accept Meteor.user();
Second approach:
server/server.js
Meteor.publish('map', function (mapOwner) {
return Map.find({mapOwner: Meteor.call('mapsCall')});
});
collections/maps.js
Map = new Meteor.SmartCollection('map');
Meteor.methods({
mapsCall: function() {
var user = Meteor.user();
var startupId = user.profile.startupId;
return startupId;
}
});
When I call Map.find().fetch() don't have anything..
What is the right approach?

The method put(Integer, MyClass) in the type Map is not applicable for the arguments (String, int)

The method put(Integer, MyClass) in the type Map is not applicable for the
arguments (String, int)

private Map<Integer,MyClass> calc()
{
Map<Integer,MyClass> closest = new HashMap<Integer,MyClass>();
//...
closest.put("index",(i+1));
closest.put("poi",myclass_element);
return closest;
}
The method put(Integer, MyClass) in the type Map is not applicable for the
arguments (String, int)
The function calc should return myclass_element and an integer value
(i+1). How to to do this?

Mysql; CASE; multiple WHEN ? THEN ?. How to create data for ? with foreach

Mysql; CASE; multiple WHEN ? THEN ?. How to create data for ? with foreach

Created this
$insertData = array();
foreach ($_POST['entry_id'] as $i => $entry_id) {
$when_then .= 'WHEN ? THEN ? ';
$insertData[] = $_POST['entry_id'][$i];
$insertData[] = $_POST['transaction_partner_name'][$i];
$insertData[] = $_POST['entry_id'][$i];
$insertData[] = $_POST['registration_number'][$i];
$insertData[] = $_POST['entry_id'][$i];
$placeholders_for_number_renamed .= '?,';
}
$placeholders_for_number_renamed = rtrim($placeholders_for_number_renamed,
',');
$sql = "
UPDATE 2_1_transactionpartners SET
CompanyName = CASE NumberRenamed
$when_then
END,
RegistrationNumber = CASE NumberRenamed
$when_then
END
WHERE NumberRenamed in ($placeholders_for_number_renamed)";
try {
$stmt = $db->prepare($sql);
$stmt->execute($insertData);
}
But can not match $insertData with ? (must replace ? with
corresponding/necessary $insertData)
qyery is this
UPDATE 2_1_transactionpartners SET
CompanyName = CASE NumberRenamed
WHEN ? THEN ? WHEN ? THEN ?
END,
RegistrationNumber = CASE NumberRenamed
WHEN ? THEN ? WHEN ? THEN ?
END
WHERE NumberRenamed in (?,?)
And array of $insertData is this
Array
(
[0] => 11
[1] => name 2
[2] => 11
[3] => number 2
[4] => 11
[5] => 10
[6] => name 1
[7] => 10
[8] => number 1
[9] => 10
)
Starting from [2] values goes to wrong place. [2] must go to the first ?
in RegistrationNumber = CASE NumberRenamed WHEN ? THEN ? but it (?) goes
to the third ? in CompanyName = CASE NumberRenamed WHEN ? THEN ? WHEN ?
I understand that in foreach must create $insertData in some other order,
but can not understand correct order.
Tried like $entry_id_for_company_name[] =
array_merge($_POST['entry_id'][$i],
$_POST['transaction_partner_name'][$i]); but this is not solution...
No idea at the moment. Please advice

Tuesday 1 October 2013

TextIO program not giving the desired output

TextIO program not giving the desired output

OK, time to give the noob a hard time. I am writing a program that is
supposed to use an algorithm to write all even integers from 1 to 100 to a
file, close the file, then display the results. Then id is supposed to
append the file with all of the odd integers from 1 to 100, close the
file, reopen and display the results. Something like: 1st list - 2, 4, 6,
8, ......., 98, 100 2nd list - 2, 4, 6, 8, ......., 98, 100, 1 , 3, 5,
...., 97, 99
I get the even(1st) list fine. The 2nd list displays just the odd numbers.
Sure it is something simple, usually is. My brain is mush right now and I
am not seeing it. Thanks for any help!!
package textFileIO;
import java.io.*;
public class TextFileIO {
public static void main(String[] args) throws Exception {
//Create newFile
File newFile = new File("numbers.dat");
newFile.createNewFile();
int evenNum = 0;
int oddNum = 0;
try{
BufferedWriter writer = new BufferedWriter(new FileWriter(newFile));
//Loop from 1 to 100
for (int i = 2; i <= 100; i+=2)
{
evenNum += i + 1;
writer.write("" + i + ", ");
}
writer.newLine();
writer.close();
BufferedReader reader = new BufferedReader(new FileReader(newFile));
System.out.println(reader.readLine());
reader.close();
BufferedWriter writer2 = new BufferedWriter(new FileWriter(newFile));
for(int i = 1; i < 100; i +=2) {
oddNum += i;
writer2.write("" + i + ", ");
}
writer2.newLine();
writer2.close();
BufferedReader reader2 = new BufferedReader(new FileReader(newFile));
System.out.printf(reader2.readLine());
}
catch (Exception e){
}
}
}

Is the function $f(x)= {\sin x \over x}$ uniformly continuous over $\mathbb{R}$?

Is the function $f(x)= {\sin x \over x}$ uniformly continuous over
$\mathbb{R}$?

Is the function $$f(x)= {\sin x \over x}$$ Uniformly continuous over $R$
How do i approach this ? I need some hints.

Prove that $(0,1)$ is cardinally equivalent to $[0,1)$

Prove that $(0,1)$ is cardinally equivalent to $[0,1)$

How's this done?
Also, I am wondering, are all subsets of $\mathbb{R}$ cardinally
equivalent to each other? If not, why not?

Counter examples for the following regarding sepation axioms. [on hold]

Counter examples for the following regarding sepation axioms. [on hold]

Please provide examples of the following: 1. A regular space which is not
T1. 2. A regular space which is not normal (other than the Sorgenfrey
plane). 3. A normal space which is not T1.