small

How do I read the contents of a small text file into a scalar in Perl?

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a small text file that I'd like to read into a scalar variable exactly as it is in the file (preserving line separators and other whitespace). The equivalent in Python would be something like buffer = "" try: file = open("fileName", 'rU') try: buffer += file.read() finally: file.close() except IOError: buffer += "The file could not be opened." This is for simply redisplaying the contents of the file on a web page, which is why my error message is going into my file buffer. 回答1: From the Perl Cookbook : my $filename = 'file.txt'; open(

Why does numpy.power return 0 for small exponents while math.pow returns the correct answer?

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In [25]: np.power(10,-100) Out[25]: 0 In [26]: math.pow(10,-100) Out[26]: 1e-100 I would expect both the commands to return 1e-100. This is not a precision issue either, since the issue persists even after increasing precision to 500. Is there some setting which I can change to get the correct answer? 回答1: Oh, it's much "worse" than that: In [2]: numpy.power(10,-1) Out[2]: 0 But this is a hint to what's going on: 10 is an integer, and numpy.power doesn't coerce the numbers to floats. But this works: In [3]: numpy.power(10.,-1) Out[3]: 0

Newly added column's data not being saved to DB

匿名 (未验证) 提交于 2019-12-03 02:22:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using Devise for user authentication in my Rails 4 app. Recently I added two new columns to the User model. They are first_name and last_name. I then updated the signin form with fields for both of these attributes. However, neither are being saved to the database when I test creating a new user. I thought it might be a mass assignment problem but I'm not getting any kind of database error. The user is successfully created but only the original attributes (email, password, and password_confirmation) are being stored. Can anyone help?

LESS: How can I pass a mixin as an argument to another mixin?

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have some basic mixins that apply some rules using media queries .on-small(@rules) { @media (@minWidthSmall) { @rules(); } } .on-medium(@rules) { @media (@minWidthMedium) { @rules(); } } // and .on-large, .on-x-large and so on And I'm trying to build a very simple flex-based grid system, I'm trying to pass the mentioned mixins as parameters so I can have a generic .make-column mixin. as follows: .make-col(@break-point-mixin, @span, @size) { flex: 1; box-sizing: border-box; /*********************************************************** Is the

Small ggplot2 plots placed on coordinates on a ggmap

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I would like to first use ggmap to plot a specific area with longitude and latitude as axes. Then I would like to put small ggplot2 plots on the specific locations, given their longitude and latitude. These can be barplots with minimal theme. My database may have the columns: 1. town 2. longitude 3. latitude 4. through 6. value A , B , C I generate a plot (pseudocode) p <- ggmap ( coordinates ) and I have my minimal ggplot2 design q <- ggplot2 ()+ geom_bar (....)+ ... x - axis null y axis null minimal template How to combine the

Splitting a large data frame into smaller segments

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following data frame and I want to break it up into 10 different data frames. I want to break the initial 100 row data frame into 10 data frames of 10 rows. I could do the following and get the desired results. df = data.frame(one=c(rnorm(100)), two=c(rnorm(100)), three=c(rnorm(100))) df1 = df[1:10,] df2 = df[11:20,] df3 = df[21:30,] df4 = df[31:40,] df5 = df[41:50,] ... Of course, this isn't an elegant way to perform this task when the initial data frames are larger or if there aren't an easy number of segments that it can be

Django. Override save for model

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Before saving model I'm re-size a picture. But how can I check if new picture added or just description updated, so I can skip rescaling every time the model is saved? class Model(model.Model): image=models.ImageField(upload_to='folder') thumb=models.ImageField(upload_to='folder') description=models.CharField() def save(self, *args, **kwargs): if self.image: small=rescale_image(self.image,width=100,height=100) self.image_small=SimpleUploadedFile(name,small_pic) super(Model, self).save(*args, **kwargs) I want to rescale only if new image

In Perl, how can I get the Cartesian product of multiple sets?

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to do permutation in Perl. For example I have three arrays: ["big", "tiny", "small"] and then I have ["red", "yellow", "green"] and also ["apple", "pear", "banana"] . How do I get: ["big", "red", "apple"] ["big", "red", "pear"] ..etc.. ["small", "green", "banana"] I understand this is called permutation. But I am not sure how to do it. Also I don't know how many arrays I can have. There may be three or four, so I don't want to do nested loop. 回答1: That's actually not permutation but Cartesian product . See Math::Cartesian::Product . #

Buffer too small error while using XMLAgg/XMLElement [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: XMLAGG with RTRIM issue 2 answers I am executing the below query in oracle and the following error comes up ORA-19011 : Character string buffer too small select Rtrim(Xmlagg (Xmlelement (e, wonum || ',')).extract ( '//text()' ), ',') as wolist from ( select w.wonum from workorder w connect by prior w.wonum = w.parent and prior w.siteid = siteid start with w.siteid = 'ABCD' and w.wonum = 'P1234' ) I have never used Xmlagg/Xmlelement hence I am not sure what's the issue. When the inner query is

Why is this small (155 lines-long) Pacman game on Python running so slow?

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have already cut everything I could from the main loop. I also optimized collisions for dynamic and static objects, reducing considerably the number of iterations. But it is still slow on his machine. I'll post the entire file for the case someone wants to test it, but you can just jump to the main loop at "while Exit==false:". import pygame from pyeuclid import Vector2 from math import sin,cos,pi from random import random class Thing: def __init__(self,pos): self.pos = pos things.append(self) def update(self): pass def draw(self,img):