Webapi core 2.1 and jQuery (CORS)

I’ve written before about Cordova, AngularJs, WebApi and CORS. (Cross Origin Resource Sharing) Now we have te same hurdle to take with our dotnet core 2.1 webapi.

Since the webapi is on a webserver and accessible to third parties we decided to keep the access fine grained. We will only allow CORS for GET operations on 1 resource. This can be achieved with policies. Below is the dotnet code to add the policy and use it only on the GET operation.

// add this to ConfigureServices
services.AddCors(o => {
    o.AddPolicy("AllowGet", builder => {
        builder.AllowAnyOrigin()    // allow everybody
               .WithMethods("GET")  // only allow GET
               .AllowAnyHeader()    // enable preflight
               .AllowCredentials(); // needed for auth
    });
});

// in the controller
[HttpGet]
[EnableCors(PolicyName = "AllowGet")]
public async Task<IActionResult> Get() {
    var result = "your data";
    return Ok( result );
}

Now that the webapi supports CORS we can call the GET from our page with jQuery.

$.ajax({
    type: "GET",
    url: url,
    crossDomain: true,
    cache: false,
    // needed for preflight
    xhrFields: {
        // needed for auth
        withCredentials: true
    },
    success: function (response) {
        // do something with response
    },
    error: function (response, status, error) {
        console.write(error)
    }
});
Posted in Development | Tagged , , , | Leave a comment

Installed macOS Catalina on my MacBook Early 2009

I still have my Early 2009 MacBook for my kids. It runs El Capitan and Windows 10 (bootcamp). Installation of macOS Catalina on my macbook 5,2 is unsupported. With the Catalina patcher from DosDude1 the installer can be tricked to allow installation.

Keep in mind that the software will be patched and the hardware remains the same. Catalina has features (continuity, handoff) that rely on certain hardware and will not be available. For Catalina to work I’ll need to patch the BootROM to enable booting from an APFS formatted disk – do this first!

After 2 hours my old MacBook showed the apple logo on a grey background. The progress bar hadn’t moved for some time, so I rebooted the machine. Turns out this is a bug reported on github (see references) and rebooting is the workaround 😉 I was greeted with the wizard to configure macOS Catalina and login to my iCloud.

macOS Catalina on macbook 5,2

The custom intel SSD supports TRIM. I enabled the TRIM support by running the following command and confirming the change:

sudo trimforce enabled

I noticed that the reboot took a long time. Also the next boot was slow. I booted from the Catalina patcher USB stick and applied the patches manually. Just before the reboot I enabled the checkbox Force Cache Rebuild.

force cache rebuild option in Post-install patches screen

Boot times are back to normal. I’ve only installed Daisydisk and Microsoft Team and both work fine.

Maybe upgrading the memory next time …

References

Posted in Uncategorized | Tagged , | 2 Comments

Working keyboard only

I’ve tried working keyboard only (no mouse) for two weeks and learned to live with shortcuts. Here are my tips-and-tricks.

my keyboard with shortcuts on Post-it notes

Just do it

Put your mouse out of reach. Disconnect it. Turn it off. Just do it.
You’ll feel helpless for a minute or two and then you start to learn how to do it.

Tools

My main computer is a MacBook. The tools listed below work on Apple machines.
Alfred helps me start my apps and automate a lot of steps. I added a script to connect to my AirPods with a command.
On my main monitor I remote desktop “full screen” into my work computer. With Amethyst I can switch the mouse focus between my two monitors. Only with the mouse focus on the right place I can use my keyboard for input …
Every application I use has different shortcuts. CheatSheet displays the shortcuts for the active app by long pressing ⌘

My company runs Windows machines. Sometimes Windows and MacOs have the same shortcuts. I run Autohotkey on Windows startup to blok Windows acting on ⌘+space (alfred) and ⌘+ctrl+c (Windows Color filter)

Other

I have an awesome Logitech K800 that has a dedicated key to toggle the mouse context menu. Sometime the context menu is easier than the shortcut.
Found this Post-it template so I can print my most used shortcuts on stickies. Download my shortcut post-it as pdf.
I Learned that navigating a webpage is easiest when searching for the text of the link and than hist ESC to see the link being selected. Now I can open the link with ENTER.

Image courtesy of ratch0013 / FreeDigitalPhotos.net
My journey continues. I’am not 100% mouse free, more like 95%. To setup the tools (alfred and amethyst) the mouse is needed – only once. Some websites and apps only work with use of the mouse (you know who you are)

Posted in Uncategorized | Leave a comment

Upgraded Windows 7 to 10 on my MacBook Early 2009

I still have my Early 2009 MacBook for my kids. It runs El Capitan and Windows 7 (bootcamp). Since the support for Windows 7 ended on January 14 2020 an upgrade was needed. Unfortunately the bootcamp 3 that comes with El Capitan doesn’t support any version higher.


Image from The Verge

A quick search on internet learned that upgrading Windows 7 to Windows 10 was easy. Just download the Media Creation Tool and download the bootcamp 4 zip for the updated drivers.

After 3 hours my old MacBook was running Windows 10 with the correct drivers. In the references all downloads are linked. The youtube link makes it dummy proof.
Maybe upgrading to macOS Catalina next time …

References

Posted in Uncategorized | Tagged , , , | Leave a comment

Bogus – testdata generator


Photo by Steve Harvey on Unsplash

https://www.nuget.org/packages/bogus

Creating testdata is not my favourite task. With bogus I can define the rules the data must adhere and generate as much data as I need.

The rules are setup with fluent syntax and reminds me of AutoMapper configuration. When you set the Randomizer the data can be generated inside your testcode and produce the same ‘random’ set of data every time.

Bogus.Randomizer.Seed = new Random(12345678);
Posted in Development, Tooling | Tagged , , , | Leave a comment