Hey,
Im sure I am missing something here but none the less.
foo['bar'] = nil
if(foo['bar'] == nil)
puts "foo bar is nil :("
However, nothing happens? Any thoughts?
Having those tables:
table_n1:
| t1_id | t1_name |
| 1 | foo |
table_n2:
| t2_id | t1_id | t2_name |
| 1 | 1 | bar |
I need a query that gives me two result:
| names |
| foo |
| foo / bar |
But i cant figure out the right way.
I wrote this one:
SELECT
CONCAT_WS(' / ', table_n1.t1_name, table_n2.t2_name) AS names
FROM
table_n1
LEFT JOIN table_n2 ON table_n2.t1_id = table_n1.t1_id
that works for an half: this only return the 2° row (in the example above):
| names |
| foo - bar |
This query return the 'father' (table_n1) name only when it doesnt have 'childs' (table_n2).
How can i fix it?
Hey guys,
I have a web service where people can edit their pages CSS, but I have a bar on the footer of that page that I want to make consistend on every page...
People are, right now, able to "remove" it with CSS and I really didn't want to go and parse the CSS to remove rules related to that bar... Is there a way to preserve the styles or re-aply them after load to keep the bar always visible?
Thanks in advanced!
I have a method foo
void foo (String x) { ... }
void foo (Integer x) { ... }
and I want to call it from a method which does not care about the argument:
void bar (Iterable i) {
...
for (Object x : i) foo(x); // this is the only time i is used
...
}
the code above complains that that foo(Object) is not defined and when I add
void foo (Object x) { throw new Exception; }
then bar(Iterable<String>) calls that instead of foo(String) and throws the exception.
How do I avoid having two textually identical definitions of bar(Iterable<String>) and bar(Iterable<Integer>)?
I thought I would be able to get away with something like
<T> void bar (Iterable<T> i) {
...
for (T x : i) foo(x); // this is the only time i is used
...
}
but then I get cannot find foo(T) error.
How do I override a class special method?
I want to be able to call the __str__() method of the class without creating an instance. Example:
class Foo:
def __str__(self):
return 'Bar'
class StaticFoo:
@staticmethod
def __str__():
return 'StaticBar'
class ClassFoo:
@classmethod
def __str__(cls):
return 'ClassBar'
if __name__ == '__main__':
print(Foo)
print(Foo())
print(StaticFoo)
print(StaticFoo())
print(ClassFoo)
print(ClassFoo())
produces:
<class '__main__.Foo'>
Bar
<class '__main__.StaticFoo'>
StaticBar
<class '__main__.ClassFoo'>
ClassBar
should be:
Bar
Bar
StaticBar
StaticBar
ClassBar
ClassBar
Even if I use the @staticmethod or @classmethod the __str__ is still using the built in python definition for __str__. It's only working when it's Foo().__str__() instead of Foo.__str__().
That title's a mouthful, isn't it?...
Here's what I'm trying to do:
public interface IBar {
void Bar();
}
public interface IFoo: IBar {
void Foo();
}
public class FooImpl: IFoo {
void IFoo.Foo() { /*works as expected*/ }
//void IFoo.Bar() { /*i'd like to do this, but it doesn't compile*/ }
void IBar.Bar() { /*works as expected*/ }
}
So... Is there a way to declare IFoo.Bar(){...} in my class, other than basically merging the two interfaces into one?
And, if not, why?
I'm upgrading some code to Java 5 and am clearly not understanding something with Generics. I have other classes which implement Comparable once, which I've been able to implement. But now I've got a class which, due to inheritance, ends up trying to implement Comparable for 2 types. Here's my situation:
I've got the following classes/interfaces:
interface Foo extends Comparable<Foo>
interface Bar extends Comparable<Bar>
abstract class BarDescription implements Bar
class FooBar extends BarDescription implements Foo
With this, I get the error 'interface Comparable cannot be implemented more than once with different arguments...'
Why can't I have a compareTo(Foo foo) implemented in FooBar, and also a compareTo(Bar) implemented in BarDescription? Isn't this simply method overloading?
Hi everyone ,
can anybody tell me why the following code doesn't work properly?
I want to play and stop an audio file.
I can do the playback but whenever I click the stop button nothing happens.
Here's the code :
Thank you.
..................
import java.io.*;
import javax.sound.sampled.*;
import javax.swing.*;
import java.awt.event.*;
public class SoundClipTest extends JFrame {
final JButton button1 = new JButton("Play");
final JButton button2 = new JButton("Stop");
int stopPlayback = 0;
// Constructor
public SoundClipTest() {
button1.setEnabled(true);
button2.setEnabled(false);
// button play
button1.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
button1.setEnabled(false);
button2.setEnabled(true);
play();
}// end actionPerformed
}// end ActionListener
);// end addActionListener()
// button stop
button2.addActionListener(
new ActionListener(){
public void actionPerformed(
ActionEvent e){
//Terminate playback before EOF
stopPlayback = 1;
}//end actionPerformed
}//end ActionListener
);//end addActionListener()
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Test Sound Clip");
this.setSize(300, 200);
JToolBar bar = new JToolBar();
bar.add(button1);
bar.add(button2);
bar.setOrientation(JToolBar.VERTICAL);
add("North", bar);
add("West", bar);
setVisible(true);
}
void play() {
try {
final File inputAudio = new File("first.wav");
// First, we get the format of the input file
final AudioFileFormat.Type fileType = AudioSystem.getAudioFileFormat(inputAudio).getType();
// Then, we get a clip for playing the audio.
final Clip c = AudioSystem.getClip();
// We get a stream for playing the input file.
AudioInputStream ais = AudioSystem.getAudioInputStream(inputAudio);
// We use the clip to open (but not start) the input stream
c.open(ais);
// We get the format of the audio codec (not the file format we got above)
final AudioFormat audioFormat = ais.getFormat();
c.start();
if (stopPlayback == 1 ) {c.stop();}
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}// end play
public static void main(String[] args) {
//new SoundClipTest().play();
new SoundClipTest();
}
}
What's the best/canonical way to define a function with optional named arguments? To make it concrete, let's create a function foo with named arguments a, b, and c, which default to 1, 2, and 3, respectively. For comparison, here's a version of foo with positional arguments:
foo[a_:1, b_:2, c_:3] := bar[a,b,c]
Here is sample input and output for the named-arguments version of foo:
foo[] --> bar[1,2,3]
foo[b->7] --> bar[1,7,3]
foo[a->6, b->7, c->8] --> bar[6,7,8]
It should of course also be easy to have positional arguments before the named arguments.
Is there a way to force a Bar Chart legend in Crystal Report 11.5 to display its objects in a particular order?
For Example, say I am reporting on the consumption of "Bananas" and "Apples" by State. The Bar Chart should display the percentage of people who eat these fruits by county (Percent Bar Chart). The "Apples" percentage always displays on top of the bar chart and the "Bananas" on the bottom. The legend for this graph also displays the "Apple" color first, then the "Banana" color. However, if the "Banana" percentage is 0% the legend displays the "Banana" color first on the legend. This creates a inconsistent report (with plenty of complaints).
I would like the "Banana" color to always display second in the legend. Hope I didn't confuse anyone and any ideas would be helpful.
I've never really been a big fan of the way most editors handle namespaces. They always force you to add an extra pointless level of indentation.
For instance, I have a lot of code in a page that I would much rather prefer formatted as
namespace mycode{
class myclass{
void function(){
foo();
}
void foo(){
bar();
}
void bar(){
//code..
}
}
}
and not something like
namespace mycode{
class myclass{
void function(){
foo();
}
void foo(){
bar();
}
void bar(){
//code..
}
}
}
Honestly, I don't really even like the class thing being indented most of the time because I usually only have 1 class per file. And it doesn't look as bad here, but when you get a ton of code and lot of scopes, you can easily have indentation that forces you off the screen, and plus here I just used 2-space tabs and not 4-space as is used by us.
Anyway, is there some way to get Visual Studio to stop trying to indent namespaces for me like that?
I have a variable that stores a Unix path, for example:
typeset unixpath=/foo/bar/
And I have to convert it to a DOS path using Korn shell scripting:
dospath=\\foo\\bar\\
I've noticed a curious phenomena popping up in my error logs recently. If, as the result of processing a form, I redirect my users to the URL http://www.example.com/index.php?foo=bar&bar=baz, I will see the following two URLs in my log
http://www.example.com/index.php?foo=barbar=baz
http://www.example.com/index.php?foo=bar&bar=baz
The first one is obviously incorrect and will cause my application to redirect to a 404. It always appears first, usually a second before the second one. The 404 page is not doing the redirection, so it appears that the browser is trying both versions. At first, looking at my server logs made me believe it affected only Firefox 3.6.3, but I've found an example of Safari being afflicted as well. It happens fairly intermittently, though it can occur multiple times in a users' session. I've never been able to get it to happen to me.
Any thoughts as to the nature of the problem or a solution?
I'm trying to debug a C++ program compiled with GCC that freezes at startup. GCC mutex protects function's static local variables, and it appears that waiting to acquire such a lock is why it freezes. How this happens is rather confusing. First module A's static initialization occurs (there are __static_init functions GCC invokes that are visible in the backtrace), which calls a function Foo(), that has a static local variable. The static local variable is an object who's constructor calls through several layers of functions, then suddenly the backtrace has a few ??'s, and then it's is in the static initialization of a second module B (the __static functions occur all over again), which then calls Foo(), but since Foo() never returned the first time the mutex on the local static variable is still set, and it locks.
How can one static init trigger another? My first theory was shared libraries -- that module A would be calling some function in module B that would cause module B to load, thus triggering B's static init, but that doesn't appear to be the case. Module A doesn't use module B at all. So I have a second (and horrifying) guess. Say that:
Module A uses some templated function or a function in a templated class, e.g. foo<int>::bar()
Module B also uses foo<int>::bar()
Module A doesn't depend on module B at all
At link time, the linker has two instances of foo<int>::bar(), but this is OK because template functions are marked as weak symbols...
At runtime, module A calls foo<int>::bar, and the static init of module B is triggered, even though module B doesn't depend on module A! Why? Because the linker decided to go with module B's instance of foo::bar instead of module A's instance at link time.
Is this particular scenario valid? Or should one module's static init never trigger static init in another module?
Hi,To get the child items as string i used the following code
private void treeview1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (treeview1.SelectedItem != null)
{
Animal bar = (Animal)treeview1.SelectedItem;
string str = bar.Name;
int boxty = bar.BoxType;
int boxno = bar.BoxNo;
}
}
It works fine .But when i click on parent(instead of + sign),it goes to this code and shows error.Ofcourse im casting SelectedItem to my List-Animal.
But i dont want this.I have to check,whether the clciked item is parent,if it is so then i will skip this coding.Only when i click the child items it will go to this coding.
How can i do that?How can i identify the selected item is parent.
I need a sparse table which contains a set of "override" values for
another table. I also need to specify the default value for the
items overridden.
For example, if the default value is 17, then foo,bar,baz will have
the values 17,21,17:
table "things" table "xvalue"
name stuff name xval
---- ----- ---- ----
foo ... bar 21
bar ...
baz ...
If I don't care about a FK from xvalue.name - things.name, I could simply
put a "DEFAULT" name:
table "xvalue"
name xval
---- ----
DEFAULT 17
bar 21
But I like having a FK. I could have a separate default table, but it
seems odd to have 2x the number of tables.
table "xvalue_default"
xval
----
17
table "xvalue"
name xval
---- ----
bar 21
I could have a "defaults table"
tablename attributename defaultvalue
xvalue xval 17
but then I run into type issues on defaultvalue.
My operations guys prefer as compact a representation as possible,
so they can most easily see the "diff" or deviations from the
default.
What's the best way to represent this, including the default value? This will be for Oracle 10.2 if that makes a difference.
Is there a way to get a class that extends AbstractTransactionalJUnit4SpringContexts to play nicely with JUnit's own @RunWith(Parameterized), so that fields marked as Autowired get wired in properly?
@RunWith(Parameterized)
public class Foo extends AbstractTransactionalJUnit4SpringContexts {
@Autowired private Bar bar
@Parameters public static Collection data() {
// return parameters, following pattern in
// http://junit.org/apidocs/org/junit/runners/Parameterized.html
}
@Test public void someTest(){
bar.baz() //NullPointerException
}
}
Imagine a base class with many constructors and a virtual method
public class Foo
{
...
public Foo() {...}
public Foo(int i) {...}
...
public virtual void SomethingElse() {...}
...
}
and now I want to create a descendant class that overrides the virtual method:
public class Bar : Foo
{
public override void SomethingElse() {...}
}
And another descendant that does some more stuff:
public class Bah : Bar
{
public void DoMoreStuff() {...}
}
Do I really have to copy all constructors from Foo into Bar and Bah? And then if I change a constructor signature in Foo, do I have to update it in Bar and Bah?
Is there no way to inherit constructors? Is there no way to encourage code reuse?
I have string as:
FOO /some/%string-in.here BAR
I would like to get everything between FOO and BAR but NOT including FOO[:space:] and NOT including [:space:]BAR
Any ideas it will be appreciate it.
Hi all,
I want to set position of keyboard when it appears. Can i set this using any API?
I didn't want to use private API for that. Actually I want to display tab bar which is place d at bottom of screen.When keyboard appears then it hide the tab bar.So i want to set keyboard position at top of tab bar.
Thanks in Advance.
This question already addresses how to remove duplicate lines, but enforces that the list is sorted first.
I would like to perform the remove contiguous duplicate lines step (i.e. uniq) without first sorting them.
Example before:
Foo
Foo
Bar
Bar
Example after:
Foo
Bar
Hi,
To begin with, I'm not even sure, if it is the right way to do it.
Let's say, i have script (jquery included) like this:
foo = function() {
this.bar = function() {
alert('I\'m bar');
}
this.test = function() {
$('body').append('<a onclick="my_var.bar();">Click me</a>');
}
this.test();
}
var my_var = new foo();
Is there any way, i could make variable "my_var" dynamic inside function "foo".
So I could do something like
$('body').append('<a onclick="'+the_variable_which_im_assigned_to+'.bar();">Click me</a>');
Thank you
Hello everybody
I want to send emails with formatted sender such as "Support team [email protected]".
If delivery method I wrote from "support team <[email protected]>" and from "\"support team\" <[email protected]>" but smtp server says
#: "@" or "." expected after "test"
This means that rails puts full "from" string into braces. How can I fix this without monkeypatching?
I'm in the process of implementing an ultra-light MVC framework in PHP. It seems to be a common opinion that the loading of data from a database, file etc. should be independent of the Model, and I agree. What I'm unsure of is the best way to link this "data layer" into MVC.
Datastore interacts with Model
//controller
public function update()
{
$model = $this->loadModel('foo');
$data = $this->loadDataStore('foo', $model);
$data->loadBar(9); //loads data and populates Model
$model->setBar('bar');
$data->save(); //reads data from Model and saves
}
Controller mediates between Model and Datastore
Seems a bit verbose and requires the model to know that a datastore exists.
//controller
public function update()
{
$model = $this->loadModel('foo');
$data = $this->loadDataStore('foo');
$model->setDataStore($data);
$model->getDataStore->loadBar(9); //loads data and populates Model
$model->setBar('bar');
$model->getDataStore->save(); //reads data from Model and saves
}
Datastore extends Model
What happens if we want to save a Model extending a database datastore to a flatfile datastore?
//controller
public function update()
{
$model = $this->loadHybrid('foo'); //get_class == Datastore_Database
$model->loadBar(9); //loads data and populates
$model->setBar('bar');
$model->save(); //saves
}
Model extends datastore
This allows for Model portability, but it seems wrong to extend like this. Further, the datastore cannot make use of any of the Model's methods.
//controller extends model
public function update()
{
$model = $this->loadHybrid('foo'); //get_class == Model
$model->loadBar(9); //loads data and populates
$model->setBar('bar');
$model->save(); //saves
}
EDIT: Model communicates with DAO
//model
public function __construct($dao)
{
$this->dao = $dao;
}
//model
public function setBar($bar)
{
//a bunch of business logic goes here
$this->dao->setBar($bar);
}
//controller
public function update()
{
$model = $this->loadModel('foo');
$model->setBar('baz');
$model->save();
}
Any input on the "best" option - or alternative - is most appreciated.