[HELP] Single questions & Help Thread [n00b] (61)

1 Name: #!usr/bin/anon 2005-10-20 18:41 ID:U7k5C2I3

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)

12 Name: dmpk2k!hinhT6kz2E 2005-11-16 22:52 ID:Heaven

Can't you swap values before hashing? Adopt a policy that lowest host comes first.

13 Name: !WAHa.06x36 2005-11-17 12:50 ID:krnY7okz

>>11

Sort the values before hashing.

14 Name: !WAHa.06x36 2005-11-17 12:51 ID:Heaven

Which I guess is what >>12 suggested already...

15 Name: #!usr/bin/anon 2005-11-18 20:59 ID:FbMyy6NN

Yes, adopting the lowest one first is a really quick'n dirty solution. It worked, thanks!

16 Name: !WAHa.06x36 2005-11-20 00:39 ID:Heaven

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.

17 Name: Albright!LC/IWhc3yc 2005-11-23 14:05 ID:AiIcLjL3

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.

18 Name: #!usr/bin/anon 2005-11-24 09:28 ID:Heaven

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.

19 Name: Albright!LC/IWhc3yc 2005-11-24 14:40 ID:AiIcLjL3

_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.

20 Name: !WAHa.06x36 2005-11-24 22:22 ID:50gFtumP

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().

21 Name: Albright!LC/IWhc3yc 2005-11-25 12:25 ID:AiIcLjL3

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.

22 Name: !WAHa.06x36 2005-11-25 13:17 ID:Heaven

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.

23 Name: #!usr/bin/anon 2005-11-26 00:17 ID:Heaven

Apple have some very good cross-browser XMLHttpRequest documentation:
http://developer.apple.com/internet/webcontent/xmlhttpreq.html

24 Name: Albright!LC/IWhc3yc 2005-11-30 16:49 ID:AiIcLjL3

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.

25 Name: !WAHa.06x36 2005-12-01 14:48 ID:krnY7okz

Don't quote me on this, but possibly your problem is that false != null. Just use if(!xyz).

26 Name: Albright!LC/IWhc3yc 2005-12-01 15:12 ID:AiIcLjL3

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.

27 Name: !WAHa.06x36 2005-12-01 23:44 ID:50gFtumP

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.

28 Name: Albright!LC/IWhc3yc 2005-12-05 17:38 ID:AiIcLjL3

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
}
}

29 Name: #!usr/bin/anon 2005-12-05 23:16 ID:2kFWuaUa

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');
}
};

30 Name: !TgfOVovqoo 2005-12-06 07:20 ID:sQiCzDJn

Why is the default anonymous name #!usr/bin/anon?

Sincerly,
#!/usr/bin/anon

31 Name: #!usr/bin/anon 2005-12-06 19:44 ID:Y1DRGnmb

I dunno, what do you suggest instead? /usr/bin/id? /usr/bin/whoami?

32 Name: #!usr/bin/anon 2005-12-06 21:32 ID:2kFWuaUa

>>31
Undefined

33 Name: #!usr/bin/anon 2005-12-06 23:44 ID:V1V3GH+G

>>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.

34 Name: #!usr/bin/anon 2005-12-07 20:40 ID:sQiCzDJn

/dev/null would be the best I can think of, using a hashbang doesn't really make sense in the first place

35 Name: #!usr/bin/anon 2005-12-07 23:25 ID:Y1DRGnmb

>>33
Ah, I hadn't even noticed, heh.

>>34
I think the point is that this is a programming board, hence the reference to an interpreter.

Some other ideas:

#include <sys/anon.h>
?f.(?x.f (x x)) (?x.f (x x))
Code Monkey

These ideas suck, but whatever. Maybe someone will volunteer a better one.

36 Name: #!usr/bin/anon 2005-12-07 23:26 ID:Heaven

How about "(null)", which some C libraries print if you do printf("%s", NULL)? Seems apt.

37 Name: Albright!LC/IWhc3yc 2005-12-12 17:49 ID:AiIcLjL3

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.)

38 Name: !WAHa.06x36 2005-12-12 20:58 ID:Heaven

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.

39 Name: the spi 2006-01-12 08:55 ID:R5O2n4Ap

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.

40 Name: #!/usr/bin/anon 2006-01-12 09:13 ID:Heaven

>>39
Python? C? Java? Ruby? (HTML isn't really a programming language.)

41 Name: the spi 2006-01-12 09:16 ID:R5O2n4Ap

well what is the most essential to learn for programming?

42 Name: !WAHa.06x36 2006-01-12 14:04 ID:krnY7okz

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.

Also see: http://4-ch.net/code/kareha.pl/1109963434

43 Name: #!/usr/bin/anon 2006-01-12 16:22 ID:Y1DRGnmb

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.

44 Name: #!/usr/bin/anon 2006-01-13 00:25 ID:Q1u9UvmX

45 Name: dmpk2k!hinhT6kz2E 2006-01-13 03:36 ID:Heaven

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.

46 Name: !WAHa.06x36 2006-01-13 14:39 ID:Heaven

>>43,45

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.

47 Name: #!/usr/bin/anon 2006-01-13 17:05 ID:Heaven

> 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.

48 Name: #!/usr/bin/anon 2006-01-13 19:26 ID:lyz6s7v0

my first two languages were quickbasic and java... i've never had any trouble learning any language since then...

49 Name: #!/usr/bin/anon 2006-01-13 19:36 ID:Heaven

>>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.

50 Name: dmpk2k!hinhT6kz2E 2006-01-13 22:19 ID:Heaven

>>46
By the same argument, vi should be used by everyone.

51 Name: #!/usr/bin/anon 2006-01-14 04:09 ID:O3BcS+hJ

>>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.

52 Name: dmpk2k!hinhT6kz2E 2006-01-14 05:27 ID:Heaven

> 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.

53 Name: !WAHa.06x36 2006-01-14 12:28 ID:50gFtumP

>>47

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.

>>50

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.

54 Name: dmpk2k!hinhT6kz2E 2006-01-14 15:12 ID:Heaven

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.

55 Name: #!/usr/bin/anon 2006-01-14 17:20 ID:O3BcS+hJ

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.

56 Name: dmpk2k!hinhT6kz2E 2006-01-15 00:52 ID:Heaven

> 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?

57 Name: #!/usr/bin/anon 2006-01-16 02:06 ID:vGQ6tMbN

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?

58 Name: dmpk2k!hinhT6kz2E 2006-01-16 02:39 ID:Heaven

Try adding "name" as well:

def initialize(parent=nil, name=nil)
super

59 Name: #!/usr/bin/anon 2006-01-16 15:33 ID:vGQ6tMbN

>>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.

60 Name: #!/usr/bin/anon 2006-01-16 16:40 ID:Heaven

s/from classes/for classes

61 Name: dmpk2k!hinhT6kz2E 2006-01-16 22:48 ID:Heaven

All I can suggest is trying some of the code at http://developer.kde.org/language-bindings/ruby/tutorial/tutorial.html

This thread has been closed. You cannot post in this thread any longer.