Say that I have a table with one column named CustomerId.
The example of the instance of this table is :
CustomerId
14
12
11
204
14
204
I want to write a query that counts the number of occurences of customer IDs.
At the end, I would like to have a result like this :
CustomerId NumberOfOccurences
14 2
12 1
11 1
204 2
14 1
I cannot think of a way to do this.
public class SubstringCount
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a word longer than 4 characters, and press q to quit");
int count = 0;
while (scan.hasNextLine())
{
System.out.println("Enter a word longer than 4 characters, and press q to quit");
String word = scan.next();
if (word.substring(0,4).equals("Stir"))
{
count++;
System.out.println("Enter a word longer than 4 characters, and press q to quit");
scan.next();
}
else if (word.equals("q"))
{
System.out.println("You have " + count + ("words with 'Stir' in them"));
}
else if (!word.substring(0,4).equals("Stir"))
{
System.out.println("Enter a word longer than 4 characters, and press q to quit");
scan.next();
}
}
}
}
Here I need to print how many words entered by the user contain the substring 'Stir.' However I'm not sure how to get this to work, or if I've done any of it right in the first place!
Thanks for any help!
I currently have a table which stores a load of statistics such as views, downloads, purchases etc. for a multiple number of items. To get a single operation count on each item I can use the following query:
SELECT , COUNT()
FROM stats
WHERE operation = 'view'
GROUP BY item_id
This gives me all the items and a count of their views. I can then change 'view' to 'purchase' or 'download' for the other variables. However this means three separate calls to the database.
Is it possible to get all three in one go?
I've just started using XSLT and am trying to figure this out.
Your help would be greatly appreciated.
Example XML file
<purchases>
<item id = "1" customer_id = "5">
</item>
<item id = "2" customer_id = "5">
</item>
<item id = "7" customer_id = "4">
</item>
</purchases>
Desired HTML Output:
<table>
<tr><th>Customer ID</th><th>Number of Items Purchased</th></tr>
<tr><td>5</td><td>2</td></tr>
<tr><td>4</td><td>1</td></tr>
</table>
Customer with id number 5 has bought 2 items.
Customer with id number 4 has bought 1 item.
Is there any efficient way in python to count the times an array of numbers is between certain intervals? the number of intervals i will be using may get quite large
like:
mylist = [4,4,1,18,2,15,6,14,2,16,2,17,12,3,12,4,15,5,17]
some function(mylist, startpoints):
# startpoints = [0,10,20]
count values in range [0,9]
count values in range [10-19]
output = [9,10]
I have been searching around and I cannot figure out how to sumarise the data I have in my data frame (subject to some ranges). I know that it can be done when applying some combination of daaply/taaply or table but I haven't been able to get the exact result I was expecting.
Basically I want to turn this:
part_no val1 val2 val3
2 1 2 3 45.3
2 1 3 4 -12.3
3 1 3 4 99.3
3 1 5 2 -3.2
3 1 4 3 -55.3
Into this:
part_no val3_between0_50 val3_bw50_100 val3_bw-50_0 val3_bw-100_-50
2 1 0 0 1 0
3 0 1 0 1 1
This is dummy data, I got a lot more rows, but the idea is the same. I just want to count the number of values for a participant that meet certain condition.
If anyone could explain it sort of step by step, I would really appreciate it. I saw lots of different little posts around, but none do exactly this and my attempts only got me half way there. Like using table, etc.
Thanks!
I need to create a Set of objects. The concern is I do not want to base the hashing or the equality on the objects' hashCode and equals implementation. Instead, I want the hash code and equality to be based only on each object's reference identity (i.e.: the value of the reference pointer).
I'm not sure how to do this in Java.
The reasoning behind this is my objects do not reliably implement equals or hashCode, and in this case reference identity is good enough.
Given a String array such as this:
string[]={"bmw"," ","1bmw"," "};
I need to count how often the substring bmw occurs in that array. In this example it occurs 2 times.
How do I write that in C#?
<!DOCTYPE HTML>
<html>
<head>
<title> Javascript - stuff </title>
<script type="text/javascript">
<!--
function GetCountsAll( Wordcount, Sentancecount, Clausecount, Charactercount )
{
var TextString = document.getElementById("Text").innerHTML;
var Wordcount = 0;
var Sentancecount = 0;
var Clausecount = 0;
var Charactercount = 0;
// For loop that runs through all characters incrementing the variable(s) value each iteration
for (i=0; i < TextString.length; i++);
if (TextString.charAt(i) == " " = true)
Wordcount++;
return Wordcount;
if (TextString.charAt(i) = "." = true)
Sentancecount++;
Clausecount++;
return Sentancecount;
if (TextString.charAt(i) = ";" = true)
Clausecount++;
return Clausecount;
}
-->
</script>
</head>
<body>
<div id="Text">
It is important to remember that XHTML is a markup language; it is not a programming language. The language only describes the placement and visual appearance of elements arranged on a page; it does not permit users to manipulate these elements to change their placement or appearance, or to perform any "processing" on the text or graphics to change their content in response to user needs. For many Web pages this lack of processing capability is not a great drawback; the pages are simply displays of static, unchanging, information for which no manipulation by the user is required. Still, there are cases where the ability to respond to user actions and the availability of processing methods can be a great asset. This is where JavaScript enters the picture.
</div>
<input type = "button" value = "Get Counts" class = "btnstyle" onclick = "GetCountsAll()"/>
<br/>
<span id= "Charactercount"> </span> Characters <br/>
<span id= "Wordcount"> </span> Words <br/>
<span id= "Sentancecount"> </span> Sentences <br/>
<span id= "ClauseCount"> </span> Clauses <br/>
</body>
</html>
I am a student and still learning JavaScript, so excuse any horrible mistakes. The script is meant to calculate the number of characters, words, sentences, and clauses in the passage. It's, plainly put, just not working. I have tried a multitude of things to get it to work for me and have gotten a plethora of different errors but no matter what I can NOT get this to work. Please help! (btw i know i misspelled sentence)
I have a text file of size 115MB. It consists of about 20 million words. I have to use the file as a word collection, and use it to search the occurrence of each user-given words from the collection. I am using this process as a small part in my project. I need a method for finding out the number of occurrence of given words in a faster and correct manner since i may use it in iterations. I am in need of suggestion about any API that i can make use or some other way that performs the task in a quicker manner. Any recommendations are appreciated.
Die Oracle Application Integration Architecture lässt sich gut nutzen, um eine SOA Initiative zügig zu starten. Naturgemäß berücksichtigt sie aber nicht alle Aspekte einer IT Strategie. Zu diesem Thema gibt es nun seit einigen Wochen eine umfassende Bibliothek von Handbüchern ("Practitioner's Guides") und Referenz-Architekturen, in denen die Erfahrung aus zahlreichen Projekten zusammengefasst ist.Hier ist beispielsweise ein IT Governance Framework beschrieben, das auch die wesentlichen Aspekte der SOA GovernanceSOA Portfolio GovernanceService Lifecycle GovernanceSOA Solution Lifecycle GovernanceSOA Vitality GovernanceSOA Organization Governancenäher beschreibt.In den Handbüchern sind zahlreiche wertvolle Hinweise und best practices enthalten; ich denke, es lohnt sich, einen Blick hinein zu werfen.Die gesamte Bibliothek findet sich unter http://www.oracle.com/goto/itstrategies; eine Übersicht über die verschiedenen Aspekte ist in dem Bild unten zusammengefasst.View image
I am working on MVC3 application. I use entity framework, NInject, Fluent Validation and some more Nuget packages. I am using Tortoise SVN for versioning.
Recently I changed the structure of my SVN repository, so my working copy of MVC3 app was moved to some different folder in the repository.
Now when I checked out the copy from SVN, all the references that I had added through Nuget were lost(EF, NInject and rest nuget packages were showing yellow missing icon in references). This had happened to me prior to this also, when I tried to check out the app from svn to some other folder. I had to manually add all the references again through Nuget again. Am I doing anything wrong?
Please guide. I hope I could explain my problem properly.
Do any programmers out there keep a personal wiki? Either locally or online.
What do you use your wiki for? or what might you use one for?
I was thinking of starting a personal wiki as a place to record documentation and and other documents for my personal projects, and various notes etc, but how else is a personal (maybe private) Wiki useful to a programmer/developer? What type of things would you put in a personal Wiki?
When reading Scrum Guide, as the official text for scrum, I find out there is no specific solution to provide software testing in scrum. (the only hint is on page15)
I'm a little vague on whether scrum is considered a software development methodology or not?
If it is not, then how come some of its practices opposes Extreme Programming?
(I know that in scrum guide, the author notes that scrum is a framework not a methodology, but still I'm not pretty clear on that)
And what's more, I'm not sure if there are any other important textbook that I'm missing so far about scrum. I need them to be official or of great deal of public acceptance.
PHP 5.5
I'm doing a bunch of passing around of objects with the assumption that they will all maintain their identities - that any changes made to their states from inside other objects' methods will continue to hold true afterwards. Am I assuming correctly?
I will give my basic structure here.
class builder {
protected $foo_ids = array(); // set in construct
protected $foo_collection;
protected $bar_ids = array(); // set in construct
protected $bar_collection;
protected function initFoos() {
$this->foo_collection = new FooCollection();
foreach($this->food_ids as $id) {
$this->foo_collection->addFoo(new foo($id));
}
}
protected function initBars() {
// same idea as initFoos
}
protected function wireFoosAndBars(fooCollection $foos, barCollection $bars) {
// arguments are passed in using $this->foo_collection and $this->bar_collection
foreach($foos as $foo_obj) { // (foo_collection implements IteratorAggregate)
$bar_ids = $foo_obj->getAssociatedBarIds();
if(!empty($bar_ids) ) {
$bar_collection = new barCollection(); // sub-collection to be a component of each foo
foreach($bar_ids as $bar_id) {
$bar_collection->addBar(new bar($bar_id));
}
$foo_obj->addBarCollection($bar_collection);
// now each foo_obj has a collection of bar objects, each of which is also in the main collection. Are they the same objects?
}
}
}
}
What has me worried is that foreach supposedly works on a copy of its arrays. I want all the $foo and $bar objects to maintain their identities no matter which $collection object they become of a part of. Does that make sense?
To make it more clear, this is a quick example:
class A implements Serializable { public B b; }
class B implements Serializable { public A a; }
A a = new A();
B b = new B();
a.b = b;
b.a = a;
So what happens if we serialize a and b objects into a file and deserialize from that file?
I thought we get 4 objects, 2 of each. Identical objects but different instances.
But I'm not sure if there's anything else or is it right or wrong.
If any technology needed to answer, please think based on Java.
Thank you.
EDIT:
This question is about finding definitive reference to MySQL syntax on SELECT modifying keywords and functions.
/EDIT
AFAIK SQL defines two uses of DISTINCT keywords - SELECT DISTINCT field... and SELECT COUNT(DISTINCT field) ...
However in one of web applications that I administer I've noticed performance issues on queries like
SELECT DISTINCT(field1), field2, field3 ...
DISTINCT() on a single column makes no sense and I am almost sure it is interpreted as
SELECT DISTINCT field1, field2, field3 ...
but how can I prove this?
I've searched mysql site for a reference on this particular syntax, but could not find any. Does anyone have a link to definition of DISTINCT() in mysql or knows about other authoritative source on this?
Best
EDIT
After asking the same question on mysql forums I learned that while parsing the SQL mysql does not care about whitespace between functions and column names (but I am still missing a reference).
As it seems you can have whitespace between functions and the parenthesis
SELECT LEFT (field1,1), field2...
and get mysql to understand it as SELECT LEFT(field,1)
Similarly SELECT DISTINCT(field1), field2... seems to get decomposed to
SELECT DISTINCT (field1), field2... and then DISTINCT is taken not as some undefined (or undocumented) function, but as SELECT modifying keyword and the parenthesis around field1 are evaluated as if they were part of field expression.
It would be great if someone would have a pointer to documentation where it is stated that the whitespace between functions and parenthesis is not significant or to provide links to apropriate MySQL forums, mailing lists where I could raise a question to put this into reference.
EDIT
I have found a reference to server option IGNORE SPACE.
It states that "The IGNORE SPACE SQL mode can be used to modify how the parser treats function names that are whitespace-sensitive", later on it states that recent versions of mysql have reduced this number from 200 to 30.
One of the remaining 30 is COUNT for example.
With IGNORE SPACE enabled both
SELECT COUNT(*) FROM mytable;
SELECT COUNT (*) FROM mytable;
are legal.
So if this is an exception, I am left to conclude that normally functions ignore space by default.
If functions ignore space by default then if the context is ambiguous, such as for the first function on a first item of the select expression, then they are not distinguishable from keywords and the error can not be thrown and MySQL must accept them as keywords.
Still, my conclusions feel like they have lot of assumptions, I would still be grateful and accept any pointers to see where to follow up on this.
https://tbe.taleo.net/MANAGER/dispatcher/servlet/rpcrouter
the above is from Taleo's API guide.
I'm trying to create a WCF Client
(e.g.: " Creating Your First WCF Client"
http://channel9.msdn.com/shows/Endpoint/Endpoint-Screencasts-Creating-Your-First-WCF-Client/ )
The tbe.taleo... link is from Taleo's API documentation.
Likely my understanding is flawed. My assumption is that when the
link from Taleo is entered into the vs2010 "Add Service Reference"
dialog and GO is clicked, then vs2010 should retrieve
a proper WSDL/SOAP envelope back from the Taleo link.
That does not happen; instead an error occurs.
Fiddler2 (http://fiddler2.com) displays the status code 500
"HTTP/1.1 500 Internal Server Error". [FULL DETAILS BELOW]
"WcfTestClient.exe" gives a similar error: [WcfTestClient DETAILS BELOW]
QUESTION: is it me, or is the Taleo link flawed?
Thank you,
Gerry
[FULL DETAILS "Add Service Reference"]
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: 'https://tbe.taleo.net/MANAGER/dispatcher/servlet/rpcrouter'.
The content type text/xml;charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 544 bytes of the response were: '
SOAP-ENV:Protocol
Unsupported content type "application/soap+xml; charset=utf-8", must be: "text/xml".
/MANAGER/dispatcher/servlet/rpcrouter
'.
The remote server returned an error: (500) Internal Server Error.
If the service is defined in the current solution, try building the solution and adding the service reference again.
[WcfTestClient DETAILS]
Error: Cannot obtain Metadata from https://tbe.taleo.net/MANAGER/dispatcher/servlet/rpcrouter If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: https://tbe.taleo.net/MANAGER/dispatcher/servlet/rpcrouter Metadata contains a reference that cannot be resolved: 'https://tbe.taleo.net/MANAGER/dispatcher/servlet/rpcrouter'. The content type text/xml;charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 544 bytes of the response were: 'SOAP-ENV:ProtocolUnsupported content type "application/soap+xml; charset=utf-8", must be: "text/xml"./MANAGER/dispatcher/servlet/rpcrouter'. The remote server returned an error: (500) Internal Server Error.HTTP GET Error URI: https://tbe.taleo.net/MANAGER/dispatcher/servlet/rpcrouter The HTML document does not contain Web service discovery information.
One of the touted advantages of jQuery.data versus raw expando properties (arbitrary attributes you can assign to DOM nodes) is that jQuery.data is "safe from circular references and therefore free from memory leaks". An article from Google titled "Optimizing JavaScript code" goes into more detail:
The most common memory leaks for web applications involve circular
references between the JavaScript script engine and the browsers' C++
objects' implementing the DOM (e.g. between the JavaScript script
engine and Internet Explorer's COM infrastructure, or between the
JavaScript engine and Firefox XPCOM infrastructure).
It lists two examples of circular reference patterns:
DOM element → event handler → closure scope → DOM
DOM element → via expando → intermediary object → DOM element
However, if a reference cycle between a DOM node and a JavaScript object produces a memory leak, doesn't this mean that any non-trivial event handler (e.g. onclick) will produce such a leak? I don't see how it's even possible for an event handler to avoid a reference cycle, because the way I see it:
The DOM element references the event handler.
The event handler references the DOM (either directly or indirectly). In any case, it's almost impossible to avoid referencing window in any interesting event handler, short of writing a setInterval loop that reads actions from a global queue.
Can someone provide a precise explanation of the JavaScript ↔ DOM circular reference problem? Things I'd like clarified:
What browsers are effected? A comment in the jQuery source specifically mentions IE6-7, but the Google article suggests Firefox is also affected.
Are expando properties and event handlers somehow different concerning memory leaks? Or are both of these code snippets susceptible to the same kind of memory leak?
// Create an expando that references to its own element.
var elem = document.getElementById('foo');
elem.myself = elem;
// Create an event handler that references its own element.
var elem = document.getElementById('foo');
elem.onclick = function() {
elem.style.display = 'none';
};
If a page leaks memory due to a circular reference, does the leak persist until the entire browser application is closed, or is the memory freed when the window/tab is closed?
Anyone knows where one could find a Latex reference sheet for usage in Word 2007? I'm interested in some which mostly deals with writing math. Formulas, text formatting and page layout are of lesser importance.
I have to do a student research project about "Server Placement in a Server Room". The paper should contain something like "place the racks about 3 meters away from any wall", "mind the maximum capacity load of the (false) floor" and other placement strategies.
I have been searching for a while, but I did not find any reliable reference I can use in my work.
Does anyone know some useful websites about server placement?
I have two Excel files, one on D:\ and the other one on E:\.
I reference one from the other, for example, using vlookup in the E: file to search from the D: file, like that:
VLOOKUP(A1,'D:\SHARIQ\[FILE NAME.XLS]SHEETNAME'!A1:10,3,FALSE)
As long as D:\SHARIQ\FILE NAME.XLS is open, I get the formula in the E: file displayed like this:
VLOOKUP(A1,'[FILE NAME.XLS]SHEETNAME'!A1:10,3,FALSE)
Why does it remove the whole path?
I am currently working on an application that allows reverse geocoding using silverlight + bing maps. The thing is that I want to add a reference to the reverse geocoding service provided in msdn ( http://msdn.microsoft.com/en-us/library/cc879136.aspx) i.e. http:// dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl, but when I try to get a reference in vs2010, I get the following error:
The document at the url http:// dev.virtualearth.net/webservices/v1/metadata/geocodeservice/geocodeservice.wsdl was not recognized as a known document type.
The error message from each known type may help you fix the problem:
Report from 'XML Schema' is ''', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.'.
Report from 'DISCO Document' is ''', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.'.
Report from 'WSDL Document' is 'There is an error in XML document (1, 1).'.
'', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.
Metadata contains a reference that cannot be resolved: 'http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http: //dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl. The client and service bindings may be mismatched.
The remote server returned an error: (415) Unsupported Media Type.
If the service is defined in the current solution, try building the solution and adding the service reference again.
It is good to mention that I can access the service URL from the browser (with a no style information warning). I am aware that there are other reverse geolocoding services out there, but I am somewhat forced by certain circumstances to use only Microsoft-related components/services. Please help :)
I am new to OpenCV2 and working on a project in emotion recognition and would like to align a facial image in relation to a reference facial image. I would like to get the image translation working before moving to rotation. Current idea is to run a search within a limited range on both x and y coordinates and use the sum of squared differences as error metric to select the optimal x/y parameters to align the image. I'm using the OpenCV face_cascade function to detect the face images, all images are resized to a fixed (128x128). Question: Which parameters of the Mat image do I need to modify to shift the image in a positive/negative direction on both x and y axis? I believe setImageROI is no longer supported by Mat datatypes? I have the ROIs for both faces available however I am unsure how to use them.
void alignImage(vector<Rect> faceROIstore, vector<Mat> faceIMGstore)
{
Mat refimg = faceIMGstore[1]; //reference image
Mat dispimg = faceIMGstore[52]; // "displaced" version of reference image
//Rect refROI = faceROIstore[1]; //Bounding box for face in reference image
//Rect dispROI = faceROIstore[52]; //Bounding box for face in displaced image
Mat aligned;
matchTemplate(dispimg, refimg, aligned, CV_TM_SQDIFF_NORMED);
imshow("Aligned image", aligned);
}
The idea for this approach is based on Image Alignment Tutorial by Richard Szeliski Working on Windows with OpenCV 2.4. Any suggestions are much appreciated.