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.

Monday, 30 September 2013

How can I find out if my installed OS is a 32-bit or a 64-bit?

How can I find out if my installed OS is a 32-bit or a 64-bit?

I am a newbie so maybe my question is not so shiny. I wont to install
something (virtualbox) but I have to chose between the 32-bit version and
the 64-bit version according to my OS. Problem is that I don't know/don't
remember what type of OS it is from that point of view.
So my question is the following: Is there any fast and easy way (for a
beginner like me) to find out what kind of OS is using? Thank you!

Touchpad and parts of keyboard frozen after boot on Macbook

Touchpad and parts of keyboard frozen after boot on Macbook

I'm experiencing an issue where, after booting a MacBookAir4-2 (Ubuntu
13.04), the touchpad won't work. Furthermore, the better part of the
keyboard doesn't work either. External USB keyboards and mouses work, and
I have to use them to disable and re-enable the trackpad in the settings
to get the on-laptop one to work, which also enables the keyboard for some
reason.
I do not experience any issues during the reFIND menu or in OS X. Is there
a way to fix this or a script that I can run at startup that can enable
and disable the touchpad?

Jquery Sortable, items inside li are able to be dragged and dropped

Jquery Sortable, items inside li are able to be dragged and dropped

I'm using jquery sortable.
<ul id="gallery">
<li class="image-item gallery-image-item"><i class="btn-comment
icon-comment icon-2x"></i><i class="btn-youtube icon-youtube-play
icon-2x"></i><i class="btn-delete icon-remove"></i></li>
//...more similar li's
</ul>
The problem is, I can drag and drop each li, but the icons situated inside
each li are able to be dragged and dropped as well, separately to it's
parent li. Is there a way to stop this?

Round to 1 decimal places in C#

Round to 1 decimal places in C#

i would like to round my answer 1 decimal places. for example : 6.7,
7.3...etc But when I use Math.round...the answer always come up with no
decimal places ...for example: 6, 7
here is my code that i used:
int [] nbOfNumber = new int[ratingListBox.Items.Count];
int sumInt = 0;
double averagesDoubles;
for (int g = 0; g < nbOfNumber.Length; g++)
{
nbOfNumber[g] = int.Parse(ratingListBox.Items[g].Text);
}
for (int h = 0; h < nbOfNumber.Length; h++)
{
sumInt += nbOfNumber[h];
}
averagesDoubles = (sumInt / ratingListBox.Items.Count);
averagesDoubles = Math.Round(averagesDoubles, 2);
averageRatingTextBox.Text = averagesDoubles.ToString();

Sunday, 29 September 2013

How cassandra replicates data in virtual nodes?

How cassandra replicates data in virtual nodes?

How cassandra replicates data in virtual nodes?
(1) cassandra replicates data randomly in virtual nodes.
http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/architecture/architectureDataDistributeVnodesUsing_c.html#concept_ds_lmw_gnf_fk
"Ring with virtual nodes" image shows like as if cassandra replicates data
randomly in virtual nodes.
or
(2) according to the replication strategy
How cassandra replicates data
If you use virtual nodes, the same idea is used but virtual nodes will be
skipped as replicas if the physical node has already received the key.

Separating multiple email messages in same thread PHP

Separating multiple email messages in same thread PHP

I have a ticketing system on my website in which I need to automatically
send the user an email when I submit a response.
In the email response I send them, I would like to be able to show a
threaded message like:
my response.....
SEPARATOR
FROM ....
ORIGINAL MESSAGE
What should I use for the SEPARATOR so that it will likely be recognized
by most email programs as a threaded message?
Note: I am using the PHP mail() method and am not going to use anything
else at this time.

why can't I create a method in the main method

why can't I create a method in the main method

Hello I am a want create method into main? So this is code where i want
crete method:
import java.io.*;
import java.util.Random;
class input{
public static void main (String args[]){
void Randomises() {
int writabledata;
Random a=new Random();
writabledata=a.nextInt();
}
}}

How can i load the css file in views/css/stylesheet.css in CI? My index file is in views/firstView.php

How can i load the css file in views/css/stylesheet.css in CI? My index
file is in views/firstView.php

I am completely new to code igniter. Thought editing the config.php like
this would work:
$config['index_page'] =
'localhost/Projects/first_CI/application/views/firstView.php';
but its not working :( . Can any one suggest anything

Saturday, 28 September 2013

How to clean the sandbox every time I run the applications?

How to clean the sandbox every time I run the applications?

I am wondering if I could clean up sandbox everytime I run the
application. I don't want to clean and rebuild every time since it takes
long time.

Visual Studio 2012 Design view out of sync

Visual Studio 2012 Design view out of sync

When I'm on the split view of Visual Studio 2012 and I make some changes
on the Code window, the design window does not show the changes and
instead gives me this message "Design view is out of sync with Code view.
Click here to synchronize views".
Is there a way configure Visual Studio to have Design view seamlessly
updated as I write code?

advice/help to finish this algorithn

advice/help to finish this algorithn

/
write a program that reads in a number between 5/95 and calculates change
**********************************************************************************
*************Author:Emma OostryckDate:20/9/13purpose:calculates and prints
out the
change
***************************************************************************
*********************/
Start _algorithm
int cents
int num
module main (void )
print "name" ()
cents = getnum()
end module main
module getnum () /*prompts the user for a number*/
int num
print"please enter a number between 5 and 95 "
scan "num"
if (num < 5 OR >95 ) THEN
print"this is an invalid number please try again "
else if (num != * 5 ) THEN
print"this is not a valid amount"
END IF
return (cents);
end module getnum
module calculatesum (num) /*calculates the change needed*/
int num,int change
change=num/50
num%=50
change=num/20
num%=20
change=num/10
change=num/5
num%=5
end module calculatesum
getnum
module printsum /*prints the change */
print"your total change is /intchange "
end module printsum end_algorithm