Search Results

Search found 46 results on 2 pages for 'coerce'.

Page 1/2 | 1 2  | Next Page >

  • In Ruby, can the coerce() method know what operator it is that requires the help to coerce?

    - by Jian Lin
    In Ruby, it seems that a lot of coerce() help can be done by def coerce(something) [self, something] end that's is, when 3 + rational is needed, Fixnum 3 doesn't know how to handle adding a Rational, so it asks Rational#coerce for help by calling rational.coerce(3), and this coerce instance method will tell the caller: # I know how to handle rational + something, so I will return you the following: [self, something] # so that now you can invoke + on me, and I will deal with Fixnum to get an answer So what if most operators can use this method, but not when it is (a - b) != (b - a) situation? Can coerce() know which operator it is, and just handle those special cases, while just using the simple [self, something] to handle all the other cases where (a op b) == (b op a) ? (op is the operator).

    Read the article

  • In Ruby, how does coerce() actually work?

    - by Jian Lin
    It is said that when we have a class Point and knows how to perform point * 3 like the following: class Point def initialize(x,y) @x, @y = x, y end def *(c) Point.new(@x * c, @y * c) end end point = Point.new(1,2) p point p point * 3 Output: #<Point:0x336094 @x=1, @y=2> #<Point:0x335fa4 @x=3, @y=6> but then, 3 * point is not understood: Point can't be coerced into Fixnum (TypeError) So we need to further define an instance method coerce: class Point def coerce(something) [self, something] end end p 3 * point Output: #<Point:0x3c45a88 @x=3, @y=6> So it is said that 3 * point is the same as 3.*(point) that is, the instance method * takes an argument point and invoke on the object 3. Now, since this method * doesn't know how to multiply a point, so point.coerce(3) will be called, and get back an array: [point, 3] and then * is once again applied to it, is that true? point * 3 which is the same as point.*(3) and now, this is understood and we now have a new Point object, as performed by the instance method * of the Point class. The question is: 1) who invokes point.coerce(3) ? Is it Ruby automatically, or is it some code inside of * method of Fixnum by catching an exception? Or is it by case statement that when it doesn't know one of the known types, then call coerce? 2) Does coerce always need to return an array of 2 elements? Can it be no array? Or can it be an array of 3 elements? 3) And is the rule that, the original operator (or method) * will then be invoked on element 0, with the argument of element 1? (element 0 and element 1 are the two elements in that array returned by coerce) Who does it? Is it done by Ruby or is it done by code in Fixnum? If it is done by code in Fixnum, then it is a "convention" that everybody follows when doing a coerce? So could it be the code in * of Fixnum do something like this: if (something.typeof? ...) else if ... # other type else if ... # other type else # if it is not a type I know array = something.coerce(self) return array[0].*(array[1]) end

    Read the article

  • In Ruby, how to implement 20 - point and point - 20 using coerce() ?

    - by Jian Lin
    In Ruby, the operation of point - 20 20 - point are to be implemented. But the following code: class Point attr_accessor :x, :y def initialize(x,y) @x, @y = x, y end def -(q) if (q.is_a? Fixnum) return Point.new(@x - q, @y - q) end Point.new(@x - q.x, @y - q.y) end def -@ Point.new(-@x, -@y) end def *(c) Point.new(@x * c, @y * c) end def coerce(something) [self, something] end end p = Point.new(100,100) q = Point.new(80,80) p (-p) p p - q p q - p p p * 3 p 5 * p p p - 30 p 30 - p Output: #<Point:0x2424e54 @x=-100, @y=-100> #<Point:0x2424dc8 @x=20, @y=20> #<Point:0x2424d3c @x=-20, @y=-20> #<Point:0x2424cc4 @x=300, @y=300> #<Point:0x2424c38 @x=500, @y=500> #<Point:0x2424bc0 @x=70, @y=70> #<Point:0x2424b20 @x=70, @y=70> 30 - p will actually be taken as p - 30 by the coerce function. Can it be made to work? I am actually surprise that the - method won't coerce the argument this way: class Fixnum def -(something) if (/* something is unknown class */) a, b = something.coerce(self) return -(a - b) # because we are doing a - b but we wanted b - a, so it is negated end end end that is, the function returns a negated version of a - b instead of just returning a - b.

    Read the article

  • juju bootstrap key error?

    - by mxdog
    I followed the guides the best as i could. there is some information missing like do as root or as regular user ..formatting, quotes no quotes..what the password or paraphrase for ssh should be ..couple other trivial things. that im sure add up to where im at (stuck!) so i have a working mass server on mx-nas-01 and 3 nodes and have been trying to get juju to start. I have tried this as both root and my regular account, sudo no-sudo and here is the output i get from juju bootstrap (however i try it) I don't know if this could be a host,domain,account issue or what i will mention i did have to shut off my dhcp server and install masq (all defaults) to get the maas pxe to work for the nodes mxdog@mx-nas-01:/$ juju bootstrap Traceback (most recent call last): File "/usr/bin/juju", line 8, in main(sys.argv[1:]) File "/usr/lib/python2.7/dist-packages/juju/control/init.py", line 183, in main env_config.load_or_write_sample() File "/usr/lib/python2.7/dist-packages/juju/environment/config.py", line 229, in load_or_write_sample self.load() File "/usr/lib/python2.7/dist-packages/juju/environment/config.py", line 115, in load self.parse(file.read(), path) File "/usr/lib/python2.7/dist-packages/juju/environment/config.py", line 138, in parse config = SCHEMA.coerce(config, []) File "/usr/lib/python2.7/dist-packages/juju/lib/schema.py", line 266, in coerce new_dict[k] = self.schema[k].coerce(v, path) File "/usr/lib/python2.7/dist-packages/juju/lib/schema.py", line 233, in coerce new_subvalue = self.value_schema.coerce(subvalue, value_path) File "/usr/lib/python2.7/dist-packages/juju/lib/schema.py", line 301, in coerce return self.schemas[selected].coerce(value, path) KeyError: 'mass' environments: maas: type: mass mass-server: http://192.168.0.30:80/MAAS mass-oauth: tDRdtJeEKVARBh93eT:N5dK5HSZBsA45cBdx9:S8wMNrfkT9PeYvQN9YrnbHGxmKARv8vb admin-secret: ########## default-series: precise

    Read the article

  • WPF DependencyProperty event before content changed

    - by morsanu
    First I will explain the context of the problem, because you might be able to point me in a better direction. I need to implement a undo-redo like system on an object. The object has a series of dependency properties. Some are double, int, string but some are also of DependencyObject type. I need to save the value of the property before it is changed, and for this I added the CoerceValueCallback. public static readonly DependencyProperty MyBackgroundProperty = DependencyProperty.Register("MyBackground", typeof(MyCustomizableBackground), typeof(MyComponent), new UIPropertyMetadata(default(MyCustomizableBackground), null, new CoerceValueCallback(OnPropertyChanged))); In OnPropertyChanged I save the value before it's changed. MyCustomizableBackground is the DependencyObject that has also some dependency properties. The problem is that in this case, where I have a custom object as a property, the OnPropertyChanged method isn't triggered, but when I have a common type, it is triggered.

    Read the article

  • Is it possible to coerce string values in xml to bool?

    - by Kugel
    Let's suppose I have xml like this one: <Server Active="No"> <Url>http://some.url</Url> </Server> C# class looks like this: public class Server { [XmlAttribute()] public string Active { get; set; } public string Url { get; set; } } Is it possible to change Active property to type bool and have XmlSerializer coerce "Yes" "No" to bool values? Edit: Xml is received, I cannot change it. So, in fact, i'm interested in deserialization only.

    Read the article

  • How to coerce type of ActiveRecord attribute returned by :select phrase on joined table?

    - by tribalvibes
    Having trouble with AR 2.3.5, e.g.: users = User.all( :select => "u.id, c.user_id", :from => "users u, connections c", :conditions => ... ) Returns, e.g.: => [#<User id: 1000>] >> users.first.attributes => {"id"=>1000, "user_id"=>"1000"} Note that AR returns the id of the model searched as numeric but the selected user_id of the joined model as a String, although both are int(11) in the database schema. How could I better form this type of query to select columns of tables backing multiple models and retrieving their natural type rather than String ? Seems like AR is punting on this somewhere. How could I coerce the returned types at AR load time and not have to tack .to_i (etc.) onto every post-hoc access?

    Read the article

  • Coerce Windows to show a thumbnail for my custom file type.

    - by Jakob Ryden
    Hi, I want to use the windows OpenFileDialog class in C# to browse files for my application. I would then like the files to show up with previews in Windows' "thumbnails" view. Is there a simple way to make this happen? I'm thinking there should be a way to encode the files so that Windows simply reads and displays the thumbnail information, even though it's an unsupported file type? I know Windows Vista has a different interface (IThumbnailProvider as opposed to IExtractImage) than Windows XP, but I need it to work across platforms. Thanks! / Jakob

    Read the article

  • Ruby on Rails: restrict file type with Paperclip using a flash uploader

    - by aperture
    I have a pretty basic Paperclip Upload model that is attached to a User model through has_many, and am using Uploadify to do the actual uploading. Flash sends all files with the content type of "application/octet-stream" so using validates_attachment_content_type rejects all files. In my create action, I am able to get the mime-type from the original file name, but only after it's been saved, with: def coerce(params) h = Hash.new h[:upload] = Hash.new h[:upload][:attachment].content_type = MIME::Types.type_for(h[:upload][:attachment].original_filename).to_s ... end and def create diff_params = coerce(params) @upload = Upload.new(diff_params[:upload]) ... end What would be the best way of white listing file types? I am thinking a before_validation method, but I'm not sure how that would work. Any ideas would be welcome.

    Read the article

  • How to convert searchTwitter results (from library(twitteR)) into a data.frame?

    - by analyticsPierce
    I am working on saving twitter search results into a database (SQL Server) and am getting an error when I pull the search results from twitteR. If I execute: library(twitteR) puppy <- as.data.frame(searchTwitter("puppy", session=getCurlHandle(),num=100)) I get an error of: Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class structure("status", package = "twitteR") into a data.frame This is important because in order to use RODBC to add this to a table using sqlSave it needs to be a data.frame. At least that's the error message I got: Error in sqlSave(localSQLServer, puppy, tablename = "puppy_staging", : should be a data frame So does anyone have any suggestions on how to coerce the list to a data.frame or how I can load the list through RODBC?

    Read the article

  • Why the SQL Server FORCESCAN hint exists

    It is often generalized that seeks are better than scans in terms of retrieving data from SQL Server. The index hint FORCESCAN was recently introduced so that you could coerce the optimizer to perform a scan instead of a seek. Which might lead you to wonder: Why would I ever want a scan instead of a seek? 12 must-have SQL Server toolsThe award-winning SQL Developer Bundle contains 10 tools for faster, simpler SQL Server development. Download a free trial.

    Read the article

  • Why is the concept of Marshalling called as such?

    - by chickeninabiscuit
    I've always thought that the concept of Marshalling had a bit of a funny name. My mental conception of the process would always involve an ol' wildwest gunslinging marshall who would coerce objects into serialized form at gunpoint. I just found out the real reason Marshalling is called what it's called and chuckled. Do you know the real reason, or perhaps you too are familiar with my gunslinger?

    Read the article

  • ggplot2 footnote

    - by user338714
    What is the best way to add a footnote to the bottom of a plot created with ggplot2? I've tried using a combination of the logic noted here http://www.r-bloggers.com/r-good-practice-%E2%80%93-adding-footnotes-to-graphics/ as well as the ggplot2 annotate function p + annotate("text",label="Footnote", x=unit(1,"npc") - unit(2, "mm"),y=unit(2, "mm"), just=c("right", "bottom"),gp=gpar(cex= 0.7, col=grey(.5))) but I am getting the error "Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class c("unit.arithmetic", "unit") into a data.frame".

    Read the article

  • How to access string[] in xhtml page

    - by Kalpana
    I am having a simple string array in my bean as public String[] colors = new String[]{"red", "blue", "green"}; and trying to display these colors from my xhtml as but I am getting a java.lang.NumberFormatException: For input string: "colors" java.lang.NumberFormatException: For input string: "colors" at java.lang.NumberFormatException.forInputString(NumberFormatException. java:48) at java.lang.Integer.parseInt(Integer.java:447) at java.lang.Integer.parseInt(Integer.java:497) at javax.el.ListELResolver.coerce(ListELResolver.java:166) at javax.el.ListELResolver.getValue(ListELResolver.java:51) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)

    Read the article

  • Zantaz's EAS exchange archive product doesn't integrate with Outlook in Windows 7

    - by Chris Farmer
    I work at a place that uses Exchange with Outlook for mail, and they also use a product from Zantaz called "EAS" which does server-side archiving of old messages. One of the artifacts of this archival is that email attachments are missing from the archived messages when viewed in Outlook. EAS has a client tool that plugs into Outlook that enables easy retrieval of those archived messages and their attachments, but it doesn't seem to work when installed on Windows 7. I have no direct evidence of this, other than that it simply doesn't work on my Windows 7 machine, and some of our network support staff seem to corroborate this. The symptom is that Outlook seems to know nothing of the existence of this EAS app. The EAS app also has a system tray icon which is there and offers some minimal functionality, but the real goodness is the Outlook integration, which I sorely miss. So, my question is this: does anyone here know whether it's possible to coerce this EAS product into working correctly in Windows 7?

    Read the article

  • Zantaz's EAS exchange archive product doesn't integrate with Outlook in Windows 7

    - by Chris Farmer
    I work at a place that uses Exchange with Outlook for mail, and they also use a product from Zantaz called "EAS" which does server-side archiving of old messages. One of the artifacts of this archival is that email attachments are missing from the archived messages when viewed in Outlook. EAS has a client tool that plugs into Outlook that enables easy retrieval of those archived messages and their attachments, but it doesn't seem to work when installed on Windows 7. I have no direct evidence of this, other than that it simply doesn't work on my Windows 7 machine, and some of our network support staff seem to corroborate this. The symptom is that Outlook seems to know nothing of the existence of this EAS app. The EAS app also has a system tray icon which is there and offers some minimal functionality, but the real goodness is the Outlook integration, which I sorely miss. So, my question is this: does anyone here know whether it's possible to coerce this EAS product into working correctly in Windows 7?

    Read the article

  • Installing PHP-GTK with PHP 5.3 on OS X

    - by Shabbyrobe
    I'm having trouble getting php-gtk installed with php 5.3 on os x. I'm currently using macports to do it and when I try to install php-gtk, it spews 'duplicate static' errors: Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_php_php5-gtk/work/php-gtk-2.0.1" && /usr/bin/make -j2 all " returned error 2 Command output: ext/gtk+/gen_pango.c:2951: error: duplicate 'static' ext/gtk+/gen_pango.c:2957: error: duplicate 'static' ext/gtk+/gen_pango.c:3097: error: duplicate 'static' ext/gtk+/gen_pango.c:3103: error: duplicate 'static' Is there a way to coerce it into building, or an alternative way to install it?

    Read the article

  • Best window manager for Linux for Virtual Desktop / Multimon

    - by mattcodes
    Previous used Ubuntu Gnome with Compiz but for my basic spec intel macbook (4 years old) its a little too heavyweight. So for now Im back on my macbook with os x, but now considering going back to Linux. Im looking for a window manager that has the following properties: 1) Supports virtual desktop (need 4 minimum) 2) Works well with multi monitors - can move an app with shortcut from one monitor to the other (on same virtual desktop) 3) Can remember window position (i.e. open vim on 2 monitor) - however must coerce everything back to first window when 2nd screen is unplugged 4) Keyboard shortcut friendly 5) Not too hard to install 6) Works well with minimum hardware such as integrated graphics Please suggest and share your experiences

    Read the article

  • Lightweight window manager for Linux for Virtual Desktop / Multimon

    - by mattcodes
    Previous used Ubuntu Gnome with Compiz but for my basic spec intel macbook (4 years old) its a little too heavyweight. So for now Im back on my macbook with os x, but now considering going back to Linux. Im looking for a window manager that has the following properties: Supports virtual desktop (need 4 minimum) Works well with multi monitors - can move an app with shortcut from one monitor to the other (on same virtual desktop) Can remember window position (i.e. open vim on 2 monitor) - however must coerce everything back to first screen when 2nd screen is unplugged Keyboard shortcut friendly Not too hard to install Works well with minimum hardware such as integrated graphics Please suggest and share your experiences

    Read the article

  • probability of trouble-free upgrade

    - by intuited
    One of the problems with recommending Ubuntu to potential future users, especially those not particularly given to technical endeavours, is that there is a chance that upgrades will break their machine, and they'll have to pay or otherwise coerce some knowledgeable person into fixing them. In my limited experience of running successive versions of Ubuntu since 8-something on a couple of different laptops, this chance is quite high. I'm not sure if I'm just unlucky with the hardware that I'm using, or if it's a result of the higher-than-average number of packages I have installed, or if upgrades are just typically problematic. So I'd like to know the likelihood, for a casual user, of doing a release upgrade, for example from 10.04 to 10.10, without experiencing any regression bugs. Obviously this is dependent on the hardware that people are running. Canonical seems to be making some efforts towards collecting data on this, for example with the "I am affected by this bug" checkbox on their issue tracker, and with the laptop compatibility reports, but I've not seen anything comprehensive. I'm hoping for an objective reference here, for example a study carried out by relatively unbiased individuals. However, anecdotal evidence is probably useful too.

    Read the article

  • 2d game view camera zoom, rotation & offset using 'Filter' / 'Shader' processing?

    - by Arthur Wulf White
    I wish to add the ability to zoom-in, zoom-out, rotate and move the view in a top-down view over a collection of points and lines in a large 2d map. I split the map into a grid so I only need to render the points that are 'near' the camera. My question is, how do I render a point A(Xp,Yp) assuming the following details: Offset of the camera pov from the origin of the map is: Xc, Yc Meaning the camera center is positioned on top of that point. If there's a point in Xc, Yc it is positioned in the center of the screen. The rotation angle is: alpha The scale is: S Read my answer first. I am thinking there is more optimized solution, thanks. My question is how to include the following improvement: I read in the AS3 Bible book that: In regards to ShaderInput, You can use these methods to coerce Pixel Bender to crunch huge sets of data masquerading as images, without doing too much work on the ActionScript side to make them look like images. Meaning if I am performing the same linear function on a lot of items, I can do it all at once if I use Shaders correctly and save processing time. Does anyone know how that is accomplished? Here is a sample of what I mean: http://wonderfl.net/c/eFp0/

    Read the article

  • Instantiating a System.Threading.Thread object in Jscript

    - by user297029
    I'm trying to create a new System.Threading.Thread object using Jscript, but I can't get the constructor to work. If I just do the following, var thread = new Thread( threadFunc ); function threadFunc() { // do stuff } then I get error JS1184: More than one constructor matches this argument list. However, if I try to coerce threadFunc to System.Threading.ThreadStart via var thread = new Thread( ThreadStart(threadFunc) ) I get error JS1208: The specified conversion or coercion is not possible Anyone know how to do this? It seems like it should be trivial.

    Read the article

  • compiling actionscript from command line using MXMLC

    - by I. J. Kennedy
    I have a tiny actionscript "project" consisting of two files, call them foo.as and bar.as. For reasons I won't go into, I really really want to build the .SWF from the command line, without setting up a formal project of any kind. Every compiler I've ever used lets you do this, but for the life of me I can't figure out how to coerce MXMLC into compiling these two files and linking them into a SWF. Naively, I try MXMLC foo.as bar.as but I'm informed that only one source file is allowed. Ok, supposing I compiled these two files separately, how would I link them together to get the final SWF? NOTE: The only reason I have two files instead of one is the requirement of only one class per file. I tried putting both classes in one file and making one of the classes "private" or "internal" but neither of these ideas worked. I would be ecstatic to find out I can put more than one class in a file (with only one being public).

    Read the article

  • Sharing output streams through a JNI interface

    - by Chris Conway
    I am writing a Java application that uses a C++ library through a JNI interface. The C++ library creates objects of type Foo, which are duly passed up through JNI to Java. Suppose the library has an output function void Foo::print(std::ostream &os) and I have a Java OutputStream out. How can I invoke Foo::print from Java so that the output appears on out? Is there any way to coerce the OutputStream to a std::ostream in the JNI layer? Can I capture the output in a buffer the JNI layer and then copy it into out?

    Read the article

  • Throwing exception vs returning null value with switch statement

    - by Greg
    So I have function that formats a date to coerce to given enum DateType{CURRENT, START, END} what would be the best way to handling return value with cases that use switch statement public static String format(Date date, DateType datetype) { ..validation checks switch(datetype){ case CURRENT:{ return getFormattedDate(date, "yyyy-MM-dd hh:mm:ss"); } ... default:throw new ("Something strange happend"); } } OR throw excpetion at the end public static String format(Date date, DateType datetype) { ..validation checks switch(datetype){ case CURRENT:{ return getFormattedDate(date, "yyyy-MM-dd hh:mm:ss"); } ... } //It will never reach here, just to make compiler happy throw new IllegalArgumentException("Something strange happend"); } OR return null public static String format(Date date, DateType datetype) { ..validation checks switch(datetype){ case CURRENT:{ return getFormattedDate(date, "yyyy-MM-dd hh:mm:ss"); } ... } return null; } What would be the best practice here ? Also all the enum values will be handled in the case statement

    Read the article

1 2  | Next Page >