w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
keeping track of dynamic memory
The statement *temp++ = n; is the root of your problem. You actually incrementing the pointer. So you can't use loop over temp after that. It's not pointing at the beginning of your memory. That's why you're seeing random numbers. I would do: temp[actual_size - 1] = n; //Storing in temp array... I should add that your re-allocation code is much more complicated that it needs. You just need a new array, memcpy the old value, set temp to the new array and deallocate the old one int *oldArray = temp; temp = new int[initial_size]; memcpy(temp, oldArray, old_initial_size * sizeof(int)); delete [] oldArray; temp[old_initial_size] = n;

Categories : C++

WPF keeping track of an elements position
Most probably you don't need any of the things you're doing. See my examples for the right way to do this in WPF (MVVM) 1 / 2 / 3 / 4

Categories : Wpf

keeping track of an image javascript
Your problem is that number doesn't accurately reflect what image is actually being shown. You should do this instead: number = 1; function move() { number++; if(number > 6) number = 1; brillo.src="images/tudelude_0"+number+".jpg"; } function Open(){ var newWindow = window.open("", "pictureViewer", "fullscreen=no"); newWindow.document.writeln("<img src='images/tude_0"+number+".jpg'/>"); newWindow.document.close(); } and in your onload, use setInterval(move, 1000).

Categories : Javascript

php keeping track of random condition
Define an array of the conditions, and store them in the session, e.g. $conditions = array(1,2,3,4); $_SESSION['conditions'] = $conditions; Randomization is easy: array_shuffle($_SESSION['conditions']); Then on each of the individual pages, you just pop off one of those values from the session: <?php # page 1 session_start(); $random_condition = array_pop($_SESSION['conditions']); and do so for all the other pages: <?php #page n session_start(); $random_condition = array_pop($_SESSION['conditions']);

Categories : PHP

