Anyone care to guess what currentIndex is at the end of execution?
int[] ints = new int[] { -1, 12, 26, 41, 52, -1, -1 };
int currentIndex = ints.Min();
It's 110. Does anyone know why?
Hello Folks,
I am trying to develop a application where
The user 'X' has logged into Facebook
app has a set of email addresses (possible friends of user 'X')
app gets the list of friends of user 'X' (uids)
Want to check if user with email address [email protected] is a valid facebook user by using email address and is user X's friend (basically a uid to email mapping)
Thanks!
Hi. Please see my code below.
ifstream myLibFile ("libs//%s" , line); // Compile failed here ???
I want to combine the path string and open the related file again.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("libs//Config.txt");
// There are several file names listed in the COnfig.txt file line by line.
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
// Read details lib files based on the each line file name.
string libFileLine;
ifstream myLibFile ("libs//%s" , line); // Compile failed here ???
if (myLibFile.is_open())
{
while (! myLibFile.eof() )
{
print "success";
}
myLibFile.close();
}
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
Apologies for the indescriptive title, however it's the best I could think of for the moment.
Basically, I've written a singleton class that loads files into a database. These files are typically large, and take hours to process. What I am looking for is to make a method where I can have this class running, and be able to call methods from within it, even if it's calling class is shut down.
The singleton class is simple. It starts a thread that loads the file into the database, while having methods to report on the current status. In a nutshell it's al little like this:
public sealed class BulkFileLoader {
static BulkFileLoader instance = null;
int currentCount = 0;
BulkFileLoader()
public static BulkFileLoader Instance
{
// Instanciate the instance class if necessary, and return it
}
public void Go() {
// kick of 'ProcessFile' thread
}
public void GetCurrentCount() {
return currentCount;
}
private void ProcessFile() {
while (more rows in the import file) {
// insert the row into the database
currentCount++;
}
}
}
The idea is that you can get an instance of BulkFileLoader to execute, which will process a file to load, while at any time you can get realtime updates on the number of rows its done so far using the GetCurrentCount() method.
This works fine, except the calling class needs to stay open the whole time for the processing to continue. As soon as I stop the calling class, the BulkFileLoader instance is removed, and it stops processing the file. What I am after is a solution where it will continue to run independently, regardless of what happens to the calling class.
I then tried another approach. I created a simple console application that kicks off the BulkFileLoader, and then wrapped it around as a process. This fixes one problem, since now when I kick off the process, the file will continue to load even if I close the class that called the process. However, now the problem I have is that cannot get updates on the current count, since if I try and get the instance of BulkFileLoader (which, as mentioned before is a singleton), it creates a new instance, rather than returning the instance that is currently in the executing process. It would appear that singletons don't extend into the scope of other processes running on the machine.
In the end, I want to be able to kick off the BulkFileLoader, and at any time be able to find out how many rows it's processed. However, that is even if I close the application I used to start it.
Can anyone see a solution to my problem?
I have a database with blog entries in it. The desired output I am trying to acheive is 3 entrys displayed using the css3 multi paragraph and then another 3(or more) formatted with the codeigniter Character_limiter. So I need 3 displays formatted one way and 3+ formatted another way on the same page.
So far this is what I have, but i do not know how to format the sql to achieve what I want. I can call all posts in descending order like I want, but dont know how to separate the code to achieve my output
Controller:
$this->db->order_by('id', 'DESC');
$this->db->limit('2');
$query = $this->db->get('posts');
if($query->result())
$data = array();
{
$data['blog'] = $query->result();
}
$data['title'] = 'LemonRose';
$data['content'] = 'home/home_content';
$this->load->view('template1', $data);
View:
<?php if (isset($blog)): foreach ($blog as $row): ?>
<span class="title"><?php echo $row->title; ?> </span>
<?php echo $row->date; ?>
<div class="split"><?php echo $row->post =$this->typography->auto_typography($row->post); ?></div>
<?php echo 'Post #',$row->id; ?>
<p> Trackback URL: <? echo base_url()."trackbacks/track/$row->id";?></p>
<hr />
<?php endforeach;
endif;
?>
The split class is multiple columns. I tried 2 different querys but dont know how to separate all the post displays. Also one query always overides the second and produces all split or all character limited paragraphs.
Im lost here lol. Thanks
in my cms i have index.php, where client must enter username and password. if they are correct, he'll moove to admin.php, where the cms is.
but now hacker can enter to cms/admin.php, so my security now is awful.
i know, that i can use $_SESSION variable.
index.php - i can give some value to $_SESSION['success']:
$_SESSION['success'] = TRUE, and in admin.php just verify it
admin.php
if($_SESSION['success'] == TRUE)
{
my script here...
}
else header("Location: index.php");
but i want to rich this effect without SESSION.
could you give me an idea, how can i do it?
thanks
Hello I have been having a problem with django while trying to work with datetime. In my webapp I have a table like so when I run server.
ID Owing
1 -100 (All the same value)
2 -100
3 -100
. .
. .
. .
It has in one column Invoice id and the other owing. One-one relationship as well. sow for example owing value for 1 is 100. Unfortunately, this is where it all goes wrong because throughout column (Owing), it is giving me the owing value for ID=1. I want each ID to give me their owing value.
Here is my view. I also wonder if I may need a for loop somewhere as well.
def homepage(request):
invoices_list = Invoice.objects.all()
invoice_name = invoices_list[0].client_contract_number.client_number.name
invoice_gross = invoices_list[0].invoice_gross
payment_date = invoices_list[0].payment_date
if payment_date <= datetime.now():
owing = invoice_gross
if payment_date > datetime.now():
owing = 0
else: owing= 0
return render_to_response(('index.html', locals()), {'invoices_list': invoices_list ,'invoice_number':invoice_number, 'invoice_name':invoice_name, 'invoice_gross':invoice_gross, 'payment_date':payment_date, 'owing': owing}, context_instance=RequestContext(request))
EDIT: Here is my template. The thing is the function owing is not in my models so saying {{invoices.owing}} wont work.
{% for invoices in invoices_list %}
<tr>
<td>{{invoices.invoice_number}}</td>
<td>{{invoices.invoice_contact}}</td>
<td>{{invoices.client_contract_number}}</td>
<td>{{invoices.payment_date|date:"d M Y"}}</td>
<td>{{invoices.invoice_gross}}</td>
<td>{{owing}}</td>
{% endfor %}
Hi,
When creating a branch, what are the implications of selecting the following?
Create copy in the repository from:
HEAD revision in the repository
Specific revision the repository
Working copy
Hi all,
I've used the following code to do an XSLT translation in PHP and save the result SVG file into a sub folder:
$command = $java . $saxon . $target2 . ' ' . $xsl2.' '.$param;
ob_start();
passthru($command, $result);
$content_grabbed=ob_get_contents();
ob_end_clean();
$info = pathinfo($_FILES['file']['name']);
$file_name= basename($_FILES['file']['name'],'.'.$info['extension']);
$myFile = "images/convert/".$file_name."_".$_POST["mydropdown"].".svg";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $content_grabbed);
fclose($fh);
It does a very simple SVG to SVG transformation, and created the resulting SVG file.
the $command is just a simple java -jar saxon.jar input.xml stylesheet java command. The current situation is ,the file gets created perfectly, however, the error gets shown in browser, probably because I inserted the "ob_start" before passthru() command.
I am thinking of making use of an argument that comes with the saxon.jar, that is "-o output_file_name". Because the final purpose is not to display the resulting SVG to the browser, but instead creating an SVG file ,and provide the link to the user for downloading.
Are there any better ways to handle this problem, I am still thinking about how to get rid of the result that gets shown in the browser that is sent by the "passthru()". Thanks in advance for suggestions!
Is there a difference between declaring a static variable outside of a function and declaring a static variable inside a function?
Also, what's the difference between declaring a variable as static and just declaring an extern variable?
right now I have this line, and it worked until I had whitespace in the second field.
svn status | grep '\!' | gawk '{print $2;}' > removedProjs
is there a way to have awk print everything in $2 or greater? ($3, $4.. until we don't have anymore columns?)
I suppose I should add that I'm doing this in a windows environment with cygwin.
Trying to use regex refind tag to find the content within the brackets in this example using coldfusion
joe smith <[email protected]>
The resulting text should be
[email protected]
Not having any luck. Any suggestions?
public static void main(String[] args)
{
int [][]shatner = new int[1][1];
int []rat = new int[4];
shatner[0] = rat;
System.out.println(shatner[0][3]);
}
surprised, The answer is 0, Java doesn't check this kind of indexOutOfBound error?
How do I split the UIPicker into multiple parts, like the date picker only not the Day, month, and year - my own specified variables such as - Gender and age?
I have recently started using the excellent Texter. I wanted to set up a shortcut for creating html comments. However that it seems that the exclamation character (!) has special significance in the program, and so does not come out in script mode.
This character is of course required for...<!-- html comment here -->
Here is the code I tried to create the shortcut...
{HOME}<!-- {END}{BS} -->
Just wondering if there is a way of getting around this problem??
Cheers
I'm 15 and have just started using source control systems to manage my code a little better, so I'm a little new to this stuff. Right now I have this repository:
[a]---[b]---[d]---[f] master
\
\
[c]---[e] develop
I want to wind up here:
[a]---[b]---[d]---[f]---[g] master
\ /
\ /
[c]---[e]---/ develop
where g is equivalent to performing commits [c] and [e] on [f]. This is git checkout master; git merge develop, right?
Hi,
I have this POSIX thread:
void subthread(void)
{
while(!quit_thread) {
// do something
...
// don't waste cpu cycles
if(!quit_thread) usleep(500);
}
// free resources
...
// tell main thread we're done
quit_thread = FALSE;
}
Now I want to terminate subthread() from my main thread. I've tried the following:
quit_thread = TRUE;
// wait until subthread() has cleaned its resources
while(quit_thread);
But it does not work! The while() clause does never exit although my subthread clearly sets quit_thread to FALSE after having freed its resources!
If I modify my shutdown code like this:
quit_thread = TRUE;
// wait until subthread() has cleaned its resources
while(quit_thread) usleep(10);
Then everything is working fine! Could someone explain to me why the first solution does not work and why the version with usleep(10) suddenly works? I know that this is not a pretty solution. I could use semaphores/signals for this but I'd like to learn something about multithreading, so I'd like to know why my first solution doesn't work.
Thanks!
I'm using the Windows API to get audio input. I've followed all the steps on MSDN and managed to record audio to a WAV file. No problem. I'm using multiple buffers and all that. I'd like to do more with the buffers than simply write to a file, so now I've got a callback set up. It works great and I'm getting the data, but I'm not sure what to do with it once I have it.
Here's my callback... everything here works:
// Media API callback
void CALLBACK AudioRecorder::waveInProc(HWAVEIN hWaveIn, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
// Data received
if (uMsg == WIM_DATA)
{
// Get wav header
LPWAVEHDR mBuffer = (WAVEHDR *)dwParam1;
// Now what?
for (unsigned i = 0; i != mBuffer->dwBytesRecorded; ++i)
{
// I can see the char, how do get them into my file and audio buffers?
cout << mBuffer->lpData[i] << "\n";
}
// Re-use buffer
mResultHnd = waveInAddBuffer(hWaveIn, mBuffer, sizeof(mInputBuffer[0])); // mInputBuffer is a const WAVEHDR *
}
}
// waveInOpen cannot use an instance method as its callback,
// so we create a static method which calls the instance version
void CALLBACK AudioRecorder::staticWaveInProc(HWAVEIN hWaveIn, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
// Call instance version of method
reinterpret_cast<AudioRecorder *>(dwParam1)->waveInProc(hWaveIn, uMsg, dwInstance, dwParam1, dwParam2);
}
Like I said, it works great, but I'm trying to do the following:
Convert the data to short and copy into an array
Convert the data to float and copy into an array
Copy the data to a larger char array which I'll write into a WAV
Relay the data to an arbitrary output device
I've worked with FMOD a lot and I'm familiar with interleaving and all that. But FMOD dishes everything out as floats. In this case, I'm going the other way. I guess I'm basically just looking for resources on how to go from LPSTR to short, float, and unsigned char.
Thanks much in advance!
I'm trying to calculate somebody's bowel health based on a points system. I can edit the data structure, or logic in any way. I'm just trying to write a function and data structure to handle this ability.
Pseudo calculator function:
// Bowel health calculator
var points = 0;
If age is from 30 and 34:
points += 1
If age is from 35 and 40:
points += 2
If daily BMs is from 1 and 3:
points -= 1
If daily BMs is from 4 and 6:
points -= 2
return points;
Pseudo data structure:
var points_map = {
age:
{
'30-34': 1,
'35-40': 2
},
dbm:
{
'1-3': -1,
'4-6': -2
}
};
I have a full spreadsheet of data like this, and I am trying to write a DRY version of code and a DRY version of this data (ie, probably not a string for the '30-34', etc) in order to handle this sort of thing without a humongous number of switch statements.
in my cms i have index.php, where client must enter username and password. if they are correct, he'll moove to admin.php, where the cms is.
but now hacker can enter to cms/admin.php, so my security now is awful.
i know, that i can use $_SESSION variable.
index.php - i can give some value to $_SESSION['error']:
$_SESSION['error'] = TRUE, and in admin.php just verify it
admin.php
if($_SESSION['error'] == TRUE)
{
my script here...
}
else header("Location: index.php");
but i want to rich this effect without SESSION.
could you give me an idea, how can i do it?
thanks
I have a custom function in Access2007 that hinges on grabbing data out of a specific query. It opens Outlook, creates a new email and populates the fields with specific addresses and data taken from the query ("DecisionEmail").
Now I want to make a different query ("RequestEmail") and have it populate the email with that data. So all I have to do is change this line:
Set MailList = db.OpenRecordset("DecisionEmail")
and that's where I get stumped.
This is my desired result:
If the user is on Form_Decision and clicks the button "Send email", "DecisionEmail" will get plugged into the function and that data will appear in the email.
If the user on Form_SendRequest and clicks the button "Send email", "RequestEmail" will instead get plugged in.
The reason that these are different queries is because they contain very different information that is smudged about in different ways. However, since it's just one little thing that needs to change in the function code, I don't think a brand new function is a good idea.
My last resort would be to make a brand new function and use the Conditions field in the Macro interface to choose between them, but I have a feeling there's a more elegant solution possible.
I have a vague notion of setting the query names as variables and using an If statement but I just don't have the mental vocabulary for thinking through this.
Why the following code prints "0-100"?
(function () {
for ( var i = 100; i >= 0; i -= 5) {
(function() {
var pos = i;
setTimeout(function() {
console.log(" pos = " + pos);
}, (pos + 1)*10);
})();
}
})();
I declare pos = i , which should be in a descending order. This code originated from John Resig' fadeIn() function in his book Pro javascript techniques.
Is there any way to get the if statement to evaluate a query?
SELECT if(50,'EQ_Type','*') FROM EQUIPMENT;
Resulting in:
+-----------------------+
| IF(50,'EQ_Type','*') |
+-----------------------+
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
| EQ_Type |
+-----------------------+
9 rows in set (0.00 sec)
I would like the above statement to be equivalent to the following:
SELECT 'EQ_Type' FROM EQUIPMENT;
And produce:
+--------------+
| EQ_Type |
+--------------+
| ENGINE |
| ENGINE |
| ENGINE |
| TRAILER |
| TRAILER |
| TRAILER |
| WATER TENDER |
| WATER TENDER |
| WATER TENDER |
+--------------+
Thanks for any help
a = matrix(1:25,5,5)
B = capture.output(for (X in 1:5){
A = c(min(a[,X]),quantile(a[,X],0.25),median(a[,X]),quantile(a[,X],0.75),max(a[,X]),mean(a[,X]),sd(a[,X])/m^(1/2),var(a[,X]))
cat(A,"\n")
})
matrix(B,8,5)
what i was trying to do is to generate a table which each column has those element in A and in that order. i try to use the matrix, but seems like it dont reli work here...can anyone help
1 2 3 4 5
min
1st quartile
median
SEM
VAR
THIS IS WHAT I WANT THE TABLE LOOKS LIKE ..
I've read lot of articles saying, that Java EE is most popular enterprise solution nowadays. Let's not argue if it is most popular or second most popular or what.
The thing is : I see almost all web pages with extension like .html, .php and .aspx.
Why there is (almost) none .JSP ?
Why so ease to find ASP.NET pages if it is supposed to be less popular?
Please I am not programming with Java EE (yet) so don't blame me, if I am completely wrong. The answer with patience would be greatly appreciated!