Click here to Skip to main content
15,887,683 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: My very own accidental DoS program Pin
John R. Shaw26-Mar-20 21:25
John R. Shaw26-Mar-20 21:25 
Generalpurchased code from who knows where Pin
rnbergren10-Jan-20 6:47
rnbergren10-Jan-20 6:47 
GeneralRe: purchased code from who knows where Pin
ZurdoDev10-Jan-20 7:06
professionalZurdoDev10-Jan-20 7:06 
GeneralRe: purchased code from who knows where Pin
John R. Shaw26-Mar-20 21:30
John R. Shaw26-Mar-20 21:30 
GeneralRe: purchased code from who knows where Pin
phil.o10-Jan-20 7:29
professionalphil.o10-Jan-20 7:29 
GeneralRe: purchased code from who knows where Pin
RickZeeland10-Jan-20 7:30
mveRickZeeland10-Jan-20 7:30 
GeneralRe: purchased code from who knows where Pin
Eddy Vluggen15-Jan-20 12:01
professionalEddy Vluggen15-Jan-20 12:01 
GeneralCross-Platform: dotnet core web api QR Codes Pin
raddevus30-Dec-19 10:00
mvaraddevus30-Dec-19 10:00 
I found a very cool library for creating QR Codes[^] from text input.

I decided I wanted to create a DotNet Core (3.1) WebAPI so I could see some (or all) of the QRCoder functionality in action.

However, I run Linux (Ubuntu) exclusively at home and Win10 at work.

The Premise
I wanted to know if I could create a DotNet Core project (using Visual Studio Code) that I could later 1) clone from GitHub (to my Linux box), 2) build and 3) run.

Visual Studio Code
Since it runs on both Win10 and Linux I knew I needed to use Visual Studio Code (instead of plain old Visual Studio). Of course, that also meant I'd need to run dotnet core command line.

I gen'd up a Web API project on the command line following this tutorial[^].

Basically just :
/> dotnet new webapi -o <PROJECT-NAME>
/> cd <PROJECT-NAME>


Then I was able to add the QRCode library from nuget via:
/> dotnet add package QRCoder --version 1.3.6


There was bit of a problem when I went to build, because even though I have dotnet 3.1 installed the qrcoder had a dependency on a newer system.drawing.common. Luckily at Nuget you can click the dependencies tab and see how to get that newer library like:
/> dotnet add package System.Drawing.Common --version 4.7.0


After that, everything built and worked. I added some URLs that allows the user to generate QRCodes as JPGs or as Ascii Text (see below).

Ok, ok, but what about Linux!?!

Building and Running On Linux
I went home, pulled my GitHub repo for the project[^] made sure my dotnet core installation was up to 3.1 and ran:

/> git clone href="https://github.com/raddevus/QRCodeGen"
/> cd QRCodeGen
/> dotnet restore -- restores all required libraries for project
/> dotnet build
/> dotnet run

The web api app started running on localhost:5001 and I made calls into the QRCoder API.
This is where the cross-platform part gets interesting.

Cross-Platform Gets Interesting
Now, think about this. The entire base Web API (built on top of MS libraries) runs and works properly even running on Linux.

The Catch
However, if you attempt to make a call to the QRCoder API that generates the QR Code as a JPG () it has a dependency upon a graphics library which is only compiled for Windows. That causes the QRCoder API to fail when running on Linux.

The error looks like this:
The type initializer for 'Gdip' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies.


However, since the QRCoder API call that generates the QR Code as ascii (see generated QR Code below - which is all ASCII chars) has no dependency upon Windows methods it succeeds with no problems, even on Linux.

Here's a snapshot of a call to the GetAsciiQR[^] via Linux command-line (curl) with the returned ascii QR code in the command-line window.

You can generate a QR Code with any message you like at my site, just change the value sent in to the API by changing inText in the following URL:
https://newlibre.com/QRCodeGen/QREncoder/GetAsciiQR?inText=try this

You can see the README which will lead you to sample links for all by going to :
https://newlibre.com/QRCodeGen/readme.htm[^]

PS - There's a secret message (all text based) in the QR Code. Laugh | :laugh:

