If you have a single (or some more) question regarding any of the tech topics of this board and feel that it wouldn't justify creating an own thread just for that, feel free to post it in here.
If you know the answer to any of the questions in this thread, please help us out here! I am sure it's going to be appreciated.
(We need one of these threads here, kopipe from tech)
Java Swing question
Sometimes the components I add turn out to small when displayed. To fix this, I've been hardcoding the components sizes. For example:
JList test = new JList(data);
test.setPreferredSize(new Dimension(800,600));
However, I hate to do this. I don't want to force the user into a single window size. Is there a way to say "use 80% of window" or use (window size - 80 pixels)?
To the JList Question:
Whenever I worked with Swing, I tended to figure out what a good size would be for the application, set those in some static variables, then do random percentages or subtractions for the paddings and things when working.
You should be able to poll back up to a parent for the (window size - # pixels). You should also be able to poll the JavaVM for some sort of desktop size (in Windows, atleast), figure out a good window size from that with some simple math inside function calls.
However, it has been awhile since I did Java Swing, and even then, I didn't do much work with it. I found it way too cludgy.
Yes. I'm big for console apps.
Viva la console!
Speaking of console apps (or: a programming-related question):
Does something like a tabbed console/terminal emulator exist for Windows?
Basically I am looking for a Konsole-clone (and no, kde-cygwin is not an option).
Perhaps by using a windowmanager that support having applications in tabs? (like fluxbox)
Um, if X window managers can run on Windows (the Microsoft OS, I assume), then that would be news to me.
There is a port of blackbox to Windows, fluxbox isn't far from blackbox, so why not?
>>7
i ran openbox on cygwin for a while... i tried compiling fluxbox once, but it didn't work and i didn't care enough to try to figure out what was wrong...
I've just run on the need of a hash function with a peculiar property: f(A,B,C) = f(B,A,C); IOW, the function should return the same result if two of its parameters are swapped (all parameters are integers).
For example, I could simply do A XOR B then hash it with C, this would give the expected result, but wouldn't give a good hashing result, since it is easly exploitable: f(0x01,0x20,C) = f(0x00,0x21,C).
I need this for classifying network streams: it doesn't matter if a given packet cames from host A to host B or vice-versa, the connection is the same. Does someone have a suggestion?
Can't you swap values before hashing? Adopt a policy that lowest host comes first.
Which I guess is what >>12 suggested already...
Yes, adopting the lowest one first is a really quick'n dirty solution. It worked, thanks!
Quick, sure, but I wouldn't call it dirty. I'm pretty sure that's mathematically equivalent to whatever other solution one might think up.
Here's one for JavaScript fans... How can I put the result of a POSTed form in a new window?
What specifically I want to do is add a feature to Thorn that lets one preview the mark-up of their post. For this, only the body part of the form needs to be posted, so we can avoid having to upload files to do this. I think I can figure out how to just submit one part of the form, but how to get the result of that submission into a new pop-up window (or maybe an inline frame?) eludes me.
Please keep in mind I'm a JavaScript toddler, so speak slowly and use small words. TIA for any help.
iirc you don't need javascript for that. just stick a target of _blank in either the form tag or the submit button in your html. been a while since i've had a use for this though, so i may have misremembered.
_blank isn't valid XHTML, if I recall correctly, so I'd like to avoid that. Either way, that doesn't work as far as avoiding sending uploaded files.
If you want to avoid sending files, what you need to do is manually read the values out of the form, and then either (Web2.0 lol) use XMLHttpRequest to make a request to the server, and then display the results (this way, you don't even need to use any iframes at all - you can just stuff the results into some <div>'s innerHTML), or fill the values into a hidden frame, that you then submit().
Hmm. I looked into XMLHttpRequest… it's actually easier to use than I thought it would be. Interesting. I've got something working now; thanks.
Compatibility warnings for XMLHttpRequest: IE has its own way to instatiate it (two of them, actually). That's probably mentioned at any page about it, though. Less obvious is the fact that Opera's implementation is pretty broken, and won't let you set headers. So POST requests might not work right in Opera.
Also, properly escaping form data is a pain in the ass, especially if you might have non-ASCII data in the form. See for instance http://xkr.us/articles/javascript/encode-compare/. I think encodeURIComponent()
is the one you want, but I recall having some trouble with that and charsets, too. Mostly it should work, though.
Apple have some very good cross-browser XMLHttpRequest documentation:
http://developer.apple.com/internet/webcontent/xmlhttpreq.html
All right, I just spent about an hour and a half trying to get it to work on IE too, with no success. Aside from the code at Apple's site, I'm also trying what's at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmobjxmlhttprequest.asp too, but to no avail. Since I'm on a Mac, I have to try to get PC users to help me out via IM or IRC... It's a pain. Giving it up for now.
From what I've found, it looks like xyz = new ActiveXObject("MSXML2.XMLHTTP.3.0");
works, but then
if (xyz==false) {
...
}
else {
...
}
causes nothing to happen for some reason.
Fucking WinIE. Giving up for now.
Don't quote me on this, but possibly your problem is that false != null
. Just use if(!xyz)
.
A good thought, but here's the full code. The relevant part is the preview()
function.
http://pichan.org/pc/tpl/WakaWakaWaka/js.js
I don't see anywhere where xyz
could be set to anything other than a (hopefully functioning) ActiveXObject, or false
.
Here's the code I use to get an XMLHttpRequest:
function get_xmlhttp()
{
var xmlhttp;
try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e1)
{
try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e1) { xmlhttp=null; }
}
if(!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
return(xmlhttp);
}
It's based on code off this or that web page, with some editing to make it more concise. It seems to work in most browsers.
Well, I don't quite like the order of that; as XMLHttpRequest is the correct way to do it, it should be tried first, I think. But I did try rewriting my code using something similar to your structure, and I got something working. w00t.
function preview() {
var it=null;
try {
it=new XMLHttpRequest();
}
catch(e) {
//alert("XMLHttpRequest failed.");
try {
it=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
//alert("Msxml2.XMLHTTP failed.");
try {
it=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
//alert("Microsoft.XMLHTTP failed.");
alert("Your browser won't support this feature.");
}
}
}
if (it) {
//do stuff
}
}
This works for me:
this.initialize = function()
{
if (window.XMLHttpRequest)
{
try
{
this.xmlhttp = new XMLHttpRequest();
}
catch(e)
{
alert('AJAX '+ e.name +': '+ e.message);
}
}
else if (window.ActiveXObject)
{
try
{
this.xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
catch(e)
{
alert('AJAX '+ e.name +': '+ e.message);
}
}
else
{
alert('AJAX Error: initialization failed');
}
};
Why is the default anonymous name #!usr/bin/anon?
Sincerly,
#!/usr/bin/anon
I dunno, what do you suggest instead? /usr/bin/id? /usr/bin/whoami?
>>31
He meant that it lacks a /
after the !
(#!/usr
instead of #!usr
)
And it should definitely be #!/usr/bin/env anon
, it is much more portable.
/dev/null would be the best I can think of, using a hashbang doesn't really make sense in the first place
How about "(null)", which some C libraries print if you do printf("%s", NULL)? Seems apt.
Just for fun, I was thinking of making a web site where you could upload an image and a script would reduce the size and colors down to work for use as a Mario Kart custom emblem. (Apparently there's a site that already does this at http://www.dsmeet.com/decalmaker/ but it seems to be down at the moment.) Mario Kart only allows fifteen colors (plus transparency, but I'm ignoring that at the moment). I'm rather unsatisfied with the methods PHP (and therefore GD) have for "downing" colors in this way... Notice how it completely ignores the blue background in this image: http://pichan.org/pc/index.php?t=156 (b.png uses imagecolorclosest(), c.png uses imagecolorclosesthwb().)
Does anyone happen to have experience with doing this kind of stuff with images and know a smart and workable way to go about this?
(But don't sweat over it; I'm not, and this is just for fun.)
ImageMagick will probably do it, if you can figure out the correct magic incantations for calling it. Just be careful what filenames you pass it - renaming the file before calling ImageMagick on it is probably the best solution.
I just want to know what would be a good beginging languae to learn? I know html but thats it. Just reccomend me a good begginers language and I will take it from there.
>>39
Python? C? Java? Ruby? (HTML isn't really a programming language.)
well what is the most essential to learn for programming?
C and Java are definitely horrible first languages. I don't think Ruby is a good idea either. Some people claim Python is good for learning, but I don't know about it.
I think Javascript and Perl (as long as you stay with the simple parts of the language) are fairly beginner-friendly languages.
Some would say PHP, but I suspect that all you learn from PHP is bad programming.
I recommend Lua. http://www.lua.org/
Small, free, real simple, and beginner-friendly. And the language also supports advanced programming techniques that you can move onto later.
Ignore the Perl suggestion, Perl is a horrible beginner language, full of special cases and confusing semantics and other stuff. Basically, Perl will make you hate programming.
Python or Ruby.
I personally prefer Ruby over Python, since is has a cleaner syntax and fewer strange quirks, but both are equally powerful. They have nice learning curves too.
I would not recommend perl, for the same reasons >>43 mentioned. I learned perl after several other languages, and I still remember beating my head over it.
C and Java are right out. Especially Java. Any compiled language should not be used as a first language. Any language that makes you jump hoops to do anything especially so. Java is criminal here.
I disagree with Javascript, because alone it doesn't let you do much interesting except websites. The plus side is most browsers come with an interpreter.
I think you are both making a basic mistake here: You say you learned Perl after learning other languages. Thus you expected it to work the same, and it didn't. As a first language, you don't have any pre-conceived opinions about how things should work, and thus this conflict never happens.
You could argue that learning the Perl quirks before anything else would be a problem later on, but I think that's about as bogus as the argument that learning BASIC is somehow harmful. Of course, I didn't learn Perl as a first language, but I have sort of an instinctive feel that it has a bunch of features that make it nice to beginners. Being more forgiving about syntax than many other languages is one.
> about as bogus as the argument that learning BASIC is somehow harmful
Sorry, but that argument is not bogus. My first two languages were QuickBASIC and Visual Basic, and they were a prison for my mind. I was constantly frustrated by stupid counterintuitive crap like the = operator doing two different things, "INPUT A$" printing a question mark while "INPUT A$," doesn't (or something like that), and other built-in gadgets with ad-hoc syntax. It took years before I was able to learn a real programming language (C) and actually figure out what the fuck I was doing.
I think you killed your whole argument right there. If Perl is as good a beginner language is BASIC, it is a god-awful beginner language and should be avoided at all costs.
my first two languages were quickbasic and java... i've never had any trouble learning any language since then...
>>48
This only shows that you probably would've been fine no matter what language you started with. Some learn more easily than others, so consider yourself lucky. BASIC is still a crap language, though.
>>46
By the same argument, vi should be used by everyone.
>>50
So then, I should start programming with a Fisher & Price keyboard for babies? The difficulty/complexity of what you first show a beginner should never be defined by a global thought of what all newbies should learn. That's just stupid. Why don't we all just drive the same kind of cars, and use exactly the same kind of computers? We dont because everyone is unique. Learning/Teaching something to someone should have the complexity-o-meter adjusted at a per-person level. Banging on that Perl would be wrong for beginners, is stupid for this reason since there will be people out there that find it easier to pick up than another language. I found Perl pretty easy, as I can't get my head around OO.
> So then, I should start programming with a Fisher & Price keyboard for babies?
Ruby and Python are hardly Fisher Price. Less rhetoric please.
> Banging on that Perl would be wrong for beginners
Nobody said it's wrong, but there are better choices.
You misunderstood the argument. It's not that BASIC is a bad language for learning in, it's that some people argue that learning BASIC is actually harmful because it somehow ruins your brain and makes you unable to learn other languages. That's what I'm calling bullshit on, not the fact that BASIC may or may not be a shitty language, for learning or otherwise.
Only if you ignore the actual point of my argument, which is that Perl has a number of features that make it appealing for beginners. I'm willing to argue that one, though, it's not something I can conclusively prove or anything.
Perl is a viable contender. It's mainstream, it's interpreted, it has CPAN (the crown jewel!), and it's fast for an interpreted language. More importantly, it's simple enough to start doing something in.
But I'm a bit worried about what might happen when the budding programmer begins to mature. My main gripe here is related to ADT, like lists of lists. Perl makes it unusually complicated to use anything fancier than the built-in datatypes. The alternatives don't present these hoops.
Perl6 might fix this (?), and a whole slew of other oddities, but right now the only serious glimmer of Perl6 is Pugs. If it wasn't for Pugs, I'd say Perl6 dev was effectively dead.
I personally feel someone is better off learning Perl than Ruby or PHP. It is a common language, it's syntax is known, and it's not full of either scandal or security holes. Nor is it a "fad" in the stupidass blogosphere.
> Nor is it a "fad" in the stupidass blogosphere.
Verily, an excellent reason to avoid Ruby. cough
I'm not certain what the "syntax is known" comment is supposed to mean. And which language is full of scandal? Why do you think that?
I've been playing with Qt bindings in ruby, however I'm having problem with this code:
require 'Qt'
class MyWidget < Qt::Widget
def initialize(parent=nil)
super(parent)
@label = Qt::Label.new(self)
@button = Qt::PushButton.new(self)
@layout = Qt::VBoxLayout.new(self)
@layout.addWidget(@label)
@layout.addWidget(@button)
@clicked_times = 0
@label.setText("The button has been clicked " +
@clicked_times.to_s + " times")
@button.setText("My Button")
end
end
a = Qt::Application.new(ARGV)
mw = MyWidget.new
a.setMainWidget(mw)
mw.show
a.exec
According to the book I got this from, this is supposed to show a window with a label, and a button below the label. However when I run it it only shows an empty window. I've figured out ruby ignores everything after the
super(parent)
in the initialize method.
Is there something wrong with the code, or is it my ruby installation that is bugged?
Try adding "name" as well:
def initialize(parent=nil, name=nil)
super
>>58 thanks for the suggestion, but that didn't make a difference. Also from what I understand adding name is optional and is only usefull for debugging and when searching from classes.
s/from classes/for classes
All I can suggest is trying some of the code at http://developer.kde.org/language-bindings/ruby/tutorial/tutorial.html