search for: idiomatic

Displaying 20 results from an estimated 320 matches for "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, by = 1000)) { x[i:(i - 1 + 1000)] <- x[i:(i - 1 + 1000)] / divs[i %/% 1000 + 1] } Any suggestions are welcome. Thanks in advance, Andre
2007 Aug 23
4
Idiomatic way to do a non-database Enumeration?
...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. There are a lot of approaches, but I was wondering what the idiomatic Rails-y way of doing it is. Should I create a Weekday class? It wouldn''t be backed by the db - that''s not localizable or DRY... Any help appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Group...
2006 Feb 08
2
Idiomatic way to change partial''s behavior based on caller
...ass to the partial. I can see this working in two ways, A: leave the link_to call there, but replace the paramters with variables that the controller populate, or B: allow the controllers to specify what appears in the fourth <td/> entirely, which is in my mind preferred. What is the idiomatic way of doing this? Is A my only option, or can you think of a way to do B? Thanks in advance, as always! John -- Posted with http://DevLists.com. Sign up and save your time!
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
...39;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 params[:username] false else true end Rest of the code below... lib/util/render_error.rb: module RenderError def render_user_exists data render :partial => "shared/error",...
2006 Feb 19
0
looking for more idiomatic way of doing this
...<%= hidden_field_tag :id, @proposal.id%> <%= submit_tag "Vote For Proposal", ''class'' => "button" %> <%= end_form_tag %> <% end %> </div> This works but is kind of ugly. Wondering if anyone has any more rails-idiomatic way of doing this? b
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
...oing 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 doing it (but maybe I'm wrong and the real idiom for doing this is something different). The problem with this "idiomatic form" is that it is _very_ slow. The loop itself + the simple extraction of the rows (no computation on the rows) takes 10 hours on a powerful server (quad core Linux with 8G of RAM)! Looping over the first 100 rows takes 12 seconds: > system.time(for (key in row.names(dat)[1:100]) { ro...
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
...ould our >binding be named guestfs-sys? > So you've seen my RFC? =) Just to guestfs-sys would be a crate that does only two things: 1) exposes the C functions using `extern` 2) links to the library And then another crate (e.g. guestfs) would expose the higher-level, safe, hopefully idiomatic API. More information (reasoning etc.) see: https://doc.rust-lang.org/cargo/reference/build-scripts.html#a-sys-packages Martin >-- >Pino Toscano
2006 Apr 26
4
O/T: Good OSX Primer
...9;'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 to OSX to help the transition. Not so much a ''dummies'' guide on how to organize the family photos, but something outlining idiomatic usage for productivity-intensive use such as software development. Any tips? Thanks -- Posted via http://www.ruby-forum.com/.
2006 Mar 23
3
Newbie: ''find'' across multiple relationships
..._name ''Z'', ... end In other words, two different associations for the same type of model. Maybe the second collection is a habtm, etc. What is the best technique for doing a find on the union of those collections? I can think of a half dozen ways, but none of them seem ''idiomatic''. Thanks -- Posted via http://www.ruby-forum.com/.
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...
2012 Sep 11
2
R equivalent of python module structure and functionality?
...to.stdout.r that takes named arguments without undue pain. I would also like to be able to call it as a function from other scripts. How to do that in R? In case that's not specific enough :-) I know how to structure files/ modules in python like http://python.net/~goodger/projects/pycon/2007/idiomatic/cmdline.py (i.e., generically, http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#module-structure > """module docstring""" > > # imports > # constants > # exception classes > # interface functions > # classes > # internal f...
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 error: return -1. But a bigger issue seems to be how to pass back the corr...
2012 Aug 18
5
Quiz: How to get a "named column" from a data frame
...(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 "R-devel"): Consider this toy example, where the dataframe already has only one column : > nv <- c(a=1, d=17, e=101); nv a d e 1 17 101 > df <- as.data.frame(cbind(VAR = nv)); df VAR a 1 d 17 e 101 Now how, can I get 'nv' back from 'df...
2005 Dec 27
2
actions with no views?
...e 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