Thursday, 3 October 2013

How do I create a Java Package and Test it Using Vim in Linux

How do I create a Java Package and Test it Using Vim in Linux

I know how to create a java package, write code in the /src folder and
test it from the /tst folder. But, I want to learn how I can do that
without Eclipse, just using Vim.
For example, I have a java Hello World Class:
class HelloWorld {
public void disp() {
System.out.println("Hello World");
}
}
I save this in a directory home/javacode/HelloWorld
Now, I write a test for it in the same folder :
import org.junit.*;
class HelloWorldTest extends HelloWorld {
@Test testHelloWorld() {
HelloWorld hello = new HelloWorld();
hello.disp();
}
}
Now, can someone please help me as to how to get this test to run? As in I
have to compile Hello World as :
javac HelloWorld.java
and then compile the test as :
javac -cp "path to junit" HelloWorldTest.java
However, I always end up with a ClassPath error. I understand that I am
really messing up something very fundamental here. Please do help me out
with this!

Wednesday, 2 October 2013

How to access var data from javascript and put into form value

How to access var data from javascript and put into form value

I've been using http://jscolor.com/ but I'm not getting one thing How can
i take out the value of the color and paste it to value area in the form
I tried to put the script there but didn't work. How can i get +this.color
into value area ?
<input value=""
onchange="document.getElementsByTagName('BODY')[0].style.backgroundColor =
'#'+this.color">

Better way to restrict object to certain attributes

Better way to restrict object to certain attributes

Suppose I have an object:
obj =
foo: 'foo'
bar: 'bar'
... and lots of other stuff ...
... these values vary, and are not actually hard coded ...
I'd like to create a copy of that object which contains only a subset of
its attributes.
obj2 =
foo: obj.foo
bar: obj.bar
// *doesn't* copy any other attributes from `obj`
Is there a more idiomatic way of doing this? Something like
obj2 = copy_only obj, ['foo', 'bar']
I mean, sure, I could write copy_only myself, but I'm looking for the
idiomatic way to do this, not the home baked way. Is there such an idiom
that you can recommend for this scenario?

Cascalog deffilterop vs pure clojure

Cascalog deffilterop vs pure clojure

Is there a difference, performance or otherwise, between using a
deffilterop and using a purse clojure function?
http://nathanmarz.com/blog/introducing-cascalog-a-clojure-based-query-language-for-hado.html
mentions that filtering can be done with clojure functions like (< ?age2
?age1) however looking at
https://github.com/nathanmarz/cascalog/wiki/Guide-to-custom-operations it
looks like you can define a function like (deffilterop is-2? [x] (= x 2)).
So my question is, is there any difference between these two approaches
and if not which is the preferred syntax?
Note: It also looks like all of the defxxxop functions are being
deprecated for defxxxfn instead.
https://github.com/nathanmarz/cascalog/blob/develop/cascalog-core/src/clj/cascalog/logic/def.clj#L131

HTML Form $_POST wont owrk

HTML Form $_POST wont owrk

menus.php
<?php
$con=mysqli_connect("localhost","root","","mmogezgini");
$menuler = mysqli_query($con,"SELECT * FROM menuler");
while($menu = mysqli_fetch_array($menuler)) {
$isim = $menu["isim"];
$url = $menu["url"];
?>
<form method="post">Menü Ýsmi :<input name="menu_isim" value="<?php echo
$isim; ?>" disabled> | Menü URL : <input name="menu_url" value="<?php echo
$url;?>"disabled> <button type="submit" formmethod="post"
formaction="menu_duzenle.php">Düzenle</button> <button
formaction="menu_sil.php">Sil</button></form><br>
<?php
}
?>
edit_menu.php
<form method="post" action="menu_duzenle_islem.php">
Þuanki Ýsim : <input name="menu_isim" value="<?php echo
$_POST['menu_isim'] ?>"disabled>
Yeni Ýsim : <input name="yeni_menu_isim" placeholder="yeni menü ismini
giriniz.">
</form>
My Problem is form in menus.php wont send $_POST['menu_isim'] to
edit_menu.php

Tuesday, 1 October 2013

Qt signals and slots: permissions

Qt signals and slots: permissions

There are discrepancies between respected answers here on SO and the
actual Qt docs.
I've read this question and I want some further clarification. Can anyone
confirm:
A signal is always protected, therefore it can be emitted only by the
class or any of its subclasses. I'm not sure this is true; the question
above shows answers supporting this statement. But the Qt docs say:
Signals are public access functions and can be emitted from anywhere, but
we recommend to only emit them from the class that defines the signal and
its subclasses. So which is it?
The words public, private, protected have no use with working with the
signal keyword
The emitted signal is always available to all other classes, that is, any
other class may always connect to that signal (but not emit it).
Despite that all signals are viewable to by all classes, you could still
have two classes with signals of the same name since the connect function
takes the class name as a signal prefix (i.e. SomeClass::itsSignal)
Slots are just functions, and thus may be public, private or protected.
Obviously an outside class will have the ability to control if your class
connects one of its own signals to one of its own slots if the slot is
public. However, again the SO information differs from the docs, which
say: a signal emitted from an instance of an arbitrary class can cause a
private slot to be invoked in an instance of an unrelated class. This
means that private is not honored by the signal/slot mechanism?

How do you sort a collection by distant relationships?

How do you sort a collection by distant relationships?

I have a tree-like relationship model with a fixed depth, and each level
has a code attribute - similar to this;
class Category < ActiveRecord::Base
has_many :sub_categories
default_scope order(:code)
end
class SubCategory < ActiveRecord::Base
belongs_to :category
has_many :items
def self.sorted
self.joins(:category).order('"categories".code ASC,
"sub_categories".code')
end
end
class Item < ActiveRecord::Base
belongs_to :sub_category
def self.sorted
# what goes here?
end
end
Category.all gets all the the categories ordered by categories.code.
SubCategory.sorted gets all the sub_categories ordered by categories.code,
sub_categories.code. I used this approach because default_scope :
joins(:categories).order('categories.code, sub_categories.code') makes
.find return read-only records.
I would like to call Items.sorted and get the all items ordered by
categories.code, sub_categories.code, items.code but I can't figure out
how. I imagine I need a second .joins, but I don't have a relationship
name to supply.