eval

Executing Javascript from inside textarea (custom JS console)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 02:13:38
问题 I am interested in building a text editor in a CMS backend that allows users to write Javascript into a textarea and test it while editing. The closest I can think of is something like. document.head.appendChild(document.createElement('script')).src='http://site.com/file.js'; But instead of .src='http://site.com/file.js'; I would need to fill the script element with the textarea value. Does anyone have any idea as how to handle something like this? 回答1: I have written a simple one of these

Using JavaScript eval to parse JSON

假装没事ソ 提交于 2019-12-04 01:17:37
问题 Question: I'm using eval to parse a JSON return value from one of my WebMethods. I prefer not to add jquery-json because the transfer volume is already quite large. So I parse the JSON return value with eval. Now rumors go that this is insecure. Why ? Nobody can modify the JSOn return value unless they hack my server, in which case I would have a much larger problem anyway. And if they do it locally, JavaScript only executes in their browser. So I fail to see where the problem is. Can anybody

Why can't I use attr_accessor inside initialize?

左心房为你撑大大i 提交于 2019-12-04 00:15:16
I'm trying to do an instance_eval followed by a attr_accessor inside initialize , and I keep getting this: ``initialize': undefined method 'attr_accessor'`. Why isn't this working? The code looks kind of like this: class MyClass def initialize(*args) instance_eval "attr_accessor :#{sym}" end end You can't call attr_accessor on the instance, because attr_accessor is not defined as an instance method of MyClass. It's only available on modules and classes. I suspect you want to call attr_accessor on the instance's metaclass, like this: class MyClass def initialize(varname) class <<self self end

dynamically create a class without a namespace

我只是一个虾纸丫 提交于 2019-12-03 21:48:45
I am trying to dynamically create a class using the eval method. It is working fine except for one small problem. As my code shows I am creating the Browser class inside the BrowserFactory class. When I do this the Browser class has an added namespace of BrowserFactory. Is there anyway to evaluate the Browser class from a string without the BrowserFactory namespace being attached? class BrowserFactory def self.create_browser(browser) super_class = nil case browser when 'IE' require 'watir' super_class = 'Watir::IE' when 'celerity' require 'celerity' super_class = 'Celerity::Browser' end raise

eval函数让我忧伤

别来无恙 提交于 2019-12-03 21:14:14
今天首次接触这个eval函数,让我忧伤了一把。我把当成字符串拼接,结果错得天远地远。大体情况是下面这句代码,一个劲的给我报NameError: name 'qinfeng' is not defined. class_obj = eval('qinfeng.zheng.ipvsadm.%s()' % class_name) 当时,我就想,这尼玛一个字符串拼接,还需要定义的啥鬼。 后面百度了一把,发现自个有点瓜。 原来eval这一骚操作之后,class_obj就是一个对象实例,而当时就是没有引包。 下面模拟一下,便于以后复习,记心真是很给狗了。 1. 代码结构如下 2. ipvsadm.py class Ipvs(): def say(self): print("我很蛋疼。。。") 3. 测试类 test.py import qinfeng.zheng.ipvsadm if __name__ == '__main__': class_name = 'Ipvs' class_obj = eval('qinfeng.zheng.ipvsadm.%s()' % class_name) print(type(class_obj)) class_obj.say() 当把import qinfeng.zheng.ipvsadm注释掉,运行test.py就会报以下错误 Traceback

Perl: Speeding up eval

好久不见. 提交于 2019-12-03 20:31:23
eval is slow when done on a string: The string first has to be parsed before it can be executed. I am looking for a way to cache the parsing, so that I can reuse the parsed string for yet another eval. The next eval will be the same code but will not eval to the same value, so I cannot simply cache the results. From the description I am looking for ceval from: https://metacpan.org/pod/Eval::Compile But I cannot use Eval::Compile, as that requires a C-compiler for the platform, and it is not given that the user has a C-compiler. So can I do something similar to ceval in pure perl? Background

Webshell免杀绕过waf

耗尽温柔 提交于 2019-12-03 20:16:30
转自: https://www.cnblogs.com/-qing-/p/10631414.html 0x03 关于eval 于 assert # 关于eval函数在php给出的官方说明是 eval 是一个语言构造器而不是一个函数,不能被 可变函数 调用 可变函数:通过一个变量,获取其对应的变量值,然后通过给该值增加一个括号(),让系统认为该值是一个函数,从而当做函数来执行 通俗的说比如你 <?php $a=eval;$a() ?> 这样是不行的 也造就了用eval的话达不到assert的灵活,但是在php7.1以上assert已经不行 关于assert函数 assert() 回调函数在构建自动测试套件的时候尤其有用,因为它们允许你简易地捕获传入断言的代码,并包含断言的位置信息。 当信息能够被其他方法捕获,使用断言可以让它更快更方便! 0x04 字符串变形 # 字符串变形多数用于BYPASS安全狗,相当对于D盾,安全狗更加重视"形" 一个特殊的变形就能绕过安全狗,看看PHP手册,有着很多关于操作字符串的函数 ucwords() //函数把字符串中每个单词的首字符转换为大写。ucfirst() //函数把字符串中的首字符转换为大写。trim() //函数从字符串的两端删除空白字符和其他预定义字符。substr_replace() //函数把字符串的一部分替换为另一个字符串substr

Tensorflow中interactivesession和session的区别

南笙酒味 提交于 2019-12-03 18:59:21
tf.Session: sess=tf.Session() with sess.as_default(): print(result.eval()) 以下代码也可以完成相同的功能, sess=tf.Session() 以下两个命令具有相同的功能 print(sess.run(result)) print(result.eval(session=sess)) tf.Interactivesession: sess=tf.Interactivesession() print(result.eval()) sess.close() 总结: Tensorflow中不会自动生成默认会话,而是要手动指定。当默认会话被指定之后可以通过tf.Tensor.eval函数来计算一个张量的取值。Tensorflow中提供了一种在交互环境下直接构造默认会话的函数。这个函数就是tf.Interactivesession。使用这个函数会自动将生成的会话注册为默认的会话。 来源: https://www.cnblogs.com/zjuhaohaoxuexi/p/11805640.html

tensorflow : .eval() never ends

人盡茶涼 提交于 2019-12-03 18:04:08
问题 i am loading the cifar-10 data set , the methods adds the data to tensor array , so to access the data i used .eval() with session , on a normal tf constant it return the value , but on the labels and the train set which are tf array it wont 1- i am using docker tensorflow-jupyter 2- it uses python 3 3- the batch file must be added to data folder i am using the first batch [data_batch_1.bin]from this file http://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz As notebook: https://drive.google

Given the following LISP eval function - what is required to add defmacro?

本秂侑毒 提交于 2019-12-03 17:53:49
问题 Given the following definition of the LISP eval function - what is required to add the defmacro function? (Or even just evaluate a macro) (defun null. (x) (eq x '())) (defun and. (x y) (cond (x (cond (y 't) ('t '()))) ('t '()))) (defun not. (x) (cond (x '()) ('t 't))) (defun append. (x y) (cond ((null. x) y) ('t (cons (car x) (append. (cdr x) y))))) (defun list. (x y) (cons x (cons y '()))) (defun pair. (x y) (cond ((and. (null. x) (null. y)) '()) ((and. (not. (atom x)) (not. (atom y))) (cons