Raspberry BASIC

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - AIR

Pages: [1] 2
1
Programming Challenges / Re: GUI Login
« on: February 11, 2020, 04:02:42 am »
So how are your NIM adventures going, John?

Sorry I haven't been around lately - 14 hour days at work while moving into a new home doesn't leave a lot of time for anything...

AIR.

2
Programming Challenges / Re: GUI Login
« on: December 25, 2019, 06:58:55 am »
Code: C
  1. /* logon.c
  2.  *
  3.  * version 1.0
  4.  *
  5.  * GUI Logon Screen Challenge Submission
  6.  * C version, using GTK+-3.0
  7.  * Written by Armando I. Rivera (AIR)
  8.  *
  9.  * Compile:  gcc logon.c $(pkg-config --libs --cflags gtk+-3.0) -o logon
  10. */
  11.  
  12. #include <gtk/gtk.h>
  13.  
  14.  
  15. void onClick( GtkWidget *widget, gpointer   data ) {
  16.         gchar *stupid_password = "pa$$w0rd!";
  17.         gchar *user_password;
  18.         g_object_get(data,"text",&user_password,NULL);
  19.  
  20.         if (g_strcmp0 (stupid_password,user_password) == 0) {
  21.                 g_print("Your are now logged in!\n");
  22.                 gtk_main_quit();
  23.         }else{
  24.                 g_print("Username or Password is Incorrect!\n");
  25.         }
  26. }
  27.  
  28. int main (int argc, char **argv) {
  29.         GtkWidget *mainWin, *lblUser, *lblPass, *txtUser, *txtPass;
  30.         GtkWidget *hbox, *vbox, *btnLogin;
  31.  
  32.         gtk_init(&argc, &argv);
  33.  
  34.         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,6);
  35.         vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL,6);
  36.         mainWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  37.  
  38.         g_object_set(mainWin,
  39.                                 "title","Login",
  40.                                 "default-width",400,
  41.                                 "resizable",FALSE,
  42.                                 "window-position",GTK_WIN_POS_CENTER,
  43.                                 "child",vbox,
  44.                                 NULL);
  45.        
  46.         g_object_set(vbox,"child",hbox,"margin",10,NULL);
  47.        
  48.         lblUser = gtk_label_new("Username:");
  49.         lblPass = gtk_label_new("Password: ");
  50.        
  51.         txtUser = gtk_entry_new();
  52.         txtPass = gtk_entry_new();
  53.        
  54.         g_object_set(txtUser,"expand",TRUE,"text",g_get_user_name(),NULL);
  55.         g_object_set(txtPass,"expand",TRUE, "visibility", FALSE,NULL);
  56.  
  57.         g_object_set(hbox,"child",lblUser,"child",txtUser,"spacing", 6, NULL);
  58.        
  59.         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,6);
  60.         g_object_set(vbox,"child",hbox, NULL);
  61.         g_object_set(hbox,"child",lblPass,"child",txtPass,"spacing", 6, NULL);
  62.        
  63.  
  64.         btnLogin = gtk_button_new_with_label("Login");
  65.         g_object_set(vbox,"child",btnLogin,NULL);
  66.  
  67.         g_signal_connect (mainWin, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  68.         g_signal_connect (btnLogin, "clicked", G_CALLBACK (onClick), txtPass);
  69.        
  70.         gtk_widget_show_all(mainWin);
  71.         gtk_main();
  72.         return 0;
  73. }
  74.  
  75.  

AIR.

3
Nim / Re: Nim IUP
« on: December 24, 2019, 11:36:12 pm »
Not meant to hijack this thread, but I wanted to show your three-button demo using a different GUI package based on libui:

Code: Text
  1. import ui
  2.  
  3. proc b1_clicked() = echo "Button 1 Event"
  4. proc b2_clicked() = echo "Button 2 Event"
  5. proc b3_clicked() = echo "Button 3 Event"  
  6.  
  7. ui.init()
  8.  
  9. let mainwin = newWindow("Window",1,1,false)
  10. let b1 = newButton("Button 1",b1_clicked)
  11. let b2 = newButton("Button 2",b2_clicked)
  12. let b3 = newButton("Button 3",b3_clicked)
  13. let hbox = newHorizontalBox(true)
  14.    
  15. mainwin.margined = true
  16. mainwin.onClosing = (proc (): bool = return true)
  17. mainwin.setChild(hbox)
  18.  
  19. hbox.add b1; hbox.add b2; hbox.add b3
  20.  
  21. mainwin.show
  22. ui.mainLoop()
  23.  

