FAQ Database Discussion Community


Calculate Dice Roll from Text Field

java,random,eval,jtextfield,dice
QUESTION: How can I read the string "d6+2-d4" so that each d# will randomly generate a number within the parameter of the dice roll? CLARIFIER: I want to read a string and have it so when a d# appears, it will randomly generate a number such as to simulate a...

How to evaluate custom javascript expression with the context in strict mode?

javascript,properties,scope,this,eval
Update I've come up with a concise solution to this problem, that behaves similar to node's vm module. var VM = function(o) { eval((function() { var src = ''; for (var prop in o) { if (o.hasOwnProperty(prop)) { src += 'var ' + prop + '=o[\'' + prop + '\'];';...

How can I use vim regex to replace text when math divide is involved in the expression

regex,vim,eval
I am using vim to process text like the following 0x8000 INDEX1 .... 0x8080 INDEX2 .... .... 0x8800 INDEXn .... I want to use regular expression to get the index number of each line. that is 0x8000 ~ 0 0x8080 ~ 1 .... 0x8800 ~ n The math evaluation should...

How to use this javascript code with eval or in a iim file?

javascript,eval,imacros
I want to use this code with eval or in a iim file without using js file.I tried for using it into eval but didn't work.Or is there any other way that can allow this code into iim file directly? please help me! do { do { iimPlay("CODE:ondialog pos=1 button=ok...

converting string to tuple in python

python,string,tuples,eval
I have a string returnd from a software like "('mono')" from that I needed to convert string to tuple . that I was thinking using ast.literal_eval("('mono')") but it is saying malformed string....

Parse Perl range string such as “1,4..7,10,11” [duplicate]

perl,parsing,eval
This question already has an answer here: Is there a Perl module for parsing numbers, including ranges? 1 answer Given a string such as 1,4..7,10,11, is there a neat way to parse it into the list (1,4,5,6,7,10,11)? The string is given as a command-line argument. My plan is ensure...

Using eval() to check if global variable isset

php,eval,constants
I am trying to check defined variables based on passing a single portion of the variable. (The rest of the variable is static and all other portions of it are the same), so I made a test to find out if this is possible. It does not work, but perhaps...

Use of eval when building a dict in a for loop. Name is not defined

python,dictionary,eval
Mostly curious why this syntax isn't behaving in the way I would expect it to. Inside of a class's init which accepts multiple parameters (id, departmentId, active), I have the following variable: attributes = [ {'id': 5}, {'departmentId': 10}, {'active': True} ] Essentially, I'm trying to build a dictionary where...

Javascript Eval overwriting variable

javascript,eval
Don't understand why the code below is overwriting my var arr. Any help appreciated. var arr = [1,2,3] var string = "function swap(arr) { var newarr = arr; var temp = arr[0]; newarr[0] = arr[arr.length-1]; newarr[arr.length-1] = temp; return newarr }" var test = eval("[" + string + "]")[0]; test(arr);...

How to return a random show function effect with javascript

javascript,jquery,arrays,random,eval
I'm trying to show some element with a random effect. I store those functions in an array and try to get a random function from that array, but the functions seem to rum at the same time. $.random_show = function(){ (function($) { $.rand = function(arg) { if ($.isArray(arg)) { return...

Store php code rules in database

php,mysql,eval
Currently Im designing db and architecture of a web-site with delivery providers. Some providers have static delivery price, there are no problems, but some of them have dynamically calculated price. For example: if ({{item_type}} == 1) $price = {{default_price}} - {{default_price}} * 0.5; else $price = {{default_price}}; // {{...}} values...

Php: json to constants

php,eval,constants
I have a Json that contains a few contants I'd like to auto-define. It works fine with simple "key": "val" statements, but I can't make it work for eval staments: $cat test.php <?php function objDefinition($obj) { foreach ($obj as $key => $val) { $val = $val; \define($key, $val); } }...

How to convert a statement in a string into a format that can be evaluated (Ruby)

ruby,string,eval
I am writing a quiz program where I need to store boolean statements as strings in an array and output them to the terminal as part of a question. I then want to evaluate the contents of these strings and return the value so that I can test whether I...

How to use Eval() data in a method within a repeater

c#,asp.net,eval,repeater
I've written a method that checks and returns the status code of a URL. Then I used a repeater to grab rows from my db. What I'm trying to figure out is how to use the data returned in the repeater in a method called within the repeater. Here's the...

Using Javascript's eval() on HTML Text

javascript,html,eval
I am toying around with some basic constructs in HTML and Javascript (i.e., I am a HTML/Javascript n00b), and there is a feature I simply cannot seem to implement properly. In a nutshell, I'd like to grab text from the body of an HTML page and evaluate it using Javascript...

How to execute JavaScript function in an Ajax() Response

javascript,jquery,ajax,function,eval
I have a home page that load the ajax() response and post it to UL as LI content, with the same page I have script function that can select the LI content with trigger for another function, but isn’t working. PAGE 1 HTML <ul id="feature-deals" class="list-products allShopping-deals"> </ul> SCRIPT $(document).ready(function(){...

Foreach loop unable to find object

r,foreach,parallel-processing,eval
I am trying to use foreach with the parallel backend to speed up computation (of cross validation of an {AUCRF} random forest for feature selection, if this does matter). In the process of doing so i need to get a subset of a vector. The name of the vector can...

Parse a string expression

python,regex,parsing,expression,eval
I need to parse a string which contains an expression. The language is proprietary and I am not sure I know the complete syntax but essentially an example expression looks like this: "some_name+(some_other_name * 4 * different_name)+ 'h40028" There are various names i've illustrated as some_name etc above which I...

Custom directive: How evaluate bindings with dynamic HTML

javascript,angularjs,angularjs-directive,eval
Setup: Very simplified HTML: <td ng-repeat="col in cols"> <div ng-bind-html="col.safeHTML"></div> </td> JS controller: $scope.cols = [ { field : 'logo', displayName : 'Logo', cellTemplate: '<div style="color:red">{{col}}</div>' }, { field : 'color', displayName : 'Color', cellTemplate: '<div style="color:green">{{col}}</div> } ]; JS link directive link function: for (var i = 0, j...

What is an alternative to using 'eval' to accessing a variable by name to “sync” it with another?

javascript,eval
I want to keep two JavaScript variables in sync when I run a function. The variable that is to be pointed to is in an object. The code I have so far is this: var myname = "bob"; var thevar = ""; var varobj = {tvar: "myname"}; var syncvar =...

How to evalulate xml literal using scala.tools.reflect.ToolBox in runtime?

xml,scala,reflection,eval
Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25). Type in expressions to have them evaluated. Type :help for more information. scala> import scala.reflect.runtime.currentMirror import scala.reflect.runtime.currentMirror scala> import scala.tools.reflect.ToolBox import scala.tools.reflect.ToolBox scala> def eval(code: String) = { | val toolbox = currentMirror.mkToolBox() | toolbox.eval(toolbox.parse(code)) | } eval:...

Python parse mathematical text expression

python,regex,math,eval
I was wondering if anyone knew of a good python library for evaluation text-based mathematical expressions. So for example, >>> evaluate("Three plus nine") 12 >>> evaluate("Eight + two") 10 I've seen similar examples that people have done for numeric values and operators in a string. One method used eval to...

Can an inserted