convert

Play Framework: How to convert strings to numbers while validating JSON

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given the following JSON.. { "ask":"428.00", "bid":"424.20" } ... I need to convert the values of ask and bid to numbers: { "ask": 428.00, "bid": 424.20 } To do that, I've created a validator that reads the string value and passes it to method toNumber , which validates and converts the given string: def validate = ( ((__ \ 'ask).json.pickBranch(Reads.of[JsString] <~ toNumber)) ~ ((__ \ 'bid).json.pickBranch(Reads.of[JsString] <~ toNumber)) ).reduce private def toNumber(implicit reads: Reads[String]) = { Reads[Double](js => reads.reads(js)

PHP - How do I convert a rectangle image to a square image?

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I change a rectangular image to a square-shaped avatar in php, such that no matter what is the resolution of the uploaded image, it is able to resize to a centralized 42 x 42 pixel avatar. This is the php code I am using. Anyone can advise. <?php //Name you want to save your file as $save = 'myfile1.jpg'; $file = 'original1.jpg'; echo "Creating file: $save"; $size = 0.45; header('Content-type: image/jpeg') ; list($width, $height) = getimagesize($file) ; $modwidth = $width * $size; $modheight = $height * $size; $tn =

Convert DBContext to ObjectContext for use with GridView

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a webforms project using EF codefirst to persist data. I'd like to use a GridView and EntityDataSource, in order to save writing CRUD. Is this possible? Can I convert my DBContext to an ObjectContext that is expected by the EntityDataSource? Here's what I tried: However I get this exception: Unable to cast object of type 'SomeNamespace.Models.ShopDBContext' to type 'System.Data.Objects.ObjectContext'. 回答1: Try this: var context = new YourDbContext (); var adapter = ( IObjectContextAdapter ) context ; var objectContext =

Convert closure to es6 module

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using a javascript build environment that supports es6 modules ( using es6-module-transpiler ) so you can simply import stuff across different files. Now I got a third party library that I'd like to be "importable". The library populates its functionality like this: (function () {/*...*/}).call(this); Would it be safe to omit the closure and convert it to: export default function () {/* ... */}; Or is there a better way? Thanks in advance! 回答1: The original code you show invokes the anonymous function, which to make any sense must define

PIL Convert PNG or GIF with Transparency to JPG without

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm prototyping an image processor in Python 2.7 using PIL1.1.7 and I would like all images to end up in JPG. Input file types will include tiff,gif,png both with transparency and without. I've been trying to combine two scripts that I found that 1. convert other file types to JPG and 2. removing transparency by creating a blank white image and pasting the original image over the white background. My searches are being spammed with people seeking to generate or preserve transparency rather than the opposite. I'm currently working with this:

Not able to convert Numpy array to OpenCV Mat in Cython when trying to write c++ wrapper function (Updated)

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to implement cv::cuda::warpPerspective in python2, there is a very sweet post about how to do that here: link . I followed the instruction as described in that post, however, I got Segmentation fault (core dumped) error. I was able to allocate the error in GpuWrapper.pyx file line 11: pyopencv_to(<PyObject*> _src, src_mat) It seems that it fails to convert numpy array to opencv Mat. I am not sure where is wrong and how to fix it. The python script that got Segmentation fault (core dumped) error is in below: import cv2 import

error CS0266: Cannot implicitly convert type &#039;object&#039; to &#039;int&#039;

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: error CS0266: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?) int dd= 6000; sqlCmdDefaultTime = new SqlCommand("myQuery", sqlCon); sqlDefaultTime = sqlCmdDefaultTime.ExecuteReader(); while (sqlDefaultTime.Read()) { dd= sqlDefaultTime[1]; } how can i cast 回答1: Simple cast to int : dd = (int)sqlDefaultTime[1]; 回答2: Try this... int.TryParse(sqlDefaultTime[1].ToString(), out dd); in the event that the parse is successful dd will now be a new value. Unless of course the object is an int

Watermark images with paperclip, rails 4

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been attempting to add watermarks to my images, following the answer listed in watermark with paperclip : Watermark.rb: module Paperclip class Watermark < Processor # Handles watermarking of images that are uploaded. attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options, :watermark_path, :watermark_offset, :overlay, :position def initialize file, options = {}, attachment = nil super geometry = options[:geometry] @file = file @crop = geometry[-1,1] == '#' @target_geometry = Geometry.parse geometry @current

How to convert text to SVG paths?

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a font in ttf file and want to generate SVG with text turned into paths. I don't need image (so using imagettftext or Image Magick font rendering capabilities is not enough), I need shape, that can be scaled up and down and I want to lose information about font used and don't want to reference it in SVG file (so font-face declarations can't be used here). Is it possible? 回答1: I have created my own class to process SVG font file and to turn text into glyphs. Example of using: include "SVGFont.php"; $svgFont = new SVGFont(); $svgFont-

Batch convert Mac iWork files to PDF on the command line

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to batch convert a bunch of assorted iWork files (Numbers, Pages, Keynote) to PDF on the command line. I've been trying cups-filter but there's no MIME type filter for the iWork types. I then looked into using qlmanage to generate the preview image and use that, but this doesn't seem to work for multi file Keynote documents as they generate as HTML rather than PDF. Any suggestions? I'd rather not resort to AppleScript. 回答1: Well... you need something that understand the iWork file formats, can render the documents to