AIR.

4
Programming Challenges / Re: SALC Ubuntu 64
« on: December 23, 2019, 04:50:25 am »
VALA

Code: Vala
  1. int main (string[] args) {
  2.         var a = new int[1000000];
  3.         var s = new StringBuilder();
  4.         var t = new StringBuilder();
  5.         int c;
  6.  
  7.         for (int x  = 0; x < 1000001; x++) {
  8.                 a[x] = x;
  9.                 c = x % 26;
  10.  
  11.                 s.append_c( (char)c + 65);
  12.  
  13.                 if ( c == 25) {
  14.                         t.append(s.str.reverse());
  15.                         s.truncate();
  16.                 }
  17.         }
  18.  
  19.         string r = t.str;
  20.  
  21.         stdout.printf("r LEN: %d\n",r.length);
  22.         stdout.printf("Front: %s\n",r.substring(0,26));
  23.         stdout.printf("Back:  %s\n", r.substring(r.length-26,26));
  24.         stdout.printf("UBVal: %d\n", a[1000000]);
  25.         return 0;
  26. }
  27.  

riveraa@rpi:~/Projects/vala$ valac -X -O3 mil64.vala

r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.03user 0.00system 0:00.03elapsed 97%CPU (0avgtext+0avgdata 7704maxresident)k
0inputs+0outputs (0major+1581minor)pagefaults 0swaps


AIR.

5
Programming Challenges / Re: SALC Ubuntu 64
« on: December 22, 2019, 06:04:08 am »
Lua5.3

