Showing posts with label Mental-Note. Show all posts
Showing posts with label Mental-Note. Show all posts

2021-04-28

Programming Language Notes 2021 - multiplatform, GUIs

These are incomplete notes and thoughts on programming languages through lens of multiplatform support and coding GUI apps for platforms like Android, iOS, Mac, Windows, Linux, and web (front and back ends).

JavaScript

Lack type safety.

Java, Go, Python, Ruby, C++, C, Elixir

Not great for frontend web dev.

D

Not great for Android or iOS.   Can build web apps via compiling to WASM (pretty sure it's experimental), but lack mature frameworks for frontend web dev.  Not very popularly used, unfortunately.

TypeScript

It's JavaScript but with a brilliant aftermarket type system retrofit. If you must code JS, then TS is a fantastic upgrade.

For backend, there's faster languages (Java, Go).  For device native apps, other languages are maybe better suited (Swift, Kotlin, etc).  Great choice for web frontend.

For frontend web dev, used with React is popular.  There's React Native to build device native apps for Macs, Windows, Linux, Android, and iOS that uses platform native UI widgets (some haven't reached 1.0 yet though, if you're looking for maturity).  You'd still have to build 5 specialized UIs though (6 including web), and there are faster device native languages.

Kotlin

Compiles to JVM, JS, and native.  Kotlin Multiplatform Mobile (alpha) is great for write-once application logic for iOS / Android native apps, but the UI code must be specialized for each platform (could still be written in Kotlin though).

e.g. Use with Google Android's Jetpack Compose (beta) and Apple's Swift UI for native Android and iOS UI.

e.g. Use with Jetbrains' Compose for Desktop to build apps for Windows, Macs, and Linux --- but this  runs on JVM and renders using Skia, so it doesn't use platform native UI widgets (it draws it's own like a game does).  And it's in alpha.

Some say Jetpack Compose is Google Android team's answer to Google Ads team's Dart/Flutter.

Kotlin/JS means you can use with React for frontend web dev too.  Not sure of its maturity.  Kotlin is great for backend using Spring or Ktor.

PHP

Not great for device native apps

C#

Windows centric.  Blazor lets you do frontend web dev by compiling to WASM but it adds C#'s runtime to your web app to run in WASM as well (read: bigger, slower app).

Rust

Lower level, like C or C++.  Can build web apps via compiling to WASM, but without bringing a runtime along for the ride (check out Yew or Seed).  Can build backend stuff (check out Actix-web or Rocket), but frameworks aren't mature the way Django or RoR are.

Coding device native GUI apps is... not there yet.

Rust is getting a lot of traction for systems programming though (unlike D, unfortunately).

Dart

Basically exists for Flutter.  Flutter lets you build apps for Windows, Macs, Linux, iOS, Android, and the web.  On the web, it draws into a canvas.  On devices, it renders using Skia.  So it doesn't use platform native UI widgets anywhere, and draws it's own like a game does.  On the web, it's UI performance is a little janky.

Dart compiles to JS or runs on Dart VM.  Unlike the Kotlin stuff above, Flutter is production ready and being used by Google, notably by their Ads team (apparently some of the Kotlin stuff above are the Android team's answer to Flutter).

It's from Google, so who knows if they'll cancel it in 5 years time.

Other thoughts

Rendering to Skia like Compose for Desktop and Flutter is not great for accessibility, and their accessibility features are currently WIP.

React Native has edge cases for each platform so you'd still need to know each platform carefully.  Plus TypeScript / JavaScript bridging into native can have performance issues.

 Nothing's perfect.

That's all I've got time for today!

Missing: Scala, Clojure, Haskell, F#, Crystal, PureScript, Elm.

2010-12-18

Getting Leiningen 1.4.1 working on Windows (and a weird bug)

First the bug, don't make a project named "test" in Leiningen or else it will throw a NullPointerException.

Second, when getting Leiningen 1.4.1 installed on Windows 7 64bit, I had to jump through a few hoops.  Firstly, don't place the lein folder in "Program Files (x64)".  Put it in "Program Files" instead.  The parentheses will mess up the lein.bat script otherwise.

Secondly, after running "lein self-install", you'll have to fetch the downloaded "leiningen-1.4.1-standalone.jar" file from "C:\Users\my_user_name_here\AppData\Local\VirtualStore\Program Files\lein" and move it into "C:\Program Files\lein".  (Refer to this).

I'm assuming you've copied the lein folder into "C:\Program Files" of course.

2010-12-12

Command line utilities missing from Mac OS X

Here I am setting up my Mac so that I can do Clojure programming as I did on my other Ubuntu Linux computer and what do I find?  Loads of missing command line utilities I didn't know I used.

I'm using Fink as the package manager for unix/linux stuff here as it's what I'm used to using from years ago, and it seems okay, excerpt on Mac OS X 10.6 they don't have the binaries pre-built yet I guess.  So I'm compiling all kinds of stuff from scratch.

So here's a partial listing of the programs missing or seriously outdated on the default Mac install that I got through Fink.  Some of them are a little oudated in Fink too though, and installing these will install a slew of other useful things along with it.

  • watch
  • clamav
  • emacs
  • srm
  • git
  • gcc
  • ghostscript

Also, I needed LaTeX.  It's best to get that through MacTex though (don't bother with the i-Installer stuff you might find elsewhere).

2010-12-06

Easier Personal File Sharing in Ubuntu

I don't know why it's so hard to get file sharing right in Ubuntu Linux [1] (Mac OS X makes it so easy).  But now there's a way for easy personal file sharing in Ubuntu.  This is meant for you sharing files with, basically, yourself, or at most one or two other people who you don't mind letting use your computer (ie, you don't mind making them an account on your computer to log in with).  If you need file sharing that's more complicated than that, you better find a more comprehensive solution, using Samba, or whatever else.

My solution basically boils down to using SSH to do the network connections, a fire wall to control whether to allow sharing of files or not at any time, user accounts to control who can log in to get at shared files, and SFTP on connecting computers to access the shared files in your Ubuntu Linux computer.  This means that you can't just share any single folder, but must share everything in a single home directory, or else you'll have to do some file permissions judo (but if you must do that, then you might as well get a proper file sharing service going).

On your Ubuntu computer, using the Synaptic package manager or Ubuntu Software Center, install sshd and a fire wall control program (I can suggest Firestarter and Firewall configuration).

sshd seems to configure itself just fine, so you just need to configure your firewall.  The pertinent part about your firewall is setting up a rule to allow access from certain IPs to your computer's port 22.  I allow every computer in my subnet 192.168.0.x to access my files, so I have a rule allowing 192.168.0.0/24 (the 24 shows that the first 24 bits are subnet masked) to access my computer's port 22.

If you only want to allow yourself access to your home folder's files, you're already set up!  This was my own use case (just wanting to share my own files with myself on multiple computers).  If others who don't have an account of your computer wants to be able to access files on your computer, you will have to create a user account for them on your computer, and do some folder permission judo, or else copy those files to that user's home folder, to let them get access to them.

In any case, so now, on another computer, you can SFTP into the first computer (where you installed sshd) using the IP address of that computer.  If you use Ubuntu on this second computer, you can do this in Nautilus (just type in the address bar sftp://your_user_name@ip.address.right.here).  If you're on Windows, you can use Filezilla as a SFTP program.  I don't recall which program Macs can use, but there's certainly one.

And that's it!  When you want to "shut down" file sharing, just close down the firewall rule.



[1] I've tried both the File Sharing and Personal File Sharing packages in Ubuntu.  They were more hassle and unreliable than I cared for in my extremely simple use-case.

2010-12-05

Visual Studio C++ 2005 Side by Side DLL Configuration Errors

Previously, I had experienced the "modern" Windows 7 version of DLL Hell, ie, the Side by Side Configuration errors.  I had to reinstall Win7, so I had to experience this Side by Side DLL Hell all over again...  So here's a better and quick explanation of how to fix it:

Programs compiled in Visual Studio C++ may have a number of dynamic link library dependencies.  The dependency is specific down to the version of a library, so the Side by Side (SXS) feature allows Windows to manage having multiple versions of a library available for programs to link to.  These libraries are stored at C:\Windows\winsxs (so you can go have a look and see if you have a particular library needed).

Usually, programs so compiled have a manifest file of what dependencies is needed embedded in the binary of the compiled program.  You can ask Visual Studio to compile with the manifest file split out as a separate XML file by, in Visual Studio, going to Project > Properties > Manifest Tool > Input and Output, and setting the Embed Manifest option to No.  Then compile the program, and opening the XML file, your_program_name.exe.manifest, in any text editor.  It'll tell you which library you need, and which version.

For me, it turns out I needed two different versions of both the C/C++ standard libraries, and the MFC libraries.  After much searching, I found where you can download them from Microsoft:
"Normally," given that you have Visual Studio installed, you should have the necessary copy of those libraries available for redistribution to users without the necessary libraries in your Bootstrapper folder: C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x.  But for whatever reason the copy I have there doesn't have the right version.

 Finally, there is some relevant discussion here.

2010-11-12

Obscure and often used emacs key bindings

Nowadays I juggle programming Clojure in emacs on Ubuntu, and C++ in Visual Studio on Windows.  Despite using what emacs key bindings I can in Visual Studio, I still have to keep track of two very different text editors.

So I'm going to start collecting some emacs key bindings I often use here that are, well, obscure:

Formatting text:

C-M-\ for applying auto-indenting on a marked region
M-q for applying auto-hard-line-breaking on a marked region

Using registers:

C-x r s n for copying text in marked region into register n, for n between 0 - 9 (and apparently other single ascii char, but I'm not sure).
C-x r r n for copying text in marked rectangular region into register n.
C-x r i n for inserting text from register n to current point (be it rectangular or otherwise).

C-x r SPC n for copying the current point/location in the file into register n.
C-x r j n for jumping to the point/location in the file saved into register n.

(See also Registers and Bookmarks.)

In paredit mode:

C-u del or C-u C-d to force the deletion of a character (without paren matching getting in the way)
C-q x for arbitrary character x will force insert the character x (without paren matching getting in the way)

That's all for now.

2010-09-23

Emacs on Windows 7, and setting up ColorTheme

Wanting Emacs on Windows 7?  The install is easy.  There is nice but old instructions over at Installing Emacs on Windows 95/98/2K/NT/ME/XP/Vista/Windows 7.  Here's what I did (I used an administrator account.  YMMV).
  1. I wanted emacs in C:\Program Files (x86)\emacs, so I created that folder first
  2. Go here to get the latest emacs version. I got emacs-23.2-bin-i386.zip
  3. Unzip that file and dump its contents into C:\Program Files (x86)\emacs
  4. In Windows Explorer, open C:\Program Files (x86)\emacs\bin, then double click on runemacs.exe
  5. Yay! You have emacs running.  You may wish to add runemacs.exe to your Start menu (drag and drop it there)
Now I copied over from my Ubuntu Linux my .emacs and .emacs.d.  But where to place it?  If you follow Art Lee's instruction step 6, you can control where you want to place those files using the HOME Environment Variable (set in the Windows Control Panel).

On the other hand, why bother?  Especially if you are not running emacs as an administrator.  By default, the HOME will apparently be set as C:\Users\your_user_name\AppData\Roaming anyway, so copy .emacs and .emacs.d into that directory.

Unfortunately for me, coming from Ubuntu, I had ColorTheme installed via apt-get, so it wasn't contained in my .emacs.d.  I have to reinstall that now...

2010-09-21

Using UUID in fstab on Ubuntu

Unfortunately for me, I have four internal hard drives and a DVD drive on a motherboard that only has four SATA connections.  So from time to time, I do a musical chairs game moving wires around.

Then I started up Ubuntu and it complained it couldn't mount one of my drives.  I checked it and it was a good running drive, so what's wrong?  It turns out I had an fstab entry for a /dev/sdb1 for one of my drives that was using ext3, but after swapping some wires around, /dev/sdb1 mapped to my other drive that was using ext4.  Or maybe it was the other way around.

Anyway, I noticed my primary boot and swap volumes were listed in fstab using UUIDs, so I figured it would be helpful to list my other drives using UUID as well so that they won't be sensitive to the wire swapping that happens from time to time.

How to find out the UUID of the drives?  A quick ls -l /dev/disk/by-uuid/ works, or else try sudo blkid.

More info here: How to find your UUID’s for devices in Ubuntu (and other Debian based distros)

Funny thing, someone else did the exact opposite years ago, switching UUIDs back to /dev/paths.  Maybe UUIDs back then were problematic, but I'm glad Ubuntu stuck with it because it's sure convenient for me nowadays.

2010-09-20

Mapping caps lock to control key in Windows 7

Turns out it's really easy to map the caps lock key to the control key in Windows 7.  Instructions are everywhere, but these two were useful for me:
Despite the link title, the first link is best as it includes the registry changes needed saved into files you can download and import into the registry.

Oh, and the Registry Editor can be opened from the Start Menu's Search box as regedit.exe.

2010-09-01

Firefox add-ons I like

Since I use a number of different computers with different user profiles and such, I have Firefox with separate profiles everywhere.  Maybe I should figure out how to synchronize them or something, but whatever, here's a list of what I like to remind myself next time I have to install Firefox anew:

Privacy
  • Adblock Plus — for blocking ads
  • HTTPS-Everywhere — because I like to encourage web site operators to use HTTPS to secure everything, whether it's really necessary or not
  • BetterPrivacy — controls cookies
  • CookieMonster — more cookie management
  • RefControl — controlling the HTTP referer sent
  • SkipScreen — skips gateway pages from various file storage/download sites
  • Stop Autoplay — stop autoplay of embedded music and movies
  • Master Password Timeout — locks the FireFox password archive automatically
Productivity
  • BlockSite — for blocking the sites I like to go to for procrastination purposes. It's amazing how just that little extra effort required to go to those sites can stop me from wasting time. It's almost like typing in "news.ycombinator.com" is just a reflex, and if something is there to block that reflex the amount of procrastination drops significantly!
  • Download Statusbar — is a way better way to display current downloads
  • FireGestures —mouse gestures control of FireFox
  • FEBE — for backing up FireFox settings and plug-ins
Teaching Web Design
  • Html Validator — validates HTML web pages. Great for use when marking students web pages!
  • TinEye Reverse Image Search — convenient access to TinEye for finding where images came from.  Great for checking to see if students submitted web pages with images they copied without permission from elsewhere
While I'm here, this new TrueType font for Mac, Windows, and Linux, looks cool for programming purposes, called "Anonymous Pro". This has nothing to do with Firefox, but I have nowhere else to write this down. :)

(edit: added more ...)

2010-08-31

Windows overwrote GRUB, and how to fix it

I don't use Windows much, and when I did, Windows 7 wanted to update a billion things (since I haven't used it for months).  Fine, but why does it have to brick my computer?  It overwrote GRUB on the MBR, so now it won't show the menu for picking which OS you want to start up in.  Now I can't boot up in Windows 7 or in Ubuntu 10.04.  How to fix it now?

The basic strategy is to boot up Ubuntu on an external disk, run some simple simple simple command line commands, and it's fixed.

The trouble is that it's my Dell Mini 10 netbook, and I don't have a DVD drive to boot from.  This means the first step is to build a bootable flash drive, and then fix GRUB.  Here's how:

2010-07-20

Various forms of named parameters in Clojure, kind of...

The short of it, from Measuring Measures' Named Parameters in Clojure post is this:

user> (defn a [{b :b c :c}] (- b c))
#'user/a
user> (a {:c 5 :b 11})
6

But that's very repetitive for too many named parameters, so there's this other form too:

user> (defn a [{:keys [b c]}] (- b c))
#'user/a
user> (a {:c 5 :b 11})
6

That's very useful when there's just a lot of arguments to pass around. What if you want to keep all those arguments in a map to continue passing around? There's this option:

user> (defn a [{:keys [b c] :as args}] (- (:b args) c))
#'user/a
user> (a {:c 5 :b 11})
6

These are technically not named parameters at all, but a way to destructure maps passed as an argument to a function.

Caution is in order, however, as you should only destructure in the arg[ument] list if you want to communicate the substructure as part of the caller contract. Otherwise, destructure in a first-line let [Clojure Library Coding Standards], perhaps like so:

user> (defn a [argmap] (let [{:keys [b c]} argmap] (- b c)))
#'user/a
user> (defn a2 [argmap] (let [{b :b c :c} argmap] (- b c)))
#'user/a2
user> (a {:c 5 :b 11})
6
user> (a2 {:c 5 :b 11})
6

2010-06-23

Blogger Page Title Hack

If your Blogger blog posts come up in search engines as "My Wonderfully Great Blog: Name of my post that...", it's being cut off where it matters! It's better to have the post name first, and your blog site name after, so that search engine results don't chop off the most specific part describing your blog post.

To change that in Blogger, go to your Settings tab and click on Edit HTML. Then replace:

<title><data:blog.pageTitle/></title>

with:

<b:if cond="data:blog.pageType != "item"">
    <title><data:blog.pageTitle/></title>
<b:else>
    <title><data:blog.pageName/> - <data:blog.title/></title></b:else></b:if> 
 

Then your blog post page title will now be: "Name of my post that doesn't get cut off - My Wonderfully Great Blog."

2010-06-08

Building Clojure projects with Leiningen

When I first started learning Clojure, I had no idea the ecosystem it was situated in. C and C++ is situated in an ecosystem where there's make for managing the building of an application, and GCC for compiling the code. You can use a plain text editor to actually write the program if you like, there's a debugger GDB, and version control can be with CVS, Git, or whatever else. emacs is a plain text editor that also has the option of pulling together all these separate parts together to work as one integrated development environment.

Of course, nowadays people seem to like the whole IDE concept so much it's probably the most popular way to program (Apple Xcode, Eclipse, NetBeans, etc). For Clojure, you can use some of those IDEs too, eg, using NetBeans with the Enclojure plug-in.

If you like the "bag of separate tools" way (the "unix way") of programming, as I do and as I described for C at the beginning, then you'll like Leiningen - I think of it as a much better make, but for Clojure. It's documentation is sparse right now, so the following may help you.

2010-06-07

Namespaces in Clojure: How to use the multitude of ns options

Namespaces in Clojure allow you to use various options, like :require, :use, etc. The syntax of those isn't as well documented as I'd like though in the API documentation.

Stack Overflow again comes to the rescue with some good answers, distinguishing between using :use versus :require.

The syntax is easily understood by an example, like so:


(ns example-namespace.core
  (:gen-class)
  (:require [incanter
            [core :as i.c :only [col-names sel $ dim]]
             [io   :as i.io :only read-dataset]]
            [mmemail.core :as mail]
            [clojure.contrib
             [seq          :as c.c.seq :only positions]
             [except       :as c.c.except :only throwf]
             [json         :as c.c.json :only read-json]
             [command-line :as c.c.cmd :only with-command-line]]))

:use and :require has the same syntax, except the :as short-namespace-name is useless for :use since :use allows you access to the functions in that namespace without qualifying which namespace it's from.

The :only function-name and :only [fun1 fun2] parts says only the specified functions are being used in this namespace from the specified namespace.

The [package.name class1 class2] or alternatively [package.name [class1 :only fun1] [class2 :only fun2]] tells us which "classes" or specific namespaces are being used from the specified package of namespaces.

You need :gen-class if you want to one day compile and package your program for distribution as a Java jar.

There's a subtlety with having namespaces or packages with a dash in it as in example-namespace. See my previous post on namespaces for details.

2010-06-06

Building a Clojure app that handles command-line arguments

Clojure-contrib has a great package (clojure.contrib.command-line) that'll process command-line arguments for you so you don't have keep writing custom code to parse it yourself.

Only problem is the documentation is sparse, to say the least.

Look to Stack Overflow instead, where there's a great answer that's essentially the API's documentation.

2010-06-05

Leiningen 1.1.0 bugs

There's a pesky bug in Leiningen 1.1.0 right now. Actually two.

One attacks modules with dashes in their name (you should get a java.lang.NoClassDefFoundError error when you try to java -jar your-app.jar).

The second attacks when your Clojure program depends on a Java signed jar (you should get a Exception in thread "main" java.lang.SecurityException: no manifiestsection for signature file entry some/package/some.class).

Here's the workaround.

Let's say you have a project pesky-bug, and you build it into a standalone application using lein uberjar, which outputs a pesky-bug-standalone.jar.

Jar's are just zipped containers, so open it up as a zipped file. I use the Archive Manager in Ubuntu, which is great for this purpose.

Look for directory META-INF. Inside, there should be a file called MANIFEST.MF.  Both bugs will require you to fix this MANIFEST.MF file.

Mitigating new Adobe Flash, PDF 0day attack on Ubuntu Lucid

By now you'll have heard of the new 0day security vulnerability. So how to mitigate it? Two things, update to Flash Player 10.1 RC (I've wrote instructions on how last night), and disable Adobe Reader's access to Flash. Here's how to disable Reader's access to Flash on Ubuntu Lucid.

For Ubuntu Lucid, delete or rename these files (I had acroread installed via Synaptic Package Manager):

  1. /opt/Adobe/Reader9/Reader/intellinux/lib/libauthplay.so
  2. /opt/Adobe/Reader9/Reader/intellinux/lib/libauthplay.so.0.0.0
  3. /opt/Adobe/Reader9/Reader/intellinux/lib/librt3d.so

Note that Adobe Reader may crash when it tries to access Flash or 3D content, but that's the price of securing against Adobe's security bugs. Let's see how long it takes for them to fix it.

2010-06-04

Installing Flash 10.1 on Ubuntu Lucid for Firefox and Chrome

Adobe Flash Player 10.1 is still in beta, but it's the way to avoid the all new 0day security vulnerability in Flash Player 10.0.45.2. Here's how to install it on Ubuntu Lucid so that it works for both Firefox and Chrome.  Yes, Chrome recently started to bundle Flash Player within itself, but only for 32bit versions, so if you have 64bit Chrome for Linux you'll need the following too.
  1. Grab the Linux version of Flash 10.1 beta. After unzip and untar, you should have a libflashplayer.so
  2. Go to Synaptic Package Manager and install flashplugin-nonfree, which will set up all the directories for you
  3. Do the following to backup the old 10.0.45.2 version:
    • cd /usr/lib/flashplugin-installer/
    • sudo mv libflashplayer.so libflashplayer.so.old
    • sudo mv path/to/new/libflashplayer.so /usr/lib/flashplugin-installer/ (replacing "path/to/new/" obviously)
  4. You might want to sudo chown root:root libflashplayer.so as well
  5. To verify, just re-open your web browser and go to the Flash Player about page.  Look in the small "Version Information" box about center on that page to check
And that's it!  Now Chrome and Firefox will both get access to the newest Flash Player that's free of the pesky 0day security bug (or so Adobe says...their security track record is...disturbing).