w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Efficient use of FileSystems for listing zip file entries stored in resources
No, this isn't possible. The reason for this is that a) streams often can't be read twice and b) ZIP archives need random reading. The list of files is attached at the end, so you need to skip the data, find the file entry, locate the position of the data entry and then seek backwards. This is why code like Java WebStart downloads and caches the files. Note that you don't have to write the ZIP archive to disk, though. You can use ShrinkWrap to create an in-memory filesystem.

Categories : Java

Pulling out latest (multiple) entries from MongoDB
The best way to do this would be to sort the results in descending date-time order (so the latest response is first) and then to limit the result set by one. This would look something like: db.proficiencies.find(YOUR QUERY).sort({'date': -1}).limit(1)

Categories : Mongodb

Most Efficient Way to Add Millisecond Timestamps to MongoDB with C++ Driver
You should use the MongoDB Date type. This stores the date in a more efficient format than a string and includes millisecond accuracy. You can then have a single index on the field which you can query using any date/time. I'd also recommend reading http://blog.pythonisito.com/2012/09/mongodb-schema-design-at-scale.html which has some recommendations for storing time series data in MongoDB, especially if you're doing a lot of updates.

Categories : C++

Remove similar entries from TXT file?
$hosts_lines = file("hosts.txt"); foreach($hosts_lines as $line) { $temp = explode(":", $line); $hosts[$temp[0]][] = $temp[1]; } $localhost = file("localhost.txt"); foreach ($localhost as $line) { $temp = explode(":", $line); unset($hosts[$temp[0]]); } foreach($hosts as $ip => $ports) { foreach ($ports as $port) { printf("%s:%s", $ip, $port); } }

Categories : PHP

Efficient way in MongoDB to find where docments properties match a subset of anothers
The following code will do the trick db.searchTest.find({$and:[{$or:[{name:{$exists:false}},{name:"Joe"}]},{$or:[{age:{$exists:false}},{age:55}]},{$or:[{sex:{$exists:false}},{sex:"male"}]},{$or:[{name:{$exists:true}},{age:{$exists:true}},{sex:{$exists:true}}]}]}) To make this efficient, you need to build appropriate indexes on your data

Categories : Mongodb

Query to remove all redundant entries from a table
A general solution is to use the always unique pseudo-column ctid: DELETE FROM foo USING foo b WHERE foo.e2 = b.e1 AND foo.e1 = b.e2 AND foo.ctid > b.ctid; Incidentally it keeps the tuple whose physical location is nearest to the first data page of the table.

Categories : Postgresql

How to remove empty associative array entries
Try this, a little weird, but : array_filter($csv_arr, function($v){return array_filter($v) == array();}); Completely untested and I don't remember if this is the proper syntax or not for closures, but it could work. Edit (tested and working): <?php $csv_arr = array( 0 => array( 'Enfalac' => 'alpha linolenic acid 300 mg', 'Enfapro' => 'alpha linolenic acid 200 mg' ), 1 => array( 'Enfalac' => 'arachidonic acid 170 mg', 'Enfapro' => '' ), 2 => array( 'Enfalac' => '', 'Enfapro' => '' ), 3 => array( 'Enfalac' => 'calcium 410 mg', 'Enfapro' => 'calcium 550 mg' ) ); $c = function($v){ return array_fi

Categories : PHP

Linux - How to remove entries from /proc/devices
You could do something like this. This works fine. The header file is ommitted, where all file opeartions are implemented. #include <linux/module.h> #include <linux/init.h> #include <linux/cdev.h> #include "my_char_device.h" MODULE_AUTHOR("alakesh"); MODULE_DESCRIPTION("Char Device"); static int r_init(void); static void r_cleanup(void); module_init(r_init); module_exit(r_cleanup); static struct cdev r_cdev; static int r_init(void) { int ret=0; dev_t dev; dev = MKDEV(222,0); if (register_chrdev_region(dev, 2, "alakesh")){ goto error; } cdev_init(&r_cdev, &my_fops); ret = cdev_add(&r_cdev, dev, 2); return 0; error: unregister_chrdev_region(dev, 2); return 0; } static void r_cleanup(void) { cdev_del(&a

Categories : Linux

How to remove duplicate(fields) entries from a mysql db?
Before you set the constraint, do manual delete first. DELETE a FROM tableName a LEFT JOIN ( SELECT customer_invoice_id, MAX(id) id FROM tableName GROUP BY customer_invoice_id ) b ON a.customer_invoice_id = b.customer_invoice_id AND a.id = b.id WHERE b.customer_invoice_id IS NULL this will preserve the latest record for every customer_invoice_id. and you can now execute this statement, ALTER TABLE tableName ADD UNIQUE KEY idx1(customer_invoice_id) Demo, SQLFiddle Demo