Code: Lua
  1. a = {}
  2. local s = ""
  3. local t = {""}
  4.  
  5. for i = 0,1000000 do
  6.         a[i] = i
  7.         local c = (i % 26)
  8.         s = s .. string.char(c + 65)
  9.         if c == 25 then
  10.                 table.insert(t, string.reverse(s))
  11.                 s = ""
  12.         end
  13. end
  14.  
  15. local r = table.concat(t)
  16. print("r LEN: ", #r)
  17. print("Front: ", string.sub(r,1,26))
  18. print("Back:  ", string.sub(r,-26))
  19. print("UBVal: ", a[1000000])
  20.  

riveraa@rpi:~/Projects/lua$ timex lua mil.lua
r LEN:    999986
Front:    ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:     ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal:    1000000
0.61user 0.02system 0:00.64elapsed 99%CPU (0avgtext+0avgdata 20812maxresident)k
0inputs+0outputs (0major+4981minor)pagefaults 0swaps


AIR.

6
Programming Challenges / Re: SALC Ubuntu 64
« on: December 17, 2019, 03:31:01 am »
I think you should split the 64bit posts into a separate thread...so they and the 32bit posts are easier to find in the future.

7
Programming Challenges / Re: SALC Ubuntu 64
« on: December 16, 2019, 05:29:05 am »
BaCon (Ubuntu 64 RPi 4B 4GB)


Compiler error:

Description:
    file '1mil4.bac' line 18: fprintf(stream,s$)
Cause:
    passing argument 2 of 'open_memstream' from incompatible pointer type [-Wincompatible-pointer-types]

ubuntu@rpi4b:~/salc/bacon-dev$


Make the following TWO changes (Ubuntu's gcc is more strict than Rasbian's):

Code: C
  1. DECLARE len TYPE size_t

Code: C
  1. fprintf(stream, "%s", s$)


AIR.

8
General Discussion / Re: Ubuntu 64 RPI 4B
« on: December 15, 2019, 07:51:19 pm »
BTW, if for some reason you want to be able to run the 32bit challenge binaries created on your Raspbian system, do this:

sudo dpkg --add-architecture armhf
sudo apt update
apt-get install libc6:armhf


AIR.

9
Programming Challenges / SALC Ubuntu 64
« on: December 15, 2019, 08:16:57 am »
I reworked the FreeBasic submission, and ran it on my Ubuntu PI4:

Code: FreeBasic
  1. ' FreeBasic - 1mil3.bas
  2.  
  3. DIM SHARED a(1000001) AS INTEGER
  4.  
  5. function Reverse( byref source as string ) as string
  6.     dim as integer first = 0, last = Len(source)-1
  7.  
  8.     while( first < last )
  9.         Swap source[first], source[last]
  10.         first += 1 : last -= 1
  11.     wend
  12.  
  13.     return source
  14. end function
  15.  
  16. sub mil()
  17.     dim as string s,t,r
  18.     dim as integer x,c
  19.  
  20.     FOR x = 1 TO 1000000
  21.         c = (x - 1) MOD 26
  22.         s &= CHR(c + 65)
  23.         a(x) = x
  24.         IF c = 25 THEN
  25.             t &= s
  26.             s = ""
  27.             c = 0
  28.         ENDIF
  29.     NEXT
  30.  
  31.     r = Reverse(t)
  32.  
  33.     PRINT "r LEN: " & LEN(r)
  34.     PRINT "Front: " & LEFT(r, 26)
  35.     PRINT "Back:  " & RIGHT(r, 26)
  36.     PRINT "UBVal: " & a(1000000)
  37. end sub
  38.  
  39.  
  40. mil()
  41.  

riveraa@dpi:~/tmp$ timex ./1mil3
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.16user 0.02system 0:00.18elapsed 98%CPU (0avgtext+0avgdata 11596maxresident)k
0inputs+0outputs (0major+2623minor)pagefaults 0swaps


AIR.

EDIT:  Cleaned up code.

10
FreeBasic / Re: FreeBasic RPi Install
« on: December 15, 2019, 05:46:12 am »
I managed to compile this from the bootstrap source on my RPI4 running Ubuntu 64bit, omitting the graphics lib for now since I run headless.

Playing around with it, I'll let you know how it goes...

AIR.

11
Programming Challenges / Re: SALC Rasbian 32
« on: December 15, 2019, 01:55:04 am »
I'm wondering if it's the build flags associated with armf....

I ran the glib submission, and it is truly smoking in 64 bit:

riveraa@dpi:~/Projects/glib$ timex ./mil64
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.02user 0.01system 0:00.04elapsed 100%CPU (0avgtext+0avgdata 6512maxresident)k
0inputs+0outputs (0major+1332minor)pagefaults 0swaps


AIR.

12
Programming Challenges / Re: SALC Rasbian 32
« on: December 15, 2019, 01:22:50 am »
I installed Ubuntu Server 19.10.1, which is 64bit, on my other RasPi 4b (4GB).

Interestingly, the arch is "aarch64".

None of the 32bit RasPi submissions run on it though.

One of the things I wanted to see is how the Swift submission would run on it.

Here's what I got:

riveraa@dpi:~/Projects/Swift/1mil3$ file ./mil
./mil: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, not stripped

riveraa@dpi:~/Projects/Swift/1mil3$ timex ./mil
r LEN:  999986
Front:  ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:   ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal:  100000
0.66user 0.02system 0:00.68elapsed 99%CPU (0avgtext+0avgdata 16292maxresident)k
0inputs+0outputs (0major+2795minor)pagefaults 0swaps

riveraa@dpi:~/Projects/Swift/1mil3$ uname -a
Linux dpi 5.3.0-1014-raspi2 #16-Ubuntu SMP Tue Nov 26 11:18:23 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux
riveraa@dpi:~/Projects/Swift/1mil3$


Food for thought...

AIR.

13
Swift / Re: Swift RPi
« on: December 11, 2019, 06:31:06 am »
That's in line with what I'm seeing on my Mac, using the official Apple Swift.

AIR.

14
Nim / Re: Nim IUP
« on: December 11, 2019, 06:22:18 am »
Took you a while, but I'm glad you're finally taking NIM for a spin!

AIR.

15
General Discussion / Re: MS Rust
« on: December 10, 2019, 11:08:44 pm »
Will it be using IL or will it be a more direct (meaning no intermediate or JIT compiling steps like some Dot Net languages) to binary solution?

AIR.

Pages: [1] 2