Developer Blog

Tipps und Tricks für Entwickler und IT-Interessierte

Haskell | Getting Started

Readings

Haskell

Glasgow Haskell Compiler

Tutorials

Applications

Games

Installation

  • Install GHCup: Windows Binary is here
    GHCup is the main installer for the general purpose language Haskell.

Or install manuell

  • Download and Install Haskell here
choco install haskell-dev
refreshenv

Installation on Windows and Powershell

Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $true

First Steps

In order to run ghc and cabal, you need to adjust your PATH variable.

To do so, you may want to run 'source /d/CLOUD/Programmier-Workshops/Kurse/Haskell/Programme/Haskell/ghcup/env' in your current terminal
session as well as your shell configuration (e.g. ~/.bashrc).
Start a simple repl via:
  ghci

Start a new haskell project in the current directory via:
  cabal init --interactive

Install other GHC versions and tools via:
  ghcup list
  ghcup install <tool> <version>

To install system libraries and update msys2/mingw64,
open the "Mingw haskell shell"
and the "Mingw package management docs"
desktop shortcuts.

If you are new to Haskell, check out https://www.haskell.org/ghcup/steps/

Configuration

Cabal configuration file is by default located at

&lt;$ENV:USERPROFILE>\AppData\Roaming\cabal\config

Create your first project

Create a haskell project

cabal init
cabal build
cabal run

Configure VS Code with Haskell Support

Install required components

$ cabal install hlint

Configure VSCode

$ stack new vscode-haskell-config
$ cd vscode-haskell-config
$ stack setup

Install an additional source code formatter

$ stack install brittany

Anaconda | Getting Started

Updating packages

To check if any new update is available you can use conda update. If any update is available you can choose whether to install or not to install it.

You can use an Anaconda prompt or the terminal for the following steps: 

  • Update specific package: 
conda update package-name
conda update --all
  • Update all packages in the current environment: 
conda update -n myenv --all
  • 4. Update Python: 
conda update python

5. Update conda itself: 

conda update conda

F# – Snippets

Mathematics

Sum of Squares

dotnet new --install Fable.Template

Create an new App

dotnet new fable

Prepare environment

dotnet tool restore

Fix NodeJS SSL Error

$ENV:NODE_OPTIONS="--openssl-legacy-provider"

Install dependencies and run app

npm install
npm start

F# – Working with Fable

Get started

Install Fable with

dotnet new --install Fable.Template

Create an new App

dotnet new fable

Prepare environment

dotnet tool restore

Fix NodeJS SSL Error

$ENV:NODE_OPTIONS="--openssl-legacy-provider"

Install dependencies and run app

npm install
npm start

Storybook – Troubleshooting

Error: Resource busy or locked

When starting storybook with npm run storybook, you always get the error EBUSY: resource busy or locked

Solution: modify .storybook/main.js

You can fix this by adding the following to the file .storybook/main.js

module.exports = {
  ...
  managerWebpack: (config, options) => {
    options.cache.set = () => Promise.resolve();
    return config;
  }
}

Power BI Visuals | Cookbook

Installation

Install NodeJS

Install pbiviz

npm i -g powerbi-visuals-tools@latest

Calculating of Data

Working with Highlighted values (“supportsHighlight”: true)

sumOfValues     = Object.keys(node.values).map(key => +node.values[key].value).reduce((prev, curr) => prev + curr)
sumOfHighlights = Object.keys(node.values).map(key => node.values[key].highlight ? +node.values[key].highlight : null).reduce((prev, curr) => curr ? prev + curr : null)

Get all Level Names

matrix.rows.levels.map( l => l.sources[0].displayName).join('/')

Table Tooltips

Im Repository TableSorter

Useful functions

Calculate Average of Data Points

private calculateAverage(): number {
	if (this.dataPoints.length === 0) {
		return 0;
	}

	let total = 0;
	this.dataPoints.forEach((value: ICustomDataPoint) => {
		total += <number>value.value;
	});

	return total / this.dataPoints.length;
}

capabilities.json

Alignment

        "alignment": {
          "type": {
            "formatting": {
              "alignment": true
            }
          },
          "displayName": "Horizontal Alignment"
        },

Power BI Visuals | Migration Guide

DataViewObjectsParser
import DataViewObjectsParser = powerbi.DataViewObjectsParser;
import { dataViewObjectsParser } from "powerbi-visuals-utils-dataviewutils";
import DataViewObjectsParser = dataViewObjectsParser.DataViewObjectsParser;
TextProperties
import { textMeasurementService as tms } from "powerbi-visuals-utils-formattingutils";
import TextProperties = tms.TextProperties;
import { interfaces } from "powerbi-visuals-utils-formattingutils";
import TextProperties = interfaces.TextProperties;
textMeasurementService
import { textMeasurementService as tms } from "powerbi-visuals-utils-formattingutils";
import textMeasurementService = tms.textMeasurementService;
import { textMeasurementService } from "powerbi-visuals-utils-formattingutils";
valueFormatter
import { valueFormatter as vf } from "powerbi-visuals-utils-formattingutils";
import IValueFormatter = vf.IValueFormatter;

Flutter | Cookbook

Development Workflow

TL;DR

flutter create <app>
cd <app>
flutter run

Run App

flutter
flutter run --release .\lib\go_router.dart

VSCode and DevTools

Change default browser

Press F1, find Preferences: Open Settings (UI) then search for devtoolsbrowser.

Change in DevTools Menu

Working with Modules and Classes

Import all Modules from a Folder

Suppose you have a list of modules located in the folder models and you want to import all of them.

To do this

  • create a file index.dart which exports all files
  • in your dart file, import this index.dart
export 'counter.dart';
export 'number.dart';
import 'data/models/index.dart';

Create custom code for unsupported packages

Create main file to check, if package is available. If not, then switch to custom code

export 'unsupported.dart' if (dart.library.io) 'io.dart';

Use this file in your code

import 'plugins/desktop/desktop.dart';

Create files for supported and unsupported packages

io.dart

import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void setTargetPlatformForDesktop({TargetPlatform platform}) {
  TargetPlatform targetPlatform;
  if (platform != null) {
    targetPlatform = platform;
  }
  if (targetPlatform == null) {
    if (Platform.isMacOS) {
      targetPlatform = TargetPlatform.iOS;
    } else if (Platform.isLinux || Platform.isWindows) {
      targetPlatform = TargetPlatform.android;
    }
  }
  debugDefaultTargetPlatformOverride = targetPlatform;
}

unsupported.dart

import 'package:flutter/material.dart';

void setTargetPlatformForDesktop({TargetPlatform platform}) {}

Working with Themes

Using a Theme in MaterialApp()

return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData.light().copyWith(
        primaryColor: Colors.blue,
      ),
      darkTheme: ThemeData.dark(),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );

Working with CSS Colors

Import

import 'package:css_colors/css_colors.dart';

Usage

new Container(color: CSSColors.orange)

App Bar

How to remove a DEBUG Banner

MaterialApp(
  debugShowCheckedModeBanner: false,

  home: Scaffold(
    appBar: AppBar(
      title: const Text('Home'),
    ),
  ),  
);

Working With Data and Data Models

Replace Integer Variables with a Data Model

Examining the default Flutter App (Counter Sample), shows, that the real counter is implemented as integer with integer operations:

int _counter = 0;

void _incrementCounter() {
  setState(() {
    _counter++;
  });
}

If you want to customize the varianble and operations, you could replace the interger variable witrh your own data model

import 'data/models/counter.dart';

CounterModel _counter = CounterModel();

void _incrementCounter() {
  setState(() {
    _counter.add(1);
  });
}

The CounterModel is defined in data/models/counter.dart'

class CounterModel {
  int _value = 0;

  int get value => _value;

  void set(int val) => _value = val;
  void add(int val) => _value += val;
  void remove(int val) => _value -= val;

  void reset() => _value = 0;

  @override
  String toString() {
    return value.toString();
  }
}

Interesting Pack

device_preview