dynamic

Resizing an array with C

独自空忆成欢 提交于 2019-12-17 06:05:46
问题 I need to have an array of structs in a game I'm making - but I don't want to limit the array to a fixed size. I'm told there is a way to use realloc to make the array bigger when it needs to, but can't find any working examples of this. Could someone please show me how to do this? 回答1: Start off by creating the array: structName ** sarray = (structName **) malloc(0 * sizeof(structName *)); Always keep track of the size separately: size_t sarray_len = 0; To increase or truncate: sarray =

How to implement a rule engine?

佐手、 提交于 2019-12-17 05:16:08
问题 I have a db table that stores the following: RuleID objectProperty ComparisonOperator TargetValue 1 age 'greater_than' 15 2 username 'equal' 'some_name' 3 tags 'hasAtLeastOne' 'some_tag some_tag2' Now say I have a collection of these rules: List<Rule> rules = db.GetRules(); Now I have an instance of a user also: User user = db.GetUser(....); How would I loop through these rules, and apply the logic and perform the comparisons etc? if(user.age > 15) if(user.username == "some_name") Since the

How to implement a rule engine?

有些话、适合烂在心里 提交于 2019-12-17 05:16:06
问题 I have a db table that stores the following: RuleID objectProperty ComparisonOperator TargetValue 1 age 'greater_than' 15 2 username 'equal' 'some_name' 3 tags 'hasAtLeastOne' 'some_tag some_tag2' Now say I have a collection of these rules: List<Rule> rules = db.GetRules(); Now I have an instance of a user also: User user = db.GetUser(....); How would I loop through these rules, and apply the logic and perform the comparisons etc? if(user.age > 15) if(user.username == "some_name") Since the

Dynamically build call for lookup multiple columns

无人久伴 提交于 2019-12-17 05:07:06
问题 How can I dynamically lookup multiple fields and add by reference using character vector variable as argument. In below case I want to lookup two columns and get rid of i. prefix in them. Of course they can override already existing columns with the same name. library(data.table) set.seed(1) ID <- data.table(id = 1:3, meta = rep(1,3), key = "id") JN <- data.table(idd = sample(ID$id, 3, FALSE), value = sample(letters, 3, FALSE), meta = rep(1,3), key = "idd") select <- c("value","meta") # my

Why does a method invocation expression have type dynamic even when there is only one possible return type?

此生再无相见时 提交于 2019-12-17 04:33:39
问题 Inspired by this question. Short version: Why can't the compiler figure out the compile-time type of M(dynamic arg) if there is only one overload of M or all of the overloads of M have the same return type? Per the spec, §7.6.5: An invocation-expression is dynamically bound (§7.2.2) if at least one of the following holds: The primary-expression has compile-time type dynamic. At least one argument of the optional argument-list has compile-time type dynamic and the primary-expression does not

jQuery autocomplete for dynamically created inputs

a 夏天 提交于 2019-12-17 04:30:36
问题 I'm having an issue using jQuery autocomplete with dynamically created inputs (again created with jQuery). I can't get autocomplete to bind to the new inputs. Autocomplete $("#description").autocomplete({ source: function(request, response) { $.ajax({ url: "../../works_search", dataType: "json", type: "post", data: { maxRows: 15, term: request.term }, success: function(data) { response($.map(data.works, function(item) { return { label: item.description, value: item.description } })) } }) },

What is the correct way to write HTML using Javascript?

谁都会走 提交于 2019-12-17 04:18:35
问题 I see in some posts that people frown upon using document.write() in javascript when writing dynamic HTML. Why is this? and what is the correct way? 回答1: document.write() will only work while the page is being originally parsed and the DOM is being created. Once the browser gets to the closing </body> tag and the DOM is ready, you can't use document.write() anymore. I wouldn't say using document.write() is correct or incorrect, it just depends on your situation. In some cases you just need to

Replace dynamic content in XML file

天涯浪子 提交于 2019-12-17 03:41:10
问题 Quick Summary: I need to create a Bash script to change the text within a node automatically every week. The script will match the node and replace the text inside them (if this is possible)? How would I do this? Long Summary: I host a Minecraft server which has shops, each of which have their own .xml file in the /ShowcaseStandalone/ffs-storage/ directory. Every Sunday my server restarts and executes several commands into the terminal to reset several things. One thing that I am trying to

Displaying emoticons in Android

亡梦爱人 提交于 2019-12-17 02:54:06
问题 My IM app has to support emoticons. They are GIFs and have textual representations, which are used in the input box if the user selects one of them. But I'd like to display them as images after they have been sent.Currently my custom array adapter displays the sent message in a TextView of a row. What is the proper method to display images dynamically based on the occurrence of their textual representation? Do I have to search for emoticon texts, and if one found, remove the TextView from the

ImageView be a square with dynamic width?

本小妞迷上赌 提交于 2019-12-17 02:44:10
问题 I have a GridView with ImageViews inside. I have 3 of them for each row. I can set correctly the width with WRAP_CONTENT and scaleType = CENTER_CROP, but I don't know how to set the ImageView's size to be a square. Here's what I did until now, it seems to be ok except the height, that is "static": imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.WRAP_CONTENT, 300)); I'm doing