eval

Why can't I use attr_accessor inside initialize?

∥☆過路亽.° 提交于 2019-12-05 12:59:55
问题 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 回答1: 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

Angular/Typescript Eval and this

让人想犯罪 __ 提交于 2019-12-05 12:59:48
So I am having a problem understanding how eval works with this in typescript/angular. Could someone please help me get the eval to work here? This is just a demo program so just ignore the fact that the logic doesn't make sense. I would just like to have eval update a dynamic array with a dynamic value. https://stackblitz.com/edit/angular-pfyt7q?file=src%2Fapp%2Fapp.component.ts export class AppComponent { arrTest1 = []; arrTest2 = []; arrTest3 = []; constructor() { this.TestClass.Run("this.arrTest1 = [1];"); this.TestClass.Run("this.arrTest2 = [2];"); this.TestClass.Run("this.arrTest3 = [3];

Embedding arbitrary objects in Clojure code

陌路散爱 提交于 2019-12-05 11:39:46
I want to embed a Java object (in this case a BufferedImage) in Clojure code that can be eval d later. Creating the code works fine: (defn f [image] `(.getRGB ~image 0 0)) => #'user/f (f some-buffered-image) => (.getRGB #<BufferedImage BufferedImage@5527f4f9: type = 2 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000 IntegerInterleavedRaster: width = 256 height = 256 #Bands = 4 xOff = 0 yOff = 0 dataOffset[0] 0> 0 0) However you get an exception when trying to eval it: (eval (f some-buffered-image)) => CompilerException java.lang.RuntimeException: Can't embed object in code,

用pytorch再实现mnist手写识别

守給你的承諾、 提交于 2019-12-05 10:19:24
用pytorch再实现mnist手写识别 mnist作为非常棒的数据集,所以入pytorch的坑就先试试mnist。 数据集下载 http://yann.lecun.com/exdb/mnist/ lecun的网站上可以下载的到,也可以用pytorch的datasets包下载 from torchvision.datasets import mn train_set = mn.MNIST('./data', train=True, download=True) test_set = mn.MNIST('./data', train=False, download=True) 但是注意的是,如果你没有 科学上网 ,是下载不下来的,速度像树懒一样非常非常非常慢。 预处理 预处理可以用transforms.Compose(),先除以255,再通过transforms.Normalize([0.5],[0.5])来将色彩值映射到[-1,1]闭区间里面,假设原色彩值是0,那么映射后就是-1。因为mnist图片都是灰度图,所以只有一个色彩通道。正常的彩色图片是RGB三通道的,transforms.Normalize([r,g,b],[d,e,f])这样对应每个RGB的均值和方差。 也可以自定义函数 def data_tf(x): x = np.array(x, dtype='float32')

WEBSHELL-恶意代码检测

馋奶兔 提交于 2019-12-05 10:10:42
静态查杀 提取特征写成规则库,调用规则库查杀。基于规则,会比较快,但漏报、误报会比较明显,一般的Webshell一句话木马变形混淆会比较多。 yara规则 $eval = /(<\?php|[;{}])[ \t]*@?(eval|preg_replace|system|assert|passthru|(pcntl_)?exec|shell_exec|call_user_func(_array)?)\s*\(/ nocase // ;eval( <- this is dodgy $eval_comment = /(eval|preg_replace|system|assert|passthru|(pcntl_)?exec|shell_exec|call_user_func(_array)?)\/\*[^\*]*\*\/\(/ nocase // eval/*lol*/( <- this is dodgy $b374k = "'ev'.'al'" $align = /(\$\w+=[^;]*)*;\$\w+=@?\$\w+\(/ //b374k $weevely3 = /\$\w=\$[a-zA-Z]\('',\$\w\);\$\w\(\);/ // weevely3 launcher $c99_launcher = /;\$\w+\(\$\w+(,\s?\$\w+)+\);/ //

js里json和eval()

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 08:44:53
JSON * - JS中的对象只有JS自己认识,其他的语言都不认识 * - JSON就是一个特殊格式的字符串,这个字符串可以被任意的语言所识别, * 并且可以转换为任意语言中的对象,JSON在开发中主要用来数据的交互 * - JSON * - JavaScript Object Notation JS对象表示法 * - JSON和JS对象的格式一样,只不过JSON字符串中的属性名必须加双引号 * 其他的和JS语法一致 * JSON分类: * 1.对象 {} * 2.数组 [] * * JSON中允许的值: * 1.字符串 * 2.数值 * 3.布尔值 * 4.null * 5.对象 * 6.数组 var arr = '[1,2,3,"hello",true]'; var obj2 = '{"arr":[1,2,3]}'; var arr2 ='[{"name":"孙悟空","age":18,"gender":"男"},{"name":"孙悟空","age":18,"gender":"男"}]'; var json = '{"name":"孙悟空","age":18,"gender":"男"}'; * JS对象 ---> JSON * JSON.stringify() * - 可以将一个JS对象转换为JSON字符串 * - 需要一个js对象作为参数,会返回一个JSON字符串 var

Redis(四):独立功能的实现

这一生的挚爱 提交于 2019-12-05 07:29:54
发布与订阅 Redis 的发布与订阅功能有 PUBLISH 命令, SUBSCRIBE 命令, PSUBSCRIBE 命令, PUBSUB 命令等组成。 客户端可以通过 SUBSCRIBE 命令订阅一个或多个频道,当其它客户端向被订阅的频道发送消息时,频道所有的订阅者都会收到这消息。 频道的订阅与退订 Redis会在 redisServer 中用 pubsub_channels 字典来记录订阅的客户端和频道的关系。其中字典的键是被订阅的频道,而字典的值是一个客户端链表,保存了订阅这个频道的所有客户端。 比如有一个客户端执行了 SUBSCRIBE HEllO ,另一个客户端执行 SUBSCRIBE HELLO WORLD ,那么此时 redisServer 中 pubsub_channels 的结构如下: 订阅频道 当客户端执行 SUBSCRIBE <channel1> <channel2...> 命令时,服务器会现在 pubsub_channels 字典中查询是否有对应的键,如果存在,则将客户端添加到键对应的链表的末端,如果不存在,则在字典中添加键,并关联新的链表,然后将客户端加入链表。 退订频道 当客户端执行 UNSUBSCRIBE 命令时,服务器会在 pubsub_channels 的字典中找到对应的键,然后遍历链表,找到客户端未自身的节点移除。如果移除完节点后,链表为空

How to “eval” results returned by “paste0”?

半腔热情 提交于 2019-12-05 07:20:48
问题 It seem that I can never get the returned values of 'paste0' been evaluated , as well as any characters that have been quoted. Do I have to use 'substr' or 'gsub' to remove these quotation marks ? eval(paste0('1','+','1')) [1] "1+1" eval(expression(paste0('1','+','1'))) [1] "1+1" eval(expression("1+1")) [1] "1+1" eval("1+1") [1] "1+1" eval(expression(1+1)) [1] 2 eval(1+1) [1] 2 回答1: An expression consisting of a string is just the string, evaluating the string just returns the string (if you

基础之杂货铺

╄→尐↘猪︶ㄣ 提交于 2019-12-05 06:45:58
生成器 (generator) (1)列表生成式: 使代码更简洁,适合数据量比较小,如果数据量非常大,就可以用 函数 作生成器(如下例:斐波那契数列) 1 a = [i*2 for i in range(10)] 2 # 得到列表a=[0, 2, 4, ... , 18] 3 # 等价于 4 a = [] 5 for i in range(10): 6 a.append(i * 2) 7 补充:a = [该参数可以是函数 for i in range(10)] 列表生成式 (2)生成器的定义: 1) 只有 在 调用 时才会生成 相应的数据 ,一次性的【节省内存空间】,列表生成器只要把一个列表生成式的 [ ] 改成 ( ),用next()或.__next__()取值 1 c = (i*2 for i in range(10)) # 生成器 2 print(c) 3 # c: <generator object <genexpr> at 0x01E47F00> 4 for i in c: 5 print(i) 6 7 c = [i*2 for i in range(10)] # 生成式 8 print(c) 9 # c:[0, 2, 4, 6, 8, 10, 12, 14, 16, 18] 列表生成器 2) 只记录 当前位置 c. __next__ () -->取下一个数据

函数的基本操作

允我心安 提交于 2019-12-05 06:45:52
自学函数的笔记整理 函数与函数式编程 编程方法: 1、面向对象 -->类 -->class(关键字) 2、面向过程 -->过程 -->def(关键字) 3、函数式编程 -->函数 -->def(关键字) python:非纯函数式编程,也是面向对象的(最火) 定义函数和定义过程的区别: 过程即为没有返回值的函数 1 # 定义函数 2 def func1(): 3 print('in the func1') 4 return 0 5 # 定义过程 6 def func2(): 7 print('in the func2') 8 9 x = func1() # x接收返回值0 10 y = func2() # y接收返回值空(python中给出了隐式返回值None) 11 print(x, y) # 0 None 区别 1 def test(x): 2 ''' 3 文档描述 4 :param x: 5 :return: 6 ''' 7 # 函数体(逻辑) 8 x += 1 9 # 定义返回值,终止函数的运行 10 return x 函数结构 1 import time 2 def test(): 3 ''' 4 文档描述 5 :param x: 6 :return: 7 ''' 8 # 函数体(逻辑) 9 time_format = '%Y-%m-%d %X' # X:时分秒 10