Categories : PHP

Python program to remove double entries from line
Use set line = line.split() line = list(set(line)) set returns an un-ordered collection of unique elements, then convert it back to list and then sort the list. Edit: line = line.split() line = list(set(line)) out.write(" ".join(sorted(line, x: (int(x.split(':')[0]), int(x.split(':')[1])))) + ' ')

Categories : Python

Remove Duplicate Entries of 'Multicolumn'-List with LINQ
One way, using Enumerable.GroupBy and then select the highest according to TimesTested. var uniques = list1.Concat(list2) .GroupBy(t => t.ID) .Select(g => g.OrderByDescending(t => t.TimesTested).First()); Edit ... or in VB.NET (sorry, i didn 't see the tag first) and with your method: Friend Shared Function GetNewerEvalQs(list1 As List(Of EvaluationQuestionData), list2 As List(Of EvaluationQuestionData)) As List(Of EvaluationQuestionData) list1 = If(list1 Is Nothing, New List(Of EvaluationQuestionData), list1) list2 = If(list2 Is Nothing, New List(Of EvaluationQuestionData), list2) If Math.Max(list1.Count, list2.Count) = 0 Then Throw New ArgumentException("One of both lists must contain data") Dim newUniqueData = list1.Concat(list2). OrderByDes

Categories : Dotnet

How to remove zero entries inside a cell array in MATLAB?
As far as I know there is no single line function. You have to combine some functionallity. The first line finds the zeros in your cell array, while the second line deletes those entries. Note the () parentheses i.s.o. {} for removal. Try this: idxZeros = cellfun(@(c)(isequal(c,0)), cell_arr); cell_arr(idxZeros) = [];

Categories : Matlab

Remove multiple keys from Map in efficient way?
Assuming your set contains the strings you want to remove, you can use the keySet method and map.keySet().removeAll(keySet);. keySet returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. Contrived example: Map<String, String> map = new HashMap<>(); map.put("a", ""); map.put("b", ""); map.put("c", ""); Set<String> set = new HashSet<> (); set.add("a"); set.add("b"); map.keySet().removeAll(set); System.out.println(map); //only contains "c"

Categories : Java

Most efficient way to remove multiple items from a IList
If the IList<T> reference happens to refer to an instance of List<T>, casting to that type and using RemoveAll is apt to yield better performance than any other approach that doesn't rely upon the particulars of its implementation. Otherwise, while the optimal approach will depend upon the relative fraction of items that are going to be removed and the nature of the IList<T>, I would suggest that your best bet might be to copy the IList<T> to a new List<T>, clear it, and selectively re-add items. Even if the items in the list are not conducive to efficient hashing, the fact that the items in the IEnumerable<T> are in the same sequence as those in the IList<T> would render that irrelevant. Start by reading an item from the IEnumerable<T>.

Categories : C#

RestKit: how to remove core data entries to keep the content in sync with the server?
You want to look at the section "Fetch Request Blocks and Deleting Orphaned Objects" on this page. It requires you to be using an RKObjectManager (which you say you are) and describes the way that you tell RestKit how to find content in the data store that should be deleted (and it checks and doesn't delete things that it just received from the server).

Categories : IOS

What's the fastest way to remove or change large number of entries in arrays in MATLAB?
Have you checked your results? Because I think they are wrong. For example, if you have A = [... 1 2 3 4 5 6 7 8 9]; and you want to set element A(1,1) and A(2,3) to NaN. What you are doing is A([1 2], [1 3]) = NaN but that gives A = NaN 2 NaN NaN 5 NaN 7 8 9 The easiest and fastest way around this is to not use find, but logical indexing: M = rand(360,360,2,4); maximum = 0.05; tic; M(M(:,:,2,4) > maximum) = NaN; toc Which gives on my PC: Elapsed time is 0.003547 seconds.

Categories : Arrays

can't remove records in mongodb
It's not working because remove takes a query conditions object, not the list of documents to remove. You also need to put your find inside your remove callback or it will be executed before the remove completes. Try this instead: Article.remove({}, function (err) { if (!err) { Article.find(function(err,articles){ if(!err){ console.log(articles); }else{ console.log(err); } }); } });

Categories : Javascript

How to remove array element in mongodb?
Try the following query: collection.update( { _id: id }, { $pull: { 'contact.phone': { number: '+1786543589455' } } } ); It will find document with the given _id and remove the phone +1786543589455 from its contact.phone array. You can use $unset to unset the value in the array (set it to null), but not to remove it completely.

Categories : Mongodb

How to remove angle brackets in my esb while using mongodb
Use a script mediator to write a JS to perform this conversion. Its not a simple < to { conversion, as per your request some part of the request[1] in XML format needs to be converted to something similar to JSON. [1]<Status>200</Status> -> "Status":"200" Refer to the following link for more information on script mediator http://docs.wso2.org/wiki/display/ESB450/Sample+350%3A+Introduction+to+the+script+mediator+using+Javascript

Categories : Mongodb

remove _id from mongodb result java
Two options: You can remove the "_id" field from the map created: ... resultElementMap.remove("_id"); System.out.println(resultElementMap); Or you can ask the query results to not include the _id field: DBObject allQuery = new BasicDBObject(); DBObject removeIdProjection = new basicDBObject("_id", 0); DBCollection collection = db.getCollection("volume"); DBCursor cursor = collection.find(allQuery, removeIdProjection); DBObject resultElement = cursor.next(); Map resultElementMap = resultElement.toMap(); System.out.println(resultElementMap); See the documentation on projections for all of the details.

Categories : Java

Mongodb remove item from array
Try something, like this: BasicDBObject match = new BasicDBObject("_id", appId); //to match your direct app document BasicDBObject update = new BasicDBObject("list", email); coll.update(match, new BasicDBObject("$pull", update)); It should work.

Categories : Java

How to remove a document referenced by an id in mongoDB from php?
"To remove a document based on its ID, you need to ensure that you pass the ID as a MongoID object rather than just a string:" Normally what the PHP manual states is true but not for you. You have changed the type of your _id to something other than an ObjectId (aka a MongoId). With this in mind you need to search by that other object which is a MongoInt32: $db->collection->remove(array('_id'=>new MongoInt32(1)))

Categories : PHP

Python: How to check an XML file every x minutes for new entries, but not alert on previously alerted entries
Are the entries associated with a timestamp such that the new entries will always have timestamps later than the old entries each time the file is updated? If so, just keep the timestamp of the last entry you pushed, and as you parse the XML file, push anything newer and discard anything older. If not, Python has pretty decent set manipulation algorithms, so I'd try this: keep a set of entries that have been pushed already. already_pushed = set() Each time your script runs, do this: make another set of the entries from the file from_file = parse_file() "subtract" (set difference) the set of already-pushed entries new_entries = from_file - already_pushed push the new entries push_all(new_entries) go through the original set and prune anything older than 4 hours + 5 minutes cuto

Categories : Python

Update/remove subdocument in MongoDB collection
You need to use $elemMatch to match inside an array. The query rules in MongoDB specify that for conditions on array elements, any array element where any of the conditions matches is considered a match. With $elemMatch, all conditions need to match on the same element.

Categories : Mongodb

remove last 100 elements from query result in mongodb
it = db.Usage.find({'Usage': "",'Rating': "", 'Average Ratings': ""})[1001:1500] to_rem = [] for doc in iter: to_rem.append( doc['_id'] ) try: db.Usage.remove( {'_id' :{ '$in': to_rem } }) except: print "Unexpected error:", sys.exc_info()[0]

Categories : Mongodb

Remove MongoDB from auto starting on login
It should be either: launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist or launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

Categories : Osx

Remove old records in mongodb based on Month
Probably there is a cleaner solution but this should work: Create new Data field from date strings: var cursor = db.user_track.find() while (cursor.hasNext()) { var doc = cursor.next(); db.user_track.update( {_id : doc._id}, {$set : {access_time_ : new Date(doc.access_time)}}) } Now you can retrieve some records by comparing dates: db.user_track.find({access_time_: {$lt: new Date("Sep 01 2013 00:00:00 GMT+00:00")}}) If everything works as expected remove obsolete records: db.user_track.remove({access_time_: {$lt: new Date("Sep 01 2013 00:00:00 GMT+00:00")}}) In the future use date objects not strings

Categories : Mongodb

Remove database name from mongodb list of databases
I am using MongoDb for Windows 7, version 2.4.2 and the database was correctly removed. But it's possible delete the files from data directory in the variable "dbpath". That can be found at the second line of "mongod"'s process log. The files from this db starts with the same name of your database. The reason for this problem, probably is because the user who runs the process do not have all the permissions to manipulate the disk files.

Categories : Database

MongoDB - Safeguard against .remove() entire database?
There is nothing you can do in the current version to provide this functionality. In a future version when user defined roles are available you could define a role which allows insert() and update() but not remove() or drop() etc. and therefore make yourself log-in as a different higher-role user, but that's not available in the current (2.4) version.

Categories : Database

Remove duplicate values from the result of MongoDB objects
I would suggest using a $or query, something like: DBObject query = QueryBuilder.start().or( new BasicDBObject("Filename", java.util.regex.Pattern.compile(KeyWord)), new BasicDBObject("Content", java.util.regex.Pattern.compile(KeyWord))).get(); and do it as a single query instead of two separate queries. Please be advised that MongoDB will not be able to use an index for non-anchored regular expressions. See http://docs.mongodb.org/manual/reference/operator/regex/ for details.

Categories : Java

MongoDB driver ruby, remove field in document
Your syntax looks slightly incorrect. As per docs: collection.update( { _id: @id }, { $unset: { herField: true } }, { multi: true }); Need the 'multi' option if you want to update multiple documents. E.g. from all records on this collection. http://docs.mongodb.org/manual/reference/operator/unset/#op._S_unset

Categories : Ruby

How to smooth datatable of 15 entries to 100 entries?
A possible solution for 106 values: int k = 0; double a; double b; double[] coarse; double[] fine; for (int i = 0; i < 15; i++) for (int j = 0; j < 7; j++) { a = 1.0 - j * 1.0/7; b = 1.0 - a; fine[k++] = a * coarse[i] + b * coarse[i+1]; } fine[k] = coarse[14]; This assumes that the 15 original values are stored in array coarse[]. The interpolated values will end in array fine[].

Categories : C#

Unique entries for normal entries?
The DDL command to add a unique constraint on multiple columns: ALTER TABLE `table_name` ADD UNIQUE INDEX (`column1`, `column2`);

Categories : Mysql

Which one is run-time efficient and storage efficient in alogarithm?
A linear search starts at the beginning and compares every element until it finds what you're looking for. A binary search splits the list in the middle and looks if your value is greater or smaller than the pivot value. Then it continues doing so recursively. For example in a list of people. You're looking for John. The binary search looks in the middle of the list and might find Mark. John is lower, so the search discards the upper half of the list, since John will not be in it, and repeats this on the lower half (recursion) A binary search is much more efficient but the list must be sorted. However - sorting a list is slower than a linear search. You won't win in efficiency by sorting a unsorted list first.

Categories : Algorithm

Select table entries belonging to combinations of entries in another table (mysql)
I assume you have two table: orders (list of your orders) order_items (list of itemd of order) two table are relationed by field fk_order. try this: SELECT o.id, (select count(*) from order_items i where i.status = 'delivered' and i.fk_order = o.id) as item_delivered, (select count(distinct i.status) from order_items i where i.fk_order = o.id) as status_no FROM orders o

Categories : Mysql

Registry keys for context menu entries written, but no context menu entries
Most likely, the people whom it didn't work for have had .gif and/or .jpg associated with a different ProgId than "giffile" or "jpegfile". You can get Inno to add the registration to whatever the current ProgId association is like so: [Registry] Root: HKLM; Subkey: "SOFTWAREClasses{reg:HKLMSOFTWAREClasses.jpg|jpegfile}shellHalve size"; Flags: uninsdeletekey Root: HKLM; Subkey: "SOFTWAREClasses{reg:HKLMSOFTWAREClasses.jpg|jpegfile}shellHalve sizecommand"; ValueType: string; ValueName: ""; ValueData: """{app}himgr.exe"" ""%1""" Root: HKLM; Subkey: "SOFTWAREclasses{reg:HKLMSOFTWAREClasses.png|pngfile}shellHalve size"; Flags: uninsdeletekey Root: HKLM; Subkey: "SOFTWAREclasses{reg:HKLMSOFTWAREClasses.png|pngfile}shellHalve sizecommand"; ValueType: string; ValueName: ""; ValueData: """{app}hi

Categories : C#

MongoDB errors: mongodb-10gen E: Sub-process /usr/bin/dpkg returned an error code (1)
This is due to some corruption within the package manager dpkg itself, this thread from Ask Ubuntu: http://askubuntu.com/questions/195950/package-system-broken-e-sub-process-usr-bin-dpkg-returned-an-error-code-1 lists some solutions, more specifically the editing of the status file has been noted as one that always works.

Categories : Linux

Nodejs, MongoDB (node-mongodb-native). FindAndModify finds doc, but doesn't update it
In findAndModify, there is one more parameter which you can set, to return the old document(before update) or new document ( after update ). I am guessing this must be the issue. For confirmation, for the existing findAndModify() command, after this command is run, check that updated document from the mongo console, it must be changed.

Categories : Node Js

query based on matching elements in DBRef list for mongodb using spring-data-mongodb
Querying for one element on an array is exactly like query for a field equality. You could read the MongoDB documentation here. So your query will be: new Query(Criteria.where("users.$id").is(new ObjectId(userId)))

Categories : Mongodb

Connecting from WSO2DSS to MongoDB, receiving error: java.lang.NoClassDefFoundError: com/mongodb/ServerAddres.
The missing class looks like ServerAddress (I assume the missing "s" is a copy-paste issue) which is in the MongoDB Java driver (mongo-java-driver). Make sure mongo-java-driver-2.xx.jar is on the runtime classpath. Note that the runtime classpath is not always the same as the compile time classpath.

Categories : Mongodb



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