Great job folks! Keep them coming. :)
I'll modify the rules so that you don't have to write stuff to terminal. That should make it easier for markup languages and for any implementations that use a simple GUI. ;)
Printable View
Great job folks! Keep them coming. :)
I'll modify the rules so that you don't have to write stuff to terminal. That should make it easier for markup languages and for any implementations that use a simple GUI. ;)
NASM Assembly (i386)... Revised for size!
This one is an alternative to my original assembly entry, but I hacked if down from about 1000 bytes to about 200 bytes. No linking required here since the ELF header is in the source.
Once again, the assembler usage command is at the top of the file.
Ugly, isn't it?Code:; nasm hello.asm -f bin -o hello && chmod +x hello
BITS 32
org 0x08048000
ehdr: db 0x7F, "ELF", 1, 1, 1, 0
console_out: db 0xB0, 0x04, 0x31, 0xDB, 0x43, 0xCD, 0x80, 0xC3
db 2, 0, 3, 0
dd 1, _start, phdr-$$
console_in: db 0xB0, 0x03, 0x31, 0xDB, 0xCD, 0x80, 0xC3, 0
dw ehdrsz, phdrsz
ehdrsz equ $-ehdr
phdr: dd 1, 0, $$, $$, filesz, filesz, 5
get_len: db 0x31, 0xD2, 0x42, 0x80
phdrsz equ $-phdr
db 0x3C, 0x11, 0x0A, 0x75, 0xF9, 0xC3
_start:
sub esp, 128
mov ecx, intro
mov dl, 22
call console_out
mov ecx, esp
mov dl, 128
call console_in
mov ecx, outro1
mov dl, 6
call console_out
mov ecx, esp
call get_len
call console_out
mov ecx, outro2
mov dl, 21
call console_out
xor eax, eax
inc eax
int 0x80
intro db "Hi! What's your name? "
outro1 db "Hello "
outro2 db "! Welcome to Ubuntu!", 10
filesz equ $-$$
Java (AWT GUI version)
Code:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class helloubuntu extends Frame {
public helloubuntu() {
initComponents();
}
private void initComponents() {
inputField = new TextField();
greetButton = new Button();
greetMsg = new Label();
setMinimumSize(new Dimension(300, 100));
setTitle("Hello Ubuntu");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
exitForm(evt);
}
});
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
add(inputField);
greetButton.setLabel("Hi! What's your name?");
greetButton.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
greetButtonMouseClicked(evt);
}
});
add(greetButton);
add(greetMsg);
pack();
}
private void greetButtonMouseClicked(MouseEvent evt) {
String userName;
userName = inputField.getText();
greetMsg.setText("Hello " + userName + "! Welcome to Ubuntu");
}
private void exitForm(WindowEvent evt) {
System.exit(0);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new helloubuntu().setVisible(true);
}
});
}
private Button greetButton;
private Label greetMsg;
private TextField inputField;
}
Hello World with Xt!
Code:/* Compile with gcc <filename> -lXaw */
/* Please do not ask me where to get the headers as I don't know where on Debian */
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/AsciiText.h>
Arg args[1];
Widget window, box, label, form, button, text;
static void button_handler(Widget w, XtPointer call_data, XtPointer client_data)
{
String string;
char msg[256];
XtSetArg(args[0], XtNstring, &string);
XtGetValues(text, args, 1);
memset(&msg, '\0', 256);
memcpy(&msg, "Hello, ", strlen("Hello, "));
memcpy((&msg[0] + strlen(&msg[0])), string, strlen(string));
memcpy((&msg[0] + strlen(&msg[0])), "! Where is your GNOME now!?", \
strlen("! Where is your GNOME now!?"));
XtVaSetValues(label, XtNlabel, &msg, NULL);
}
int main(int argc, char** argv)
{
XtAppContext cx;
window = XtVaAppInitialize(&cx, "Hello World", NULL, 0, \
&argc, argv, NULL, NULL);
box = XtVaCreateManagedWidget("box", boxWidgetClass, window, NULL);
label = XtVaCreateManagedWidget("label", labelWidgetClass, box, \
XtNlabel, "Hi! What's your name?", XtNborderWidth, 0, NULL);
form = XtVaCreateManagedWidget("form", formWidgetClass, \
box, XtNsensitive, True, XtNborderWidth, 0, NULL);
text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, \
form, XtNheight, 20, XtNwidth, 500, NULL, NULL, NULL, NULL, \
NULL);
button = XtVaCreateManagedWidget("button", commandWidgetClass, form, \
XtNlabel, "Okay", XtNfromVert, text, NULL);
XtAddCallback(button, XtNcallback, button_handler, NULL);
XtVaSetValues(text, XtNeditType, XawtextEdit, XtNdisplayCaret, True, \
NULL);
XtRealizeWidget(window);
XtAppMainLoop(cx);
}
SQL (script to be run in SQL*Plus)
Code:select 'Hi! What''s your name?' from dual;
select 'Hello, &1 ! Welcome to Ubuntu!' from dual;
PL/SQL (procedure with parameter)
Code:create or replace procedure helloUbuntu(in_name in varchar2)
is
begin
dbms_output.put_line('Hi! What''s your name?');
dbms_output.put_line('Hello, '||in_name||' ! Welcome to Ubuntu!');
end helloUbuntu;
VBScript
All the cools languages where done, so I had to go over to the darkside.Code:dim name
name = inputbox("Hi! What is your name?","Hello Ubuntu!")
msgbox "Hello, "& name &"! Welcome to Ubuntu!"
Please note, this will NOT work in Linux.
Javascript
I think that should work, haven't coded Javascript for a long time =DCode:var name = prompt( 'Hi! What is your name?', 'Please enter your name' );
alert( 'Hello, '+name+'! Welcome to Ubuntu!' );
...
danke, fixed!