Click here to Skip to main content
14,423,065 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.

 
GeneralMy very own accidental DoS program Pin
kmoorevs15-Jan-20 11:34
Memberkmoorevs15-Jan-20 11:34 
GeneralRe: My very own accidental DoS program Pin
Ron Anders15-Jan-20 16:46
MemberRon Anders15-Jan-20 16:46 
Generalpurchased code from who knows where Pin
rnbergren10-Jan-20 7:47
Memberrnbergren10-Jan-20 7:47 
GeneralRe: purchased code from who knows where Pin
ZurdoDev10-Jan-20 8:06
mveZurdoDev10-Jan-20 8:06 
GeneralRe: purchased code from who knows where Pin
phil.o10-Jan-20 8:29
mvephil.o10-Jan-20 8:29 
GeneralRe: purchased code from who knows where Pin
RickZeeland10-Jan-20 8:30
communityengineerRickZeeland10-Jan-20 8:30 
GeneralRe: purchased code from who knows where Pin
Eddy Vluggen15-Jan-20 13:01
mveEddy Vluggen15-Jan-20 13:01 
GeneralCross-Platform: dotnet core web api QR Codes Pin
raddevus30-Dec-19 11:00
communityengineerraddevus30-Dec-19 11: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 11:23
communityengineerRickZeeland30-Dec-19 11:23 
GeneralRe: Cross-Platform: dotnet core web api QR Codes Pin
Brisingr Aerowing10-Jan-20 11:34
professionalBrisingr Aerowing10-Jan-20 11:34 
GeneralRe: Cross-Platform: dotnet core web api QR Codes Pin
raddevus10-Jan-20 12:04
communityengineerraddevus10-Jan-20 12:04 
GeneralHead, meet desk Pin
Richard Deeming20-Dec-19 4:25
communityengineerRichard Deeming20-Dec-19 4:25 
GeneralRe: Head, meet desk Pin
Greg Utas20-Dec-19 5:47
professionalGreg Utas20-Dec-19 5:47 
GeneralRe: Head, meet desk Pin
ZurdoDev20-Dec-19 9:29
mveZurdoDev20-Dec-19 9:29 
GeneralWeird Performance PinPopular
Rick York18-Dec-19 11:11
mveRick York18-Dec-19 11:11 
GeneralRe: Weird Performance Pin
Nelek19-Dec-19 1:27
protectorNelek19-Dec-19 1:27 
GeneralRe: Weird Performance Pin
Rick York19-Dec-19 5:51
mveRick York19-Dec-19 5:51 
GeneralRe: Weird Performance Pin
Nelek19-Dec-19 9:38
protectorNelek19-Dec-19 9:38 
GeneralRe: Weird Performance Pin
Rick York20-Dec-19 9:13
mveRick York20-Dec-19 9:13 
GeneralRe: Weird Performance Pin
Nelek20-Dec-19 9:44
protectorNelek20-Dec-19 9:44 
GeneralHow many values between 0 and 0? Pin
raddevus16-Dec-19 6:59
communityengineerraddevus16-Dec-19 6:59 
GeneralRe: How many values between 0 and 0? Pin
Richard Deeming16-Dec-19 9:49
communityengineerRichard Deeming16-Dec-19 9:49 
GeneralRe: How many values between 0 and 0? Pin
raddevus16-Dec-19 9:58
communityengineerraddevus16-Dec-19 9:58 
GeneralRe: How many values between 0 and 0? Pin
TheGreatAndPowerfulOz16-Dec-19 10:05
MemberTheGreatAndPowerfulOz16-Dec-19 10:05 
GeneralRe: How many values between 0 and 0? Pin
raddevus16-Dec-19 10:21
communityengineerraddevus16-Dec-19 10: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.