Keeping track of pairs of Strings
If one of the two strings in each pair is unique, as your suggestion to use an AbstractMap seems to suggest, you may want to expose an API that returns Map<String,String>, and use an implementation of your choice for that interface (say, LinkedHashMap<String,String>). The users of your class would be able to pull the pairs of Strings from the Map by using Map.Entry<String,String>, rather than calling a get for each key: Map<String,String> getAllPairs() { ... } ... for (Map.Entry<String,String> pair : myClass.getAllPairs()) { // You can use pair.getKey() and pair.getValue() here }

Categories : Java

Python 2.7 Keeping track of what's been printed
You can assign a different file-like object to sys.stdout; anything that is printed is written to that object. You can use a StringIO.StringIO() object to replace stdout: import sys from StringIO import StringIO sys.stdout = StringIO() and inspect what was printed by calling sys.stdout.getvalue(). Demo: >>> import sys >>> from StringIO import StringIO >>> sys.stdout = StringIO() >>> print 'Hello world!' >>> output = sys.stdout.getvalue() >>> sys.stdout = sys.__stdout__ >>> output 'Hello world! ' Note that I restored sys.stdout from sys.__stdout__. You may want to store the old value of sys.stdout instead and restore to that to support scenarios where your platform already replaced sys.stdout before.

Categories : Python

Keeping track of top 'N' queries in Solr
This is not functionality supplied directly within Solr. However a few ways are outlined in this previous post from the Solr Mailing List: Any way to get top 'n' queries searched from Solr?

Categories : Solr

Android Service, Keeping Track of Objects
I assume that your workout objects are in an adapter. In this case you can use the workout object's index as the unique identifier. Instead of the object itself, pass the object's index when you create the intent to send to the service. When the service publishes results, get the correct workout object from the adapter by the index that you passed when calling the service.

Categories : Android

Java Graphics - Keeping track of shapes
Use java.awt.geom.* to create shapes, use fields to reference them and then use the graphics object to draw them. for eg: Ellipse2D.Float ellipse=new Ellipse2D.Float(50,50,100,100); graphics.draw(ellipse);

Categories : Java

Keeping track of the ID of a selected div element in HTML?
What you describe is called overflow. The user clicks faster than you can communicate deletions to the server, "more than one element" doesn't fit in a container that can only hold one element, and consequently the behaviour becomes undefined (and undesirable). The solution: don't use a single variable to track deletions, use a list. user hits delete -> push this element to the deletion queue, disable element on the page so it can't be clicked anymore (looks grayed out, etc). ajax call to delete to the server -> pop element from the deletion queue and add it to a pending qeueu sever says "I deleted it" -> pop the element from the pending queue and remove it from the page. So your idea was good, and the only problem was that you accidentally used a single var when you actually needed a

Categories : Javascript

Keeping track of number of button clicks
Use ViewState to store the number. Or better yet - Session. The advantage of Session is that it is stored on the Server (AFAIK) so it can't be tampered with, and also that it will persist even when reloading the page.

Categories : C#

Generating random values and keeping track of their sum
Original question yesterday had exactly 200 entries and the sum "not greater than 100". My original answer from yesterday: Use random numbers not greater than 0.5 to be sure. Alternatively, depending on how "random" those numbers need to be (how much correlation is allowed), you could keep a running total, and if it gets disproportionately high, you can mix in a bunch of smaller values. Edit: Way to go changing the question, making me look stupid and get downvoted. To get the exact sum you have to normalize, and better use exact fractions instead of floats to avoid rounding errors.

Categories : PHP

Keeping track of users and photos they've viewed
Your best bet is to create a collection with { _id:Generated automagically, pictureID, viewerID } with find( pictureID, viewerID ).limit(1) and an index on pictureID AND viewerID will make checking super ultra fast level 99. very important to set the index. I use find().limit(1) because its faster than findOne, at least from the current benchmarks. why not have one entry per user with an array of viewed images? because searching through the array is slower than searching for a whole document in a collection. 10 million images? no problem. this is where mongodb shines. its designed to scale for big-ass databases like yours. As long as your documents are less than 16 mb, and with 3 properties, it is :) you have little to worry about. When you delete an image, just db.viewed.remove( { pict

Categories : PHP

iOS-Managing and Keeping Track of Multiple Concurrent tasks
GCD groups could easily be used for this. Groups allow you to track arbitrary "members" of the group, and hook a block up to run when all members of the group have finished. It's quite handy. For example (using your code): dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ dispatch_group_t group = dispatch_group_create(); dispatch_group_enter(group); // + 1 [self.webLoader getFeedWithCompletion: ^{ self.thatOtherCompletionBlock(); dispatch_group_leave(group); // - 1 }]; dispatch_group_enter(group); // + 1 [self.otherDataLoader getDataWithCompletion:^{ self.completionBlock(); dispatch_group_leave(group); // - 1 }]; dispatch_group_enter(group); // + 1 [self.thatDataLoader getThatDataW

Categories : IOS

keeping track of online user using phone number
I had a similar issue while developing an app. What you can do here is, to check the input for special characters, and also take the size in account. Remove the spaces, and store just the last 10 digits. This can be achieved by trimming and subString operations, if the entry type is a string. Then comparison of the two strings should result in a desired manner.

Categories : Android

Keeping track of text position on pdf using FPDF and GetY
No idea why this works - but it does: If you just grab Y after the call, it seems to be the value before the MultiCell. Grabbing it before and after and taking the difference gives you the height. $oldY = $this->getY(); $this->MultiCell(150, 4, utf8_decode($description), 0, "L"); $newY = $this->getY(); $multiCellHeight = $newY-$oldY;

Categories : Misc

COUNT(*) or separate table for keeping track of total?
Creating a separate table is denormalised design, but it might be justified if not doing it would significantly impact performance. If you do choose to do this, then it becomes your job to keep the table of metadata updated properly, which is an additional burden and set of things that can go wrong. For MySQL it matters what storage engine you are using. InnoDB performs poorly with COUNT(*) queries IIRC. For MyISAM it does not matter so much.

Categories : Mysql

uploading image files and keeping track with mysql table
As per the docs : If a second transaction wants to update a row or lock a table already locked by a prior transaction in an incompatible mode, InnoDB adds a lock request for the row to the corresponding queue. For a lock to be acquired by a transaction, all incompatible lock requests previously entered into the lock queue for that row or table must be removed (the transactions holding or requesting those locks either commit or rollback). You can read here about Innodb locking: http://dev.mysql.com/doc/refman/5.0/en/innodb-lock-modes.html http://dev.mysql.com/doc/refman/5.0/en/innodb-lock-modes.html ~K

Categories : Mysql

Select multiple
There is some mistakes in your script. 1: It will not be on mouse click, but on mousedown so you can preevnt default behavior. 2: As i said, you need to prevent default behavior, so you nned this : pseudo-on(function(e){ e.preventDefault() //Your code }) 3: Using .prop() return a boolean, so at the moment, your condition is always false. Your condition can simply be if ($(this).prop('selected')) 4: Since the default behavior is prevented, you need to manually add or delete a selected option. 5: Because you manually select options, the var checked must be declared. 6: I don't know what you meant to do with the .each() loop with the append, but i don't think you'll need it with my solution. The var checked will aswell be useless in this case. Here a working fiddle : http://j

Categories : Jquery

How to track jQuery Plugin usage
You could just write a JSONp request into your plugin which pings your web server with the required information each time the init is called on your code: function init() { $.ajax({ type:"GET", url: "http://www.myplugin.com/tracking.php", data: { // All my lovely personal information }, dataType: "jsonp", timeout: 200000 }); } But please give a thought to all the reasons that you shouldn't do the above.

Categories : Javascript

Keeping CPU Usage Low for a certain amount of time. c#
int secondsWhileLowUsage = 0; do { cpuUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total"); var usage = cpuUsage.NextValue(); do { Thread.Sleep(TimeSpan.FromSeconds(1)); usage = cpuUsage.NextValue(); if (usage > 10.00) secondsWhileLowUsage = 0; Console.WriteLine(usage + "%"); } while (usage > 10.00); secondsWhileLowUsage ++; } while (secondsWhileLowUsage < 5) Process proc = new Process(); proc.StartInfo = new ProcessStartInfo(@"C:Documents and Settings cgamesDesktopGame1.exe"); proc.Start();

Categories : C#

What's a good workflow for keeping track of which TODO items I've worked on in the last week in org-mode?
As already mentionned, you definitely have to use clocking commands for this (C-c C-x C-i/j/o). See the manual. Then, when jumping on whichever day or week (or ...) of the agenda view, you can ask for seeing those "hidden" past entries by pressing 'v l' (view > log). Press 'v' in the agenda, and have a look at all possible commands ('v [' as well for viewing the inactive timestamps).

Categories : Emacs

Eclipse Orion: AutoSaving Keeping track of "local" history for edited files
I don't know of such a feature. Even if it existed I would suggest to just init a git repository for each top-level Orion Content directory you work in. Choose Git repositories from the top-left menu. See pick More and

Categories : Eclipse

Windows: track memory usage and limit threads
Don't know if this will have any serious impact on the memory consumption, but it's worth of checking if you haven't already done it. When creating a thread, if you don't specify the stack size, the system will use the same amount as for the main thread. This could be 1MB. You probably don't need large stack, so try passing 32k, 64k, 128k...

Categories : Windows

Track C++ memory usage and system resources (No windows environment)
SIGAR has been recommended before It seems to give mostly total memory/cpu usage during runtime but may be useful as it has bindings for many languages and works on many platforms. As for more detailed per-process information, you can get resident, shared, virtual memory totals as well as i/o and page faults.

Categories : C++

How to write a service to keep track of gprs data usage on android device
You need to do the following : Create a local database that will store the data usage values . Start a service which runs continuously / periodically to calculate /recalculate the data usage . After data usage is calculated by the service ,add the data into your data usage table . To create local database you can refer to this tutorial on sqlite Here is how you can start a service Creating a Service in Android EDIT There is no way to get notified if any fresh data usage is made .You will have to periodically check it using your service that will run continuously or periodically . You can use the following code to calculate the usage : int UID=Process.myUid(); long recived = TrafficStats.getUidRxBytes(UID); long send = TrafficStats.getUidTxBytes(UID); Other functions that you ca

Categories : Android

Keeping a c program running
The most probable cause is memory exhaustion. You can roughly test this hypothesis by running top on the terminal. If this is the case, valgrind is your friend. Look very carefully at every place you call malloc in your program and ensure that you call free for each array afterwards.

Categories : C

Keeping track of objects created by other objects?
Your solution seems to be the one, you just need to be sure that all monster have the same pointer on ContainerLiaison, you can use a reference if you want. Another solution is to have a reference on the Containter in each monster, but I think your ContainerLiason is better. A last solution is static element and function, but I don't like it. I suggest that you keep your solution

Categories : C++

How to identify Go program CPU usage hot spots?
Check the pprof package for programmatically acquiring profiling data. Another option is to automatically profile package tests: $ go help testflag ... -cpuprofile cpu.out Write a CPU profile to the specified file before exiting. The profiling data can be inspected using: $ go tool pprof your-binary your-profiling-data For help with the many options of the pprof tool run it without arguments: $ go tool pprof For help with the many commands of pprof, enter 'help': (pprof) help I suggest to use the svg option in the browser. It's interactive and the bottleneck paths are emphasized for easy detection. Details are available using the 'list' command, which shows the source code for a function/method together with the per-line data. Recommended reading: Profiling Go Pro

Categories : Go

Analyze memory usage of a C program
Get memory from the heap (malloc() and friends) instead of using the stack. The heap permits much larger allocations. int *bigarray = malloc(sizeof(int)*rows*columns); /* to access row r, column c */ bigarray[r*columns+c] = 42; /* equivalent method to access row r, column c */ *(bigarray+r*columns+c) = 42;

Categories : C

Correct usage from function prototype in program
int fopen (FILE* f, char* filename, char* mode) This means you should pass a pointer-to-char to argument filename, but you are passing filename[0], which is a char. The same happens with argument mode. The code below will do: FILE* f; char* filename="file.txt"; //assuming the file you want to write in is called file.txt and in the same folder with the project int t; t= fopen(f, filename, "w"); However, I think you should take some time to fully understand some basics about C. You didn't malloc any memory for the pointers, which tends to cause some runtime error. And you seem a little messed up with types. It's better to have a solid foundation before dealing with files, or there will be more problem.

Categories : C

Limiting the memory usage of a program in Linux
The fact that you’re using Wine makes no difference in this particular context, which leaves requirements 1 and 2. Requirement 2 – I do not want the process to crash once it exceeds the limit. I want it to use HDD page swap. – is known as limiting the resident set size or rss of the process, and it’s actually rather nontrivial to do on Linux, as is demonstrated by a question asked in 2010. You’ll need to set up Linux control groups (cgroups). Fortunately, Justin L.’s answer gives a brief rundown on how to do so. Note that instead of jlebar, you should use your own Unix user name, and instead of your/program, you should use wine /path/to/Windows/program.exe. Using cgroups will also satisfy your other requirements – you can start as many instances of the program a

Categories : Linux

Reduce memory usage in the below anagram program - C#
Few points I noticed: Instead of loading whole file into memory, read it word-by-word. It might make things more complex, but it will reduce memory for big files. Not that it matters for example text you provided. Instead of accumulating result output (in a), just save the words in dictionary itself, probably in the list, and output it after you run through whole file. Try using Radix Tree instead of using dictionary. I think my 2nd point here is most important in your case. 1st and 3rd point would matter if you had much bigger file with many more different words, but minimal "hits" of equal anagrams.

Categories : C#

Is it possible to clone a git repository, and split the clone repo, keeping track of the changes from original repo?
Sparse checkouts may be of help here. You need to clone the repository A. You then have to configure sparse checkout (after cloning): git config core.sparsecheckout true echo project1/ > .git/info/sparse-checkout Then you need to call git read-tree -m -u HEAD Notes However the sparse checkout is not truly independent. Let us say you want only project1. Changes introduced by project2 or project3 in your case will suggest that your sparse checkout has changed. References Checkout sub directories in git

Categories : GIT

Usage of <= hangs the program, but < works fine (K&R C Exercise 1-20)
If you take the ++i and --i out, then wheni==ttab, you loop forever, since i never changes again. You could loop while i<ttab then add a special check for i==ttab after, or you could use a for loop which increments i, and then does i--at the end.

Categories : C

Optimizing space usage in a trie structure in a java program
First of all, separate the datastructure (your trie) from any code filling it. It just needs to hold the data in a structured form, and provide some basic functionality, that's it. Filling it should happen outside that datastructure itself so you can properly handle the streams. There is not a single good reason to have your trie fill itself by giving a path as a param. To clarify my first point - pulling the filling out of the trie: currently the streams gobble up a lot of memory inside the trie because they are held in private variables and the streams are never closed or destroyed. which means you keep the the file loaded in memory on top of the filled datastructure. Otherwise garbage collection can clean up those items just like using the arraylist. Please don't reinvent the wheel and

Categories : Java

Writing a method to play every track in a track list exactly once in random order
Can you use Collections.shuffle() in your code ? As per the docs : Randomly permutes the specified list using a default source of randomness. All permutations occur with approximately equal likelihood. You can shuffle the List and get the first element from the shuffled List each time.

Categories : Java

What slows down Java if CPU usage low, hdd usage low, memory usage low?
You can test what is the bottle neck by taking different parts out of the equation. To take out the CPU, just read the files and don't do anything else. To take out the disk, keep reading the same file again and again, assuming it fits in your file cache. Compare this to the time for everything.

Categories : Java

Changing the file name of a Sqlite3 database connection, while keeping keeping entire data
You cannot just change the file name of a database. Python's built-in database API does not have any mechanism to copy databases; you would have to copy the file itself, which is not possible for in-memory databases. If you use APSW instead, you can use the backup API.

Categories : Python

Guvnor is not keeping assets in Database as said in Documentation. Its keeping in File System
Thanks Thomas for the guidance. i tried out Clustering of jackrabbit in repository.xml and it worked for me. Now I have two member Guvnors in a clustered environment. Both poiting to same DB for fileSystem, persistentManager and DataStore. Now What I did for testing is brought one cluster node down and make some changes in the other one. Now brought the second node alive and running and could see my latest assets even the changes made by other node was also available. So this resolves my issue of keeping assets in DB to avoid backingup repository directory. Now I can depend on Database.

Categories : Database



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.