Search Results

Search found 1486 results on 60 pages for 'counter'.

Page 7/60 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • counter_cache rails a child creation should increment the count intwo different models based on cond

    - by aditi-syal
    Hi, I have 3 models Recommendation Job Qualification Recommendation model has two fields as work_type and work_id(foreign key for job/qualification based on work_type as "J"/"Q") I am facing problem in using counter_cache I have done this in recommendation.rb belongs_to :job , :counter_cache = true, :foreign_key = "work_id" belongs_to :qualification , :counter_cache = true, :foreign_key = "work_id" and in job and qualification model files has_many :recommendations , :conditions = {:work_type = "J"} has_many :recommendations , :conditions = {:work_type = "Q"} Both Job and Qualification Models have a column as recommendations_count The problem is every time an object of recommendation is created count is increased in the both the models Please help me with this Thanks

    Read the article

  • Ruby Performance Profiling

    - by JustSmith
    I'm developing some code that calls another function and then sends out its response. If the said function takes to long i want to record this. Are there any light weight FREE performance profiling tools for Ruby, not on rails, that can do this? I'm even open to any solution that is accurate.

    Read the article

  • Increment global variable on click in flash, actionscript 3

    - by msandbot
    Hi, Making a flash page that can cycle through these three images on mouseclick. For some reason the local changes to count are not reflected on the global one. I tried _global but the syntax was odd and gave me errors. How should I implement this? import flash.events.Event; var images:Array = ["images/image.jpg", "images/image2.jpg", "images/image3.jpg"]; var count:int = 0; forward.addEventListener(MouseEvent.CLICK, loadPhoto); function loadPhoto(evt:Event){ if(count>2){ count==0; } trace(count); imageFrame.source = images[count]; count++; }

    Read the article

  • Update count every second causing massive memory problems

    - by Josh
    Just on my local machine, trying the run the following script causes my computer to crash... What am I doing wrong? (function($) { var count = '6824756980'; while (count > 0) { setInterval(function() { $('#showcount').html(Math.floor(count-1)); count--; }, 1000 ); } })(jQuery); All I need to do is subtract one from the var "count" and update/display it's value every second.

    Read the article

  • How to increment counters based on a printed array

    - by Sam Liew
    I managed to developed a simple board of 5x5 using random numbers and array. Big achievement for someone like me! :) Now I have to increment the counters depending on the frequency of the numbers. If the value within 0-49 is printed..then nCounter++ If the value within 50-75 is printed..then pCounter++ something like that. The problem is that I don't know how to increase the counters based on the printed board. Here is the code: #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { //Initialize Variables int randomNumber; int rows; int columns; int hdCounter =0; int hCounter = 0; int cCounter = 0; int pCounter = 0; int nCounter = 0; //Declare board size int board[5][5]; //size of board is 5 x 5 //Create the random number generator seed srand(time(NULL)); //Assign the random numbers from 1 - 25 into variable randomNumber //Create the rows for the board for ( rows = 1; rows <= 5 ; rows++ ) { //Create the colimns for the board for ( columns = 1; columns <= 5 ; columns++ ) { //Assign variable randomNumber into variable board randomNumber = rand() %100 + 1; board[rows][columns] = randomNumber; //print the board printf("%d\t", board[rows][columns]); //calculate the frequency of numbers on the printed board if (randomNumber >= 85 && randomNumber <= 100 ) hdCounter++; else if ( randomNumber >= 75 ) hCounter++; else if ( randomNumber >= 65 ) cCounter++; else if ( randomNumber >= 50 ) pCounter++; else if ( randomNumber >= 1 ) nCounter++; else continue; } //Newline after the end of 5th column. printf("\n\n"); } printf( "N \t P \t C \t H \t HD\n\n" ); printf("%d \t %d \t %d \t %d \t %d \t", nCounter, pCounter, cCounter, hCounter, hdCounter); }//end main I tried replacing randomNumber in the if-statement with board[rows][columns] but I seem to get the same undesired results.

    Read the article

  • How to get the number of loop when using an iterator, in C++?

    - by pollux
    Dear reader, I'm working on a aplication where I draw a couple of images, like this: void TimeSlice::draw(float fX, float fY) { list<TimeSliceLevel*>::iterator it = levels.begin(); float level_x = x; float level_y = y; while(it != levels.end()) { (*it)->draw(level_x,level_y); level_y += (*it)->height; ++it; } } Though this is a bit incorrect. I need to position the TimeSliceLevel* on a X.. When I've got a for(int i = 0; i < slices.size(); ++i) loop, I can use x = i * width. Though I'm using an iterator as I've been told many times that's good programming : and I'm wondering if the iterator has a "index" number of something which I can use to calculate the new X position? (So it's more a question about using iterators) Kind regards, Pollux

    Read the article

  • Updating counters through Hibernate

    - by at
    This is an extremely common situation, so I'm expecting a good solution. Basically we need to update counters in our tables. As an example a web page visit: Web_Page -------- Id Url Visit_Count So in hibernate, we might have this code: webPage.setVisitCount(webPage.getVisitCount()+1); The problem there is reads in mysql by default don't pay attention to transactions. So a highly trafficked webpage will have inaccurate counts. The way I'm used to doing this type of thing is simply call: update Web_Page set Visit_Count=Visit_Count+1 where Id=12345; I guess my question is, how do I do that in Hibernate? And secondly, how can I do an update like this in Hibernate which is a bit more complex? update Web_Page wp set wp.Visit_Count=(select stats.Visits from Statistics stats where stats.Web_Page_Id=wp.Id) + 1 where Id=12345;

    Read the article

  • c# counting identical strings from text file

    - by Winkz
    I have a foreach statement where I go through several lines from a text file, where I have trimmed down and sorted out the lines I need. What I want to do is count up on how many times an identical string is present. How do I do this? Here is my code. It's the second if statement where I am stuck: foreach (string line in lines.Where(l => l.Length >= 5)) { string a = line.Remove(0, 11); if ((a.Contains(mobName) && a.Contains("dies"))) { mobDeathCount++; } if (a.Contains(mobName) && a.Contains("drops")) { string lastpart = a.Substring(a.LastIndexOf("drops")); string modifiedLastpart = lastpart.Remove(0, 6); } Heres what some of the lines look like: a bag of coins a siog brandy a bag of coins a bag of coins the Cath Shield a tattered scroll So what im trying to do is counting up there are 3 lines with bag of coins. But i need to make it so that it can be everything, theres a drop lists thats huge. So cant add all of em, would take too long

    Read the article

  • How do I programatically determine which port a SQL Server is running on?

    - by Ralph Willgoss
    How do I programatically determine which port a SQL Server is running on?/*Wrapper script for xp_readerrorlogAuthor: Ralph WillgossDate: 2nd Oct 2012This script cycles through all logs files, looking for the listening port.Normally you have to specify the log file one by one, the script removes the need for that.Param ref for: xp_readerrorlog1. Value of error log file you want to read: 0 = current, 1 = Archive #1, 2 = Archive #2, etc...2. Log file type: 1 or NULL = error log, 2 = SQL Agent log3. Search string 1: String one you want to search for4. Search string 2: String two you want to search for to further refine the results5. Search from start time6. Search to end time7. Sort order for results: N'asc' = ascending, N'desc' = descending*/USE MasterGO--  Get log countDECLARE @logcount intDROP TABLE #ResultCREATE TABLE #Result (ArchiveNo int, Date datetime, Size int)INSERT INTO #ResultEXEC xp_enumerrorlogsSET @logcount = (SELECT COUNT(*) FROM #Result)-- Search the available logsDECLARE @counter intSET @counter = 0WHILE @counter <= @logcountBEGIN   EXEC xp_readerrorlog @counter, 1, N'Server is listening on', 'any', NULL, NULL, N'asc'   SET @counter = @counter + 1ENDGO

    Read the article

  • How do I programatically determine which port a SQL Server is running on?

    - by Ralph Willgoss
    How do I programatically determine which port a SQL Server is running on?/*===== Param ref for xp_readerrorlog ===1. Value of error log file you want to read: 0 = current, 1 = Archive #1, 2 = Archive #2, etc...2. Log file type: 1 or NULL = error log, 2 = SQL Agent log3. Search string 1: String one you want to search for4. Search string 2: String two you want to search for to further refine the results5. Search from start time6. Search to end time7. Sort order for results: N'asc' = ascending, N'desc' = descendingHow many error logs do I have?SMSStudio -> Management -> SQL Server Logs -> (right click) -> configure = see values*/USE MasterGO--  get log countDECLARE @logcount intDROP TABLE #ResultCREATE TABLE #Result (ArchiveNo int, Date datetime, Size int)INSERT INTO #ResultEXEC xp_enumerrorlogsSET @logcount = (SELECT COUNT(*) FROM #Result)-- search logsDECLARE @counter intSET @counter = 0WHILE @counter <= @logcountBEGIN    EXEC xp_readerrorlog @counter, 1, N'Server is listening on', 'any', NULL, NULL, N'asc'    SET @counter = @counter + 1ENDGO

    Read the article

  • Why does jquery leak memory so badly?

    - by Thomas Lane
    This is kind of a follow-up to a question I posted last week: http://stackoverflow.com/questions/2429056/simple-jquery-ajax-call-leaks-memory-in-ie I love the jquery syntax and all of its nice features, but I've been having trouble with a page that automatically updates table cells via ajax calls leaking memory. So I created two simple test pages for experimenting. Both pages do an ajax call every .1 seconds. After each successful ajax call, a counter is incremented and the DOM is updated. The script stops after 1000 cycles. One uses jquery for both the ajax call and to update the DOM. The other uses the Yahoo API for the ajax and does a document.getElementById(...).innerHTML to update the DOM. The jquery version leaks memory badly. Running in drip (on XP Home with IE7), it starts at 9MB and finishes at about 48MB, with memory growing linearly the whole time. If I comment out the line that updates the DOM, it still finishes at 32MB, suggesting that even simple DOM updates leak a significant amount of memory. The non-jquery version starts and finishes at about 9MB, regardless of whether it updates the DOM. Does anyone have a good explanation of what is causing jquery to leak so badly? Am I missing something obvious? Is there a circular reference that I'm not aware of? Or does jquery just have some serious memory issues? Here is the source for the leaky (jquery) version: <html> <head> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('jquery', '1.4.2'); </script> <script type="text/javascript"> var counter = 0; leakTest(); function leakTest() { $.ajax({ url: '/html/delme.x', type: 'GET', success: incrementCounter }); } function incrementCounter(data) { if (counter<1000) { counter++; $('#counter').text(counter); setTimeout(leakTest,100); } else $('#counter').text('finished.'); } </script> </head> <body> <div>Why is memory usage going up?</div> <div id="counter"></div> </body> </html> And here is the non-leaky version: <html> <head> <script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/yahoo/yahoo-min.js"></script> <script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/event/event-min.js"></script> <script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/connection/connection_core-min.js"></script> <script type="text/javascript"> var counter = 0; leakTest(); function leakTest() { YAHOO.util.Connect.asyncRequest('GET', '/html/delme.x', {success:incrementCounter}); } function incrementCounter(o) { if (counter<1000) { counter++; document.getElementById('counter').innerHTML = counter; setTimeout(leakTest,100); } else document.getElementById('counter').innerHTML = 'finished.' } </script> </head> <body> <div>Memory usage is stable, right?</div> <div id="counter"></div> </body> </html>

    Read the article

  • Why can't perfmon see instances of my custom performance counter?

    - by spoulson
    I'm creating some custom performance counters for an application. I wrote a simple C# tool to create the categories and counters. For example, the code snippet below is basically what I'm running. Then, I run a separate app that endlessly refreshes the raw value of the counter. While that runs, the counter and dummy instance are seen locally in perfmon. The problem I'm having is that the monitoring system we use can't see the instances in the multi-instance counter I've created when viewing remotely from another server. When using perfmon to browse the counters, I can see the category and counters, but the instances box is grayed out and I can't even select "All instances", nor can I click "Add". Using other access methods, like [typeperf][1] exhibit similar issues. I'm not sure if this is a server or code issue. This is only reproducible in the production environment where I need it. On my desktop and development servers, it works great. I'm a local admin on all servers. CounterCreationDataCollection collection = new CounterCreationDataCollection(); var category_name = "My Application"; var counter_name = "My counter name"; CounterCreationData ccd = new CounterCreationData(); ccd.CounterType = PerformanceCounterType.RateOfCountsPerSecond64; ccd.CounterName = counter_name; ccd.CounterHelp = counter_name; collection.Add(ccd); PerformanceCounterCategory.Create(category_name, category_name, PerformanceCounterCategoryType.MultiInstance, collection); Then, in a separate app, I run this to generate dummy instance data: var pc = new PerformanceCounter(category_name, counter_name, instance_name, false); while (true) { pc.RawValue = 0; Thread.Sleep(1000); }

    Read the article

  • SQL Server "Long running transaction" performance counter: why no workee?

    - by Sleepless
    Please explain to me the following observation: I have the following piece of T-SQL code that I run from SSMS: BEGIN TRAN SELECT COUNT (*) FROM m WHERE m.[x] = 123456 or m.[y] IN (SELECT f.x FROM f) SELECT COUNT (*) FROM m WHERE m.[x] = 123456 or m.[y] IN (SELECT f.x FROM f) COMMIT TRAN The query takes about twenty seconds to run. I have no other user queries running on the server. Under these circumstances, I would expect the performance counter "MSSQL$SQLInstanceName:Transactions\Longest Transaction Running Time" to rise constantly up to a value of 20 and then drop rapidly. Instead, it rises to around 12 within two seconds and then oscillates between 12 and 14 for the duration of the query after which it drops again. According to the MS docs, the counter measures "The length of time (in seconds) since the start of the transaction that has been active longer than any other current transaction." But apparently, it doesn't. What gives?

    Read the article

  • What's a good way to detect wrap-around in a fixed-width message counter?

    - by Kristo
    I'm writing a client application to communicate with a server program via UDP. The client periodically makes requests for data and needs to use the most recent server response. The request message has a 16-bit unsigned counter field that is echoed by the server so I can pair requests with server responses. Since it's UDP, I have to handle the case where server responses arrive out of order (or don't arrive at all). Naively, that means holding on to the highest message counter seen so far and dropping any incoming message with a lower number. But that will fail as soon as we pass 65535 messages and the counter wraps back to zero. Is there a good way to detect (with reasonable probability) that, for example, message 5 actually comes after message 65,000? The implementation language is C++.

    Read the article

  • Objective-C error... Cannot convert to pointer type (int)

    - by Flash84x
    I am attempting to use the TouchXML library and followed the example with the following code for (CXMLElement node in nodes) { NSMutableDictionary *item = [[NSMutableDictionary alloc] init]; int counter; for (counter = 0; counter < [node childCount]; counter++ ) { [item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]]; } [rst addObject:item]; [item release]; } The compiler however is complaining about counter and throwing the following error for counter = 0 and both occurances in the setObject call. Cannot convert to pointer type Any help with my rusty C/ObjC would be appreciated

    Read the article

  • CGContextFillEllipseInRect: invalid context

    - by hakewake
    Hi all, when I launch my app, I keep getting this CGContextFillEllipseInRect: invalid context error. My app is simply to make the circle 'pinchable'. The debugger shows me this: [Session started at 2010-05-23 18:21:25 +0800.] 2010-05-23 18:21:27.140 Erase[8045:207] I'm being redrawn. Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] <Error>: CGContextFillEllipseInRect: invalid context 2010-05-23 18:21:27.144 Erase[8045:207] New value of counter is 1 2010-05-23 18:21:27.144 Erase[8045:207] I'm being redrawn. Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] <Error>: CGContextFillEllipseInRect: invalid context 2010-05-23 18:21:27.144 Erase[8045:207] New value of counter is 2 2010-05-23 18:21:27.144 Erase[8045:207] I'm being redrawn. Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] <Error>: CGContextFillEllipseInRect: invalid context 2010-05-23 18:21:27.144 Erase[8045:207] New value of counter is 3 2010-05-23 18:21:27.145 Erase[8045:207] I'm being redrawn. Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] <Error>: CGContextFillEllipseInRect: invalid context 2010-05-23 18:21:27.145 Erase[8045:207] New value of counter is 4 2010-05-23 18:21:27.148 Erase[8045:207] I'm being redrawn. Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] <Error>: CGContextFillEllipseInRect: invalid context 2010-05-23 18:21:27.149 Erase[8045:207] New value of counter is 5 2010-05-23 18:21:27.150 Erase[8045:207] I'm being redrawn. Sun May 23 18:21:27 Sidwyn-Kohs-MacBook-Pro.local Erase[8045] <Error>: CGContextFillEllipseInRect: invalid context 2010-05-23 18:21:27.150 Erase[8045:207] New value of counter is 6 My implementation file is: // // ImageView.m // Erase // #import "ImageView.h" #import "EraseViewController.h" @implementation ImageView -(void)setNewRect:(CGRect)anotherRect{ newRect = anotherRect; } - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { newRect = CGRectMake(0,0,0,0); ref = UIGraphicsGetCurrentContext(); } return self; } - (void)drawRect:(CGRect)rect { static int counter = 0; CGRect veryNewRect = CGRectMake(30.0, 210.0, 60.0, 60.0); NSLog(@"I'm being redrawn."); if (counter == 0){ CGContextFillEllipseInRect(ref, veryNewRect); } else{ CGContextFillEllipseInRect(ref, rect); } counter++; NSLog(@"New value of counter is %d", counter); } - (void)setNeedsDisplay{ [super setNeedsDisplay]; [self drawRect:newRect]; } - (void)dealloc { [super dealloc]; } @end I've got two questions: 1) Why is it updating counter 6 times? I removed the line [super setNeedsDisplay]; but it becomes 4 times. 2) What is that invalid context error? Thanks guys.

    Read the article

  • How can I add a simple counter function in javascript jquery?

    - by Adam
    I'm using Shadowbox a jquery overlay and I wanted to count how many people are actually using the overlay. Thus, I would need a function that would write a counter to a file or sending a query through a php api... has to be a a php url api because I cant use php on the server where the overlay is. So I need help with executing a javascript function on the overlay click, tips on how to make a counter query through GET method. Thanks

    Read the article

  • Translation of a RoR view to Java

    - by mnml
    Hi, for some reasons I am trying to translate the following RoR view code to a GSP view: List<Object> objectscontains the data I want to display in 3 columns <% modulo_objects = @objects.length % 3 base = @objects.length / 3 base = base.ceil case modulo_objects when 0 cols = [base, base, base] when 1 cols = [base, base + 1, base] when 2 cols = [base + 1, base, base + 1] end counter = 0 %> <% 3.times do |i| %> <td width="220" align="center" style="padding-right: 15px;"> <% cols[i].times do %> <h1><a href="/objects/show/<%= @objects[counter].urlname %>" ><%= @objects[counter].name %></a></h1> <% counter = counter + 1 %> <% end %> </td> <% end %> This is what I got so far: #{extends 'main.html' /} %{ modulo_objects = objects.size() % 3 base = objects.size() / 3 base = Math.ceil(base) if(modulo_objects == 0) cols = [base, base, base] else if(modulo_objects == 1) cols = [base, base + 1, base] else if(modulo_objects == 2) cols = [base + 1, base, base + 1] endif counter = 0 }% #{list items:1..3, as:'i'} <td width="220" align="center" style="padding-right: 15px;"> #{list items:cols[i]} <a href="@{Objects.show(objects.get(counter).name.replaceAll(" ", "-"))}" >${objects.get(counter).name}</a> %{ counter = counter + 1 }% #{/list} </td> #{/list} The idea is to keep the items organised in 3 columns like 1|0|1 4|5|4 or 5|4|5 for example, I don't really understand if #{list items:cols[i]} will reproduce ruby's cols[i].times do. So far the Java view is does not display more than two elements.

    Read the article

  • How to return a value when destroying/cleaning-up an object instance

    - by Mridang Agarwalla
    When I initiate a class in Python, I give it some values. I then call method in the class which does something. Here's a snippet: class TestClass(): def __init__(self): self.counter = 0 def doSomething(self): self.counter = self.counter + 1 print 'Hiya' if __name__ == "__main__": obj = TestClass() obj.doSomething() obj.doSomething() obj.doSomething() print obj.counter As you can see, everytime I call the doSomething method, it prints some text and increments an internal variable i.e. counter. When I initiate the class, i set the counter variable to 0. When I destroy the object, I'd like to return the internal counter variable. What would be a good way of doing this? I wanted to know if there were other ways apart from doing stuff like: accessing the variable directly. Like obj.counter. creating a method like getCounter. Thanks.

    Read the article

  • Incrmenting a Cookies with PHP (Beginner Question)

    - by BandonRandon
    Hello, I have used sessions before but never cookies. I would like to use cookies for two reasons: 1) it's something new to learn 2) I would like to have the cookie expire in an hour or so (i know in the code example it expires in 40 sec) I am trying to write a basic if statement that if($counter=="1") { //do this second } elseif ($counter >="2") { //do this every time after the first and second } else {// this is the first action as counter is zero } Here is the code I'm using to set the cookie: // if cookie doesnt exsist, set the default if(!isset($_COOKIE["counter_cookie"])) { $counter = setcookie("counter_cookie", 0 ,time()+40); } // increment it $counter++; // save it setcookie("counter_cookie", $counter,time()+40); $counter = $_COOKIE["counter_cookie"]; The problem is that the counter will be set from 0 to 1 but won't be set from 1 to 2 and so on. Any help would be great I know this is a really simple stupid question :| Thanks!

    Read the article

  • Need help with some C# Counting Code

    - by kaywai
    Hi, I'm trying to code a counter in Ninjatrader which uses C# as its programming language. I would like this counter to commence counting upon the completion of the first counter and once it commences counting to consider only the new condition when counting. So, the first counter commences when Close[0] < Close[4]. The second counter commences ONLY after the first counter has reached 9 and its condition for counting is Close[0] <= Low[2]. I don't know how to write the part of the code where the second counter commences counting and its counts are independent of the first counter reaching 9.

    Read the article

  • Returning Value of Radio Button Jquery [migrated]

    - by Jerry Walker
    I am trying to figure out why, when I run this code, I am getting undefined for my correct answers. $(document).ready (function () { // var answers = [["Fee","Fi","Fo"], ["La","Dee","Da"]], questions = ["Fee-ing?", "La-ing?"], corAns = ["Fee", "La"]; var counter = 0; var $facts = $('#main_ .facts_div'), $question = $facts.find('.question'), $ul = $facts.find('ul'), $btn = $('.myBtn'); $btn.on('click', function() { if (counter < questions.length) { $question.text(questions[counter]); var ansstring = $.map(answers[counter], function(value) { return '<li><input type="radio" name="ans" value="0"/>' + value + '</li>'}).join(''); $ul.html(ansstring); var currentAnswers = $('input[name="ans"]:checked').map(function() { return this.val(); }).get(); var correct = 0; if (currentAnswers[counter]==corAns[counter]) { correct++; } } else { $facts.text('You are done with the quiz ' + correct); $(this).hide(); } counter++; }); // }); It is quite long and I'm sorry about that, but I don't really know how tostrip it down. I also realize this isn't the most elegant way to do this, but I just want to know why I can't seem to get my radio values. I will add the markup as well if anyone wants.

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >