Search Results

Search found 332 results on 14 pages for 'baz'.

Page 6/14 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • Is it possible to distribute STDIN over parallel processes?

    - by Erik
    Given the following example input on STDIN: foo bar bar baz === qux bla === def zzz yyy Is it possible to split it on the delimiter (in this case '===') and feed it over stdin to a command running in parallel? So the example input above would result in 3 parallel processes (for example a command called do.sh) where each instance received a part of the data on STDIN, like this: do.sh (instance 1) receives this over STDIN: foo bar bar baz do.sh (instance 2) receives this over STDIN: qux bla do.sh (instance 3) receives this over STDIN: def zzz yyy I suppose something like this is possible using xargs or GNU parallel, but I do not know how.

    Read the article

  • Send instance method to module

    - by Matchu
    Given the following module, module Foo def bar :baz end end def send_to_foo(method) # ...? end send_to_foo(:bar) # => :baz What code should go in send_to_foo to make the last line work as expected? (send_to_foo is obviously not how I would implement this; it just makes clearer what I'm looking for.) I expected Foo.send(:bar) to work at first, but it makes sense that it doesn't. It would if the method were defined as def self.bar, but that's no fun.

    Read the article

  • Approaches for generic, compile-time safe lazy-load methods

    - by Aaronaught
    Suppose I have created a wrapper class like the following: public class Foo : IFoo { private readonly IFoo innerFoo; public Foo(IFoo innerFoo) { this.innerFoo = innerFoo; } public int? Bar { get; set; } public int? Baz { get; set; } } The idea here is that the innerFoo might wrap data-access methods or something similarly expensive, and I only want its GetBar and GetBaz methods to be invoked once. So I want to create another wrapper around it, which will save the values obtained on the first run. It's simple enough to do this, of course: int IFoo.GetBar() { if ((Bar == null) && (innerFoo != null)) Bar = innerFoo.GetBar(); return Bar ?? 0; } int IFoo.GetBaz() { if ((Baz == null) && (innerFoo != null)) Baz = innerFoo.GetBaz(); return Baz ?? 0; } But it gets pretty repetitive if I'm doing this with 10 different properties and 30 different wrappers. So I figured, hey, let's make this generic: T LazyLoad<T>(ref T prop, Func<IFoo, T> loader) { if ((prop == null) && (innerFoo != null)) prop = loader(innerFoo); return prop; } Which almost gets me where I want, but not quite, because you can't ref an auto-property (or any property at all). In other words, I can't write this: int IFoo.GetBar() { return LazyLoad(ref Bar, f => f.GetBar()); // <--- Won't compile } Instead, I'd have to change Bar to have an explicit backing field and write explicit getters and setters. Which is fine, except for the fact that I end up writing even more redundant code than I was writing in the first place. Then I considered the possibility of using expression trees: T LazyLoad<T>(Expression<Func<T>> propExpr, Func<IFoo, T> loader) { var memberExpression = propExpr.Body as MemberExpression; if (memberExpression != null) { // Use Reflection to inspect/set the property } } This plays nice with refactoring - it'll work great if I do this: return LazyLoad(f => f.Bar, f => f.GetBar()); But it's not actually safe, because someone less clever (i.e. myself in 3 days from now when I inevitably forget how this is implemented internally) could decide to write this instead: return LazyLoad(f => 3, f => f.GetBar()); Which is either going to crash or result in unexpected/undefined behaviour, depending on how defensively I write the LazyLoad method. So I don't really like this approach either, because it leads to the possibility of runtime errors which would have been prevented in the first attempt. It also relies on Reflection, which feels a little dirty here, even though this code is admittedly not performance-sensitive. Now I could also decide to go all-out and use DynamicProxy to do method interception and not have to write any code, and in fact I already do this in some applications. But this code is residing in a core library which many other assemblies depend on, and it seems horribly wrong to be introducing this kind of complexity at such a low level. Separating the interceptor-based implementation from the IFoo interface by putting it into its own assembly doesn't really help; the fact is that this very class is still going to be used all over the place, must be used, so this isn't one of those problems that could be trivially solved with a little DI magic. The last option I've already thought of would be to have a method like: T LazyLoad<T>(Func<T> getter, Action<T> setter, Func<IFoo, T> loader) { ... } This option is very "meh" as well - it avoids Reflection but is still error-prone, and it doesn't really reduce the repetition that much. It's almost as bad as having to write explicit getters and setters for each property. Maybe I'm just being incredibly nit-picky, but this application is still in its early stages, and it's going to grow substantially over time, and I really want to keep the code squeaky-clean. Bottom line: I'm at an impasse, looking for other ideas. Question: Is there any way to clean up the lazy-loading code at the top, such that the implementation will: Guarantee compile-time safety, like the ref version; Actually reduce the amount of code repetition, like the Expression version; and Not take on any significant additional dependencies? In other words, is there a way to do this just using regular C# language features and possibly a few small helper classes? Or am I just going to have to accept that there's a trade-off here and strike one of the above requirements from the list?

    Read the article

  • Converting delimited string to multiple values in mysql

    - by epo
    I have a mysql legacy table which contains an client identifier and a list of items, the latter as a comma-delimited string. E.g. "xyz001", "foo,bar,baz". This is legacy stuff and the user insists on being able to edit a comma delimited string. They now have a requirement for a report table with the above broken into separate rows, e.g. "xyz001", "foo" "xyz001", "bar" "xyz001", "baz" Breaking the string into substrings is easily doable and I have written a procedure to do this by creating a separate table, but that requires triggers to deal with deletes, updates and inserts. This query is required rarely (say once a month) but has to be absolutely up to date when it is run, so e.g. the overhead of triggers is not warranted and scheduled tasks to create the table might not be timely enough. Is there any way to write a function to return a table or a set so that I can join the identifier with the individual items on demand?

    Read the article

  • Java: why can't iterate over an iterator?

    - by noamtm
    I read http://stackoverflow.com/questions/839178/why-is-javas-iterator-not-an-iterable and http://stackoverflow.com/questions/27240/why-arent-enumerations-iterable, but I still don't understand why this: void foo(Iterator<X> it) { for (X x : it) { bar(x); baz(x); } } was not made possible. In other words, unless I'm missing something, the above could have been nice and valid syntactic sugar for: void foo(Iterator<X> it) { for (X x; it.hasNext();) { x = it.next(); bar(x); baz(x); } }

    Read the article

  • JAX-WS wsgen and collections of collections: wsgen broken?

    - by ayang
    I've been playing around with "bottom-up" JAX-WS and have come across something odd when running wsgen. If I have a service class that does something like: @WebService public class Foo { public ArrayList<Bar> getBarList(String baz) { ... } } then running wsgen gets me a FooService_schema1.xsd that has something like this: <xs:complexType name="getBarListResponse"> <xs:sequence> <xs:element name="return" type="tns:bar" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> which seems reasonable. However, if I want a collection of collections like: public BarCollection getBarCollection(String baz) { ... } // BarCollection is just a container for an ArrayList<Bar> then the generated schema ends up with stuff like: <xs:complexType name="barCollection"> <xs:sequence/> </xs:complexType> <xs:complexType name="getBookCollectionsResponse"> <xs:sequence> <xs:element name="return" type="tns:barCollection" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> An empty sequence is not what I had in mind at all. My original approach was to go with: public ArrayList<ArrayList<Bar>> getBarLists(String baz) { ... } but that ends up with a big chain of complexTypes that just wind up with an empty sequence at the end as well: <xs:complexType name="getBarListsResponse"> <xs:sequence> <xs:element name="return" type="tns:arrayList" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="arrayList"> <xs:complexContent> <xs:extension base="tns:abstractList"> <xs:sequence/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="abstractList" abstract="true"> <xs:complexContent> <xs:extension base="tns:abstractCollection"> <xs:sequence/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="abstractCollection" abstract="true"> <xs:sequence/> </xs:complexType> Am I missing something or is this a known hole in wsgen? JAXB? Andy

    Read the article

  • How to version control config files pragmatically?

    - by erenon
    Suppose we have a config file with sensitive passwords. I'd like to version control the whole project, including the config file as well, but I don't want to share my passwords. That could be good, if this config file: password=secret foo=bar becomes password=* foo=bar and the other users of the vcs could also set up the password on they own. To ignoring the file isn't a good approach, the developers should be aware, if the config file changes. Example: Local version: password=own_secret foo=bar config file in vcs: password=* foo=bar Then suddenly, the config file changes: password=* foo=bar baz=foo And the local version would become for each developer: password=own_secret foo=bar baz=foo This is my solution. How could I achieve this behaviour? How do you store your config files? Is there a way to do that, or should I hack something?

    Read the article

  • XSLT: How do I trigger a template when there is no input file?

    - by Ben Blank
    I'm creating a template which produces output based on a single string, passed via parameter, and does not use an input XML document. xsltproc seems to happily run with a single parameter specifying the stylesheet, but I don't see a way to trigger a template without an input file (no parameter to xsltproc to run a named template, for example). I'd like to be able to run: xsltproc --stringparam bar baz foo.xsl But I'm currently having to run, with the "main" template matching "/": echo '<xml/>' | xsltproc --stringparam bar baz foo.xsl - How can I get this to work? I'm sure I've seen other templates in the past which were meant to be run without an input document, but I don't remember how they worked or where to find them again. :-)

    Read the article

  • Preprocessor macros: how to insert arguments?

    - by mhambra
    Hi all, the code has a number of following sections: int filter; #ifdef INPUTFILTER_FOO LOG4CXX_DEBUG(log, "FOO filter used"); filter = F_FOO; #endif They are used multiple times in the code (used to provide I/O, threading support etc for all testing configurations), Circa they are essential for debugging but make the code look harsh, want to replace them with macros, one for each category_type namespace. So, want to expand the following: MACROSTUFFBAZ(log2, stuff, "BAZ") <- the text part is unique for each class, so it needs to be included in macro too. to: #ifdef INPUTSTUFF_BAZ LOG4CXX_DEBUG(log2, "BAZ stuff used"); stuff = S_BAZ; #endif To define macros, plan to use this: debug.hpp: #ifdef INPUTSTUFF_BAZ #define MACROSTUFFBAZ ... #else #define MACROSTUFFBAZ .. no code! #endif #endif (at least this will give a clear overview of the things currently undergoing probation, without seeing them around the code)

    Read the article

  • Is there a difference between Perl's shift versus assignment from @_ for subroutine parameters?

    - by cowgod
    Let us ignore for a moment Damian Conway's best practice of no more than three positional parameters for any given subroutine. Is there any difference between the two examples below in regards to performance or functionality? Using shift: sub do_something_fantastical { my $foo = shift; my $bar = shift; my $baz = shift; my $qux = shift; my $quux = shift; my $corge = shift; } Using @_: sub do_something_fantastical { my ($foo, $bar, $baz, $qux, $quux, $corge) = @_; } Provided that both examples are the same in terms of performance and functionality, what do people think about one format over the other? Obviously the example using @_ is fewer lines of code, but isn't it more legible to use shift as shown in the other example? Opinions with good reasoning are welcome.

    Read the article

  • Can I customize the indentation of ternary operators in emacs' cperl-mode?

    - by Ryan Thompson
    In emacs cperl-mode, ternary operators are not treated specially. If you break them over multiple lines, cperl-mode simply indents each line the same way it indents any continued statement, like this: $result = ($foo == $bar) ? 'result1' : ($foo == $baz) ? 'result2' : ($foo == $qux) ? 'result3' : ($foo == $quux) ? 'result4' : fail_result; This is not very readable. Is there some way that I can convince cperl-mode indent like this? $result = ($foo == $bar) ? 'result1' : ($foo == $baz) ? 'result2' : ($foo == $qux) ? 'result3' : ($foo == $quux) ? 'result4' : fail_result; By the way, code example from this question.

    Read the article

  • C: Incompatible types?

    - by Airjoe
    #include <stdlib.h> #include <stdio.h> struct foo{ int id; char *bar; char *baz[6]; }; int main(int argc, char **argv){ struct foo f; f.id=1; char *qux[6]; f.bar=argv[0]; f.baz=qux; // Marked line return 1; } This is just some test code so ignore that qux doesn't actually have anything useful in it. I'm getting an error on the marked line, incompatible types when assigning to type ‘char *[6]’ from type ‘char **’ but both of the variables are defined as char *[6] in the code. Any insight?

    Read the article

  • Simple string parsing with C++

    - by Andreas Brinck
    I've been using C++ for quite a long time now but nevertheless I tend to fall back on scanf when I have to parse simple text files. For example given a config like this (also assuming that the order of the fields could vary): foo: [3 4 5] baz: 3.0 I would write something like: char line[SOME_SIZE]; while (fgets(line, SOME_SIZE, file)) { int x, y, z; if (3 == sscanf(line, "foo: [%d %d %d]", &x, &y, &z)) { continue; } float w; if (1 == sscanf(line, "baz: %f", &w)) { continue; } } What's the most concise way to achieve this in C++? Whenever I try I end up with a lot of scaffolding code.

    Read the article

  • Forward web request for directory index ('/') to an index.htm page in JBoss 4.0.5

    - by The Pretender
    I am using JBoss 4.0.5.GA to run a set of java applications. One of them is a web frontend, using Spring 1.4. URL mappings are configured in a way that 'fake' pages from request URLs are mapped to controllers. That means that when someone requests /index.htm, there's no actual 'index.htm' on disk, and that request maps to a specific conroller which then renders a jsp view. So the problem is as follows: I need to tell JBoss to somehow forward all requests for directory indices to corresponding 'index.htm' URLs like so: / ? /index.htm; /news/ ? /news/index.htm; /foo/bar/baz/ ? /foo/bar/baz/index.htm and so on. I can't use Tomcat's welcome-file-list feature because it looks for those files on disk, while all 'index.htm's are fake and don't actually exist on disk.

    Read the article

  • How do I make a symlink to every directory in the current directory that has the same name but has u

    - by Jason Baker
    For instance, I suppose I have a directory that contains the following folders foo_bar baz What I would like to have is a bash command that will make a symlink foo-bar to foo_bar so it would look like this: foo-bar foo_bar baz I'm pretty sure I can write a Python script to do this, but I'm curious if there's a way to do this with bash. Here's where I'm stuck: ls -1 | grep _ | xargs -I {} ln -s {} `{} | sed 's/_/-/'` What I'm trying to do is run the command ln -s with the first argument being the directory name and the second argument being that name passed through sed s/_/-/. Is there another way to do this?

    Read the article

  • How do I convert an arbitrary list of strings to a SQL rowset?

    - by Jim Kiley
    I have a simple list of strings, which may be of arbitrary length. I'd like to be able to use this list of strings as I would use a rowset. The app in question is running against SQL Server. To be clearer, if I do SELECT 'foo', 'bar', 'baz' I get 'foo', 'bar', and 'baz' as fields in a single row. I'd like to see each one of them as a separate row. Is there a SQL (or SQLServer-specific) function or technique that I'm missing, or am I going to have to resort to writing a function in an external scripting language?

    Read the article

  • Question about C Pointers (just learning)

    - by Mike
    I am curious as to why this is an error and what the error message means. Here is some code. int *x[] = {"foo", "bar", "baz"}; int *y[] = {"foo", "bar", "baz"}; x = y; I try to compile and I get this: error: incompatible types when assigning to type ‘char [3]’ from type ‘char *’ Question #1 why is this an error? and Question #2 why are the types different? Thanks for you help.

    Read the article

  • Drupal: why can't user admin access my module pages?

    - by mmersz
    I am working on a drupal 6.x module which consists of several page as defined in the .module page. The problem is that when I visit those pages as admin, I get access denied. I thought that admin (user 1) could access anything? Here the code for some of the pages: function foobar_menu() { $items['admin/foobar'] = array( 'title' => 'administer foobar', 'page callback' => 'foobarpage', ); $items['admin/foobar/baz'] = array( 'title' => 'Do baz', 'page callback' => 'drupal_get_form', 'page arguments' =>array('foobarpage'), ); So how do I make sure that only admin can see these pages and the rest get a "page does not exists" error?

    Read the article

  • @Stateless, @Remote and @Local

    - by Jeff Foster
    In my deployment on JBoss 5.1.0GA with JavaEE-5 I have beans of the general form public interface Foo { void baz (); } @Stateless public class FooBean implements Foo { void baz() { // ... } } I have assumed that this is the same as if I have explicitly annotated the Foo interface with @Local. From seeing a stack trace in the code I think that it is actually using a remote interface, whereas I want all of my beans to be local. Do I need to explicitly annotate interfaces as Local or is there some default? Finding documentation on this is proving challenging so any links to relevant documentation would be greatly appreciated.

    Read the article

  • Mapping over multiple Seq in Scala

    - by bsdfish
    Suppose I have val foo : Seq[Double] = ... val bar : Seq[Double] = ... and I wish to produce a seq where the baz(i) = foo(i) + bar(i). One way I can think of to do this is val baz : Seq[Double] = (foo.toList zip bar.toList) map ((f: Double, b : Double) => f+b) However, this feels both ugly and inefficient -- I have to convert both seqs to lists (which explodes with lazy lists), create this temporary list of tuples, only to map over it and let it be GCed. Maybe streams solve the lazy problem, but in any case, this feels like unnecessarily ugly. In lisp, the map function would map over multiple sequences. I would write (mapcar (lambda (f b) (+ f b)) foo bar) And no temporary lists would get created anywhere. Is there a map-over-multiple-lists function in Scala, or is zip combined with destructuring really the 'right' way to do this?

    Read the article

  • Tabular.vim : how to align on the first occurrence of 2 different delimiters placed at the beginning of Words?

    - by ThG
    I have installed the Tabular plugin, which works very well for me, as long as there are no complicated regexes involved… But I have this list : one @abc @rstuvw &foo three @defg &bar four @mn @opq &kludge &hack twelve @hijkl &baz &quux I wish to align it that way (on @… first, then on &…) : one @abc @rstuvw &foo three @defg &bar four @mn @opq &kludge &hack twelve @hijkl &baz &quux which means I have 3 problems at the same time : align on the first occurrence of 2 different delimiters (@ and &) which are not really delimiters but "special characters" at the beginning of Words This is far beyond my understanding of both regexes and Tabular.vim How should I proceed ?

    Read the article

  • Converting delimited string to multiple values in mysql

    - by epo
    I have a mysql legacy table which contains an client identifier and a list of items, the latter as a comma-delimited string. E.g. "xyz001", "foo,bar,baz". This is legacy stuff and the user insists on being able to edit a comma delimited string. They now have a requirement for a report table with the above broken into separate rows, e.g. "xyz001", "foo" "xyz001", "bar" "xyz001", "baz" Breaking the string into substrings is easily doable and I have written a procedure to do this by creating a separate table, but that requires triggers to deal with deletes, updates and inserts. This query is required rarely (say once a month) but has to be absolutely up to date when it is run, so e.g. the overhead of triggers is not warranted and scheduled tasks to create the table might not be timely enough. Is there any way to write a function to return a table or a set so that I can join the identifier with the individual items on demand?

    Read the article

  • Replace strings differently depending if is enclosed in braces or not.

    - by peroyomas
    I want to replace all instances of an specific words between braces with something else, unless it is written between double braces, while it should show as is it was written with single braces without the filter. I have tried a code but only works for the first match. The rest are shown depending of the first one: $foo = 'a {bar} b {{bar}} c {bar} d'; $baz = 'Chile'; preg_match_all( '/(\{?)\{(tin)\}(\}?)/i', $foo, $matches, PREG_SET_ORDER ); if ( !empty($matches) ) { foreach ( (array) $matches as $match ) { if( empty($match[1]) && empty($match[3])) { $tull = str_replace( $match[0], $baz, $foo ); } else { $tull = str_replace( $match[0], substr($match[0], 1, -1), $foo ) ; } } } echo $tull;

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >