search for: idiomatical

Displaying 20 results from an estimated 320 matches for "idiomatical".

Did you mean: idiomatic
2010 May 04
3
Idiomatic looping over list name, value pairs in R
Considering the python code: for k, v in d.items(): do_something(k); do_something_else(v) I have the following for R: for (i in c(1:length(d))) { do_something(names(d[i])); do_something_else(d[[i]]) } This does not seem seems idiomatic. What is the best way of doing the same with R? Thanks. Luis
2008 Feb 25
4
A more idiomatic way to write this
Hello, I have a vector of 1,000,000 numbers and another vector of 1,000 divisors. What I'd like to do is to divide the first 1,000 numbers of the first vector by the first divisor, then the next 1,000 by the second divisor and so on. I came up with this, but I was wondering if there is a more idiomatic, R-like way to write it: x <- ... divs <- ... for (i in seq(from = 1, to = 1000000,
2007 Aug 23
4
Idiomatic way to do a non-database Enumeration?
I have a class which stores as one of its attributes a day of the week as an integer (0-6, 0=Sunday, standard UNIXy values). I want, obviously, the views to show the weekday name and the forms to provide a drop-down with the weekday names. Essentially it''s a vrtual attribute whose value is the localized weekday name, which maps to the integer value that''s actually stored.
2006 Feb 08
2
Idiomatic way to change partial''s behavior based on caller
Guys, I have a partial that is shared by many controllers, and this partial has a link that needs to do different things based on which controller calls it. So, the partial looks like this: <!-- _part.rhtml --> <tr> <td><%=part.number%></td> <td><%=part.associated_part_number%></td> <td><%=part.drawings%></td>
2011 Aug 20
4
[PATCH 1/2] Make xencommons a bit more idiomatic
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com> diff -r 8d6edc3d26d2 -r cfb49fe940fd tools/hotplug/Linux/init.d/xencommons --- a/tools/hotplug/Linux/init.d/xencommons Sat Aug 13 10:14:58 2011 +0100 +++ b/tools/hotplug/Linux/init.d/xencommons Tue Aug 16 16:56:16 2011 -0700 @@ -29,11 +29,9 @@ XENCONSOLED_PIDFILE=/var/run/xenconsoled.pid shopt -s extglob -if test
2006 Jun 27
0
More idiomatic way of doing this
Folks, I''m trying to write a validating filter that checks if the user exists and renders XML if not. Most of the controllers will be returning XML on some error or other so I''m including RenderError in ApplicationController. Is my approach a sound one? Also, is there a shorter and more idiomatic way of writing this: if @user.nil? render_user_exists
2006 Feb 19
0
looking for more idiomatic way of doing this
I have proposals and members can vote for them. In my proposal view I have a little div where the currently logged in member can vote: <div id="vote_div" class="vote"> Your vote: <% if @member_vote %> You have voted for this proposal<br /> <%= start_form_tag :action => "delete_vote" %> <%= hidden_field_tag :id,
2006 Jun 30
4
More idiomatic way of writing a filter
Is there a more elegant way of writing this? def verify_user @user = User.find_by_username params[:username] if @user.nil? message = xml.error do |xm| xm.message "User does not exists: #{params[:username]}" end render :xml => message return false else true end end Thanks, Joel --
2007 Mar 02
5
extracting rows from a data frame by looping over the row names: performance issues
Hi, I have a big data frame: > mat <- matrix(rep(paste(letters, collapse=""), 5*300000), ncol=5) > dat <- as.data.frame(mat) and I need to do some computation on each row. Currently I'm doing this: > for (key in row.names(dat)) { row <- dat[key, ]; ... do some computation on row... } which could probably considered a very natural (and R'ish) way of
2020 Feb 19
1
[PATCH] golang: make API idiomatic so that functions return (<val>, error)
Go API functions returned (<val>, *GuestfsError) that made code like this fail to build: n, err := os.Stdin.Read(buf) if err != nil { log.Fatal(err) } n, err = g.Pwrite_device(dev, buf[:n], off) ... As err should be of error (interface) type as of the stdlib call, and should be of *GuestfsError type as of the libguestfs call. The concrete error value that
2019 Jul 08
2
Re: [PATCH] Add Rust bindings
On Mon, Jul 08, 2019 at 10:10:10AM +0200, Pino Toscano wrote: >On Saturday, 6 July 2019 13:03:24 CEST Martin Kletzander wrote: >> Just one thing, the Cargo.toml includes a version under which the crate would be >> published. I presume the version would be the same as the one of the project >> itself, i.e. when releasing libguestfs-x.y.z, we publish guestfs-rs-x.y.z to
2006 Apr 26
4
O/T: Good OSX Primer
A bit off topic, but I know there are a lot of smart Mac evangelists on the list so I thought I''d pose the question here. I made the switch to OS X after Apple moved to the x86 platform. Now that VMWare can be ported to OS X, it''s a practical platform for me. I''m an ex *nix admin, so I ''get the drift''; however, I''m looking for a good guide
2006 Mar 23
3
Newbie: ''find'' across multiple relationships
For security purposes, I often want to find objects that are ''visible''. e.g. class Person < ActiveRecord::Base has_many :x end ... @person.x.find(params[:id]) as opposed to X.find([params[:id]). Simple enough for me. My question: Say we have - class Person < ActiveRecord::Base has_many :x, :class_name ''Z'', .... has_many :y, :class_name
2006 Jul 15
3
How bad is it to have 7 joins in my find_by_sql?
My question is whether there''s a more idiomatic rails way of structuring this query or of redoing the underlying models. First, the ugly find_by_sql code, which is the method to generate an atom feed: def atom items_per_feed = 15 sql_query = "SELECT activities.*, users.real_name AS real_name, accounts.last_scraped_at AS last_scraped_at,
2012 Sep 11
2
R equivalent of python module structure and functionality?
summary: how to structure an R file such that it can be both 1. used as a script via, e.g., (from OS commandline) $ Rscript foo.r bar=baz 2. imported and called as a function via, e.g. (from R commandline) > source('./foo.r) > foo(bar='baz') ? I'm looking for the 'R equivalent' of how python supports this usecase. details: As discussed in the thread beginning
2018 Jun 28
1
[nbdkit PATCH] main: More idiomatic use of getopt_long
Prefer named constants over magic numbers in the 'struct option' list, and expand the list of enums for long-only options so that the call to getopt_long() can switch directly to every option, rather than needing a lengthy if/else chain that grows for every new long option. Patch best viewed with whitespace changes ignored. Signed-off-by: Eric Blake <eblake@redhat.com> ---
2009 Nov 27
3
Iteration idioms & laziness
Hi all, I'm new to R. Having a functional background, I was wondering what's the idiomatic way to iterate. It seems that for loops are the default given there's no tail-call optimization. I'm curious to know whether there is a way to transform the following toy snippet into something that doesn't eat up gigabytes of memory (like it's for loop counterpart) using laziness:
2020 Jun 06
2
[nbdkit] About the Rust bindings
[To continue the conversation from https://github.com/libguestfs/nbdkit/issues/5] > Currently there's no way for the Rust plugin to report an error. The > idiomatic way to do it would be for each callback to return a Result > object, much like how the Go plugin currently does it. I'm sure it's not idiomatic for Rust, but I just wanted to say that there is a way to return an
2012 Aug 18
5
Quiz: How to get a "named column" from a data frame
Today, I was looking for an elegant (and efficient) way to get a named (atomic) vector by selecting one column of a data frame. Of course, the vector names must be the rownames of the data frame. Ok, here is the quiz, I know one quite "cute"/"slick" answer, but was wondering if there are obvious better ones, and also if this should not become more idiomatic (hence
2005 Dec 27
2
actions with no views?
In Depot, the demo application in the the Agile book, actions that modify the model such as add_to_cart redirect to another action that has a clear view role, like index, or show_cart, instead of generating the view themselves. This uses an HTTP redirect that goes to the client and returns. Is this an idiomatic way to design the flow in Rails? -- fxn