██████████████      ████                ████    ██  ██████████████
██          ██  ████          ██    ██████      ██  ██          ██
██  ██████  ██        ██          ██    ██    ██    ██  ██████  ██
██  ██████  ██    ████  ████████████  ██    ██      ██  ██████  ██
██  ██████  ██  ██  ████      ██████  ████████████  ██  ██████  ██
██          ██    ████████████  ████          ████  ██          ██
██████████████  ██  ██  ██  ██  ██  ██  ██  ██  ██  ██████████████
                    ██  ████        ████  ██  ██
    ██  ██████  ██    ██        ████████████      ██    ██    ██
  ██  ██              ████  ██████  ██████████  ██  ██      ██  ██
    ██  ██  ████  ██    ████  ████  ██  ████████████  ████
████████      ██    ██████            ████      ████      ████  ██
██          ██████        ████  ██  ████  ██  ██    ██    ██  ████
██  ██  ████      ██████████      ████        ████████  ██  ██████
  ██    ██████  ████  ████  ██████  ██████  ██████      ██    ████
  ████  ████  ██████      ████  ██  ████  ██      ██  ██████████
████        ██  ████████  ████████  ████    ██        ████  ████
████  ██      ████  ████      ████  ██████    ██  ██      ████
      ████  ██    ██  ████  ████    ██    ██      ██        ██  ██
  ██    ████    ██        ██████        ████    ████      ██████
      ████  ██  ██    ████    ████        ████      ██████    ████
    ██    ██  ████  ████  ██  ██████          ████  ████      ████
████  ██    ██████  ██          ████  ████  ██  ██████    ████
██    ████    ██    ████  ██████████████  ████  ████      ████████
          ████████          ██  ████  ████    ████████████    ████
                ████  ██████      ██        ██████      ██    ██
██████████████        ████  ██████      ██      ██  ██  ██████  ██
██          ██  ████    ██████    ██████████    ██      ████  ██
██  ██████  ██  ██      ██    ████    ████  ████████████████████
██  ██████  ██    ██      ██  ██  ████      ██    ██    ██████
██  ██████  ██  ██  ██            ██      ██      ██    ████
██          ██    ████  ██████████  ████  ████    ████    ██
██████████████        ████    ████    ██  ██  ████    ████      ██


modified 30-Dec-19 16:08pm.

PraiseRe: Cross-Platform: dotnet core web api QR Codes Pin
RickZeeland30-Dec-19 10:23
mveRickZeeland30-Dec-19 10:23 
GeneralRe: Cross-Platform: dotnet core web api QR Codes Pin
Brisingr Aerowing10-Jan-20 10:34
professionalBrisingr Aerowing10-Jan-20 10:34 
GeneralRe: Cross-Platform: dotnet core web api QR Codes Pin
raddevus10-Jan-20 11:04
mvaraddevus10-Jan-20 11:04 
GeneralHead, meet desk Pin
Richard Deeming20-Dec-19 3:25
mveRichard Deeming20-Dec-19 3:25 
GeneralRe: Head, meet desk Pin
Greg Utas20-Dec-19 4:47
professionalGreg Utas20-Dec-19 4:47 
GeneralRe: Head, meet desk Pin
ZurdoDev20-Dec-19 8:29
professionalZurdoDev20-Dec-19 8:29 
GeneralWeird Performance PinPopular
Rick York18-Dec-19 10:11
mveRick York18-Dec-19 10:11 
GeneralRe: Weird Performance Pin
Nelek19-Dec-19 0:27
protectorNelek19-Dec-19 0:27 
GeneralRe: Weird Performance Pin
Rick York19-Dec-19 4:51
mveRick York19-Dec-19 4:51 
GeneralRe: Weird Performance Pin
Nelek19-Dec-19 8:38
protectorNelek19-Dec-19 8:38 
GeneralRe: Weird Performance Pin
Rick York20-Dec-19 8:13
mveRick York20-Dec-19 8:13 
GeneralRe: Weird Performance Pin
Nelek20-Dec-19 8:44
protectorNelek20-Dec-19 8:44 
GeneralHow many values between 0 and 0? Pin
raddevus16-Dec-19 5:59
mvaraddevus16-Dec-19 5:59 
GeneralRe: How many values between 0 and 0? Pin
Richard Deeming16-Dec-19 8:49
mveRichard Deeming16-Dec-19 8:49 
GeneralRe: How many values between 0 and 0? Pin
raddevus16-Dec-19 8:58
mvaraddevus16-Dec-19 8:58 
GeneralRe: How many values between 0 and 0? Pin
TheGreatAndPowerfulOz16-Dec-19 9:05
TheGreatAndPowerfulOz16-Dec-19 9:05 
GeneralRe: How many values between 0 and 0? Pin
raddevus16-Dec-19 9:21
mvaraddevus16-Dec-19 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.