Joseph Michael Pesch
VP Programming

NgCore - Angular App with Dot Net Core

by 8. September 2019 12:57

Before getting started, I recommend looking at using https://cmder.net/ for Command Editor.  

Prerequisites:

  1. Angular installed globally: 
    npm install -g @angular/cli
  2. Visual Studio Code or Visual Studio Community (or other full version)
  3. Node.js v. 8.10.0 or higher (https://nodejs.org/en/download/) to check current version, run command: 
    node -v

Steps to create project:

  1. Create folder for the project, in my case "NgCore"
  2. Run the following command from within the project folder:  
    ng new NgCoreApp
  3. Run the following command from withing the "NgCoreApp" folder: 
    ng build
  4. Run the app from the "dist" folder (created by the "ng build")

Tags:

Angular | ASP.Net Core

https://cmder.net/

by 8. September 2019 12:54

Tags:

Tools

https://codechecks.io/

by 6. September 2019 06:20

Tags:

MacBook SSD Upgrade

by 28. August 2019 11:36

Tags:

Mac OS

HTML Textbox Auto Complete

by 15. August 2019 19:44

Tags:

HTML

Postman Collection Runner Save Response Body to Environment Variable

by 9. August 2019 08:14

First, create an environment variable called responseData, with the value [].

Then, add the following code under 'Tests' in Builder. Postman environment variables are intended to be used as string, so we will parse the object then push the JSON responses from the API into the object array.

var jsonData = JSON.parse(responseBody); var old = pm.environment.get("responseData"); old = JSON.parse(old); // filter jsonData if needed

old.push(jsonData); old = JSON.stringify(old); pm.environment.set("responseData", old); console.log(pm.environment.get("responseData")); Now you can retrieve a nested JSON object with all the response data included by viewing the environment variables value (see example below).

Warning: you must reset the responseData value as [] after every use of Collection Runner in order to avoid keeping data from previous runs.

Tags:

ffmpeg

by 21. May 2019 12:40

Tags:

Python Async without Await

by 19. May 2019 16:26

import asyncio
import time
 
async def px(x):
    time.sleep(5)
    print(x + ': ' + str(time.time()))
 
async def main():
    x = px('x')
    print("main1")
    y = px('y')
    print("main2")
    asyncio.ensure_future(y)
    asyncio.ensure_future(x)
 
asyncio.run(
    main())
    
input()

Tags:

Python

Google GSuite Drive File Stream

by 19. May 2019 10:12

 

Local Cache Location:

  • Win: %USERPROFILE%\AppData\Local\Google\DriveFS
  • Mac: ~/Library/Application Support/Google/DriveFS

Tags:

GSuite

Swift IOS UITableViewCell Button

by 5. January 2019 12:40

There are two steps to add a working button to a table view cell. The first step is to add a button like this:

cell.accessoryType = .detailDisclosureButton

The second step is to take action when the button is tapped by creating the accessoryButtonTappedForRowWith method:

override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    doSomethingWithItem(indexPath.row)
}

Tags:

XCode | iOS | Swift

xCode Support for IOS Device

by 24. November 2018 06:47

Trying to run xCode against connected iPhone and receive error message below:

Could not locate device support files. This iPhone 6s Plus is running iOS 12.0.1 (16A404), which may not be supported by this version of Xcode.

 

Download latest xCode from developer.apple.com (as .xip file), extract the .app file (https://developer.apple.com/download/more/)

Right click on latest xCode .app and select "Show Package Contents" and navigate to:

/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport

Select the required version(s) and copy to:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport

Look into this path as well: /Users/xxx/Library/Developer/Xcode/iOS DeviceSupport

Tags:

XCode

xCode Facebook Login Integration Using CocoaPods

by 18. November 2018 09:26

Terminal window, navigated to root folder where xCode project exists and run the following commands:

  • $ sudo gem install cocoapods
  • $ pod init

This will create a file named Podfile in your project's root directory. Open the Podfile with a text editor and add the following:

  • pod 'FBSDKLoginKit'

Back in the Terminal window, run the following command:

  • $ pod install 

Register app with Facebook (follow steps in this link: https://developers.facebook.com/docs/facebook-login/ios/)

Configure the information property list file (info.plist) with an XML snippet that contains data about your app. Right-click info.plist, and choose Open As Source Code. Copy and paste the following XML snippet into the body of your file ( ...)

<key>CFBundleURLTypes</key>
<array>
  <dict>
  <key>CFBundleURLSchemes</key>
  <array>
    <string>fb[APP_ID]</string>
  </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>[APP_ID]</string>
<key>FacebookDisplayName</key>
<string>[APP_NAME]</string>

To use any of the Facebook dialogs (e.g., Login, Share, App Invites, etc.) that can perform an app switch to Facebook apps, your application's info.plist also needs to include:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fbapi</string>
  <string>fb-messenger-share-api</string>
  <string>fbauth2</string>
  <string>fbshareextension</string>
</array>

Go to the Project Navigator in Xcode and select your project to see project settings. Select Other Linker Flags for editing. Add the flag -ObjC to Other Linker Flags for all build targets. NOTE: Use the find feature to easily locate the Other Linker Flags in the settins area.

If you still have the xCode project open close it. Open the new Workspace that should have been created in the same root folder as the project (e.g. MyApp.xcodeproj should now have a MyApp.xcworkspace partner).

Update the applications AppDelegate method to include the FBSDKLoginKit import reference and methods with FBSDKApplicationDelegate and FBSDKAppEvents (sample shown below).

import UIKit
import FBSDKLoginKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        // FaceBook
        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

        // FaceBook
        FBSDKAppEvents.activateApp()
    }
    
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
    }


    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

Build Project for Running to make sure everything compiles correctly.

 

Tags:

Facebook | XCode

Hosted Site Issues with Roslyn - This program is blocked by group policy. For more information, contact your system administrator

by 9. September 2018 12:24
NOTE: Had to remove package: Microsoft.CodeDom.Providers.DotNetCompilerPlatform
      Due to hosting limitation, throwing this error:
      This program is blocked by group policy. For more information, contact your system administrator
      Cannot execute a program. The command being executed was 
          "C:\InetPub\...\bin\roslyn\csc.exe" 
              /shared /keepalive:"10" /noconfig  
              /fullpaths @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\bd40b76f\3452b533\33n50imf.cmdline"
       
NOTE: See nuget url for package details:
      https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform
       
NOTE: Some of the new C# 6.0 language features if used in Views (MVC project) will not compile. 
      Many of my views use the ? null checking operator for accessing Model properties.  
      All of these views now return errors on my Godaddy hosted MVC 5 application.
      This error occurs because Views (by default) are compiled at runtime using the .NET pipeline (not pre-compiled).
      To resolve this issue, simply uncheck the "Allow precompiled site to be updatable" option in your publish profile settings.  
      This should pre-compile your views and allow your C# 6.0 (Latest version of Roslyn Compiler) to run like a champ.

Tags:

MVC

Angular 2 Compile Warning "Critical dependency: the request of a dependency is an expression"

by 28. February 2018 15:11

When compiling Angular 2 application I received compile warning "Critical dependency: the request of a dependency is an expression" when using the require() method with a variable vs. literal string value (see examples below).

 

This throws compile warning:

let path = 'path_to_item';

let item = require(path);

 

This does not throw compile warning:

let item = require('path_to_item');

 

Tags:

Angular

Angular Component StyleUrls Not Working

by 16. February 2018 15:08

Issue with component level styles not working, import "ViewEncapsulation: from @angular/core and add encapsulation: ViewEncapsoulation.None to the @Component decorator as shown below.

import { Component, OnInit, ViewEncapsulation } from '@angular/core';

@Component({

    selector: 'app-demo',

    templateUrl: './demo.component.html',

    styleUrls: ['./demo.component.css'],

    encapsulation: ViewEncapsulation.None

})

Tags:

Angular | JavaScript | TypeScript

JavaScript/TypeScript JSON Navigate by Dotted String Path

by 16. February 2018 15:00

Navigate a JSON object by a dotted string path (e.g. "somePath.subPath.anotherSubPath").

console.log('somePath.subPath.anotherSubPath'.split('.').reduce((o, i) => o[i], jsonObject));

Tags:

Angular | JavaScript | TypeScript

JavaScript/TypeScript Dotted String to Upper/Lower First Letter

by 16. February 2018 14:56

Take a dotted string (e.g. "someThing.someThingElse.another") and convert first letter of each dotted component to upper or lower case.

    dottedToUpper(str) {
        str = str.replace(/\./g, ' ');
        str = str.replace(/\w\S*/g, function (txt) {
            return txt.charAt(0).toUpperCase() + txt.substr(1);
        });
        return str.replace(/ /g, '.');
    }
    dottedToLower(str) {
        str = str.replace(/\./g, ' ');
        str = str.replace(/\w\S*/g, function (txt) {
            return txt.charAt(0).toLowerCase() + txt.substr(1);
        });
        return str.replace(/ /g, '.');
    }
 

Tags:

Angular | JavaScript | TypeScript

C# Name Tuple Items

by 1. February 2018 14:29

To name tuple items in C#, first install the NuGet package: Install-Package System.ValueTuple

Syntax: (string ItemName, DateTime ItemName, etc.) vs. Tuple<string, DateTime>

Tags:

ASP.Net | C#

Debug Windows Service Running as Interactive Console Application

by 1. February 2018 08:40

Before running in Visual Studio change the project output type from Windows Application to Console Application.  Below is sample Program.cs code to run interactively in Visual Studio.

using System;
using System.Reflection;
using System.ServiceProcess;
using System.Threading;

namespace DemoWindowsService
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] servicesToRun;
            servicesToRun = new ServiceBase[]
            {
                new DemoService()
            };
            if (Environment.UserInteractive) RunInteractive(servicesToRun);
            else ServiceBase.Run(servicesToRun);
        }

        static void RunInteractive(ServiceBase[] servicesToRun)
        {
            Console.WriteLine("Services running in interactive mode.");
            Console.WriteLine();

            MethodInfo onStartMethod = typeof(ServiceBase).GetMethod("OnStart",
                BindingFlags.Instance | BindingFlags.NonPublic);
            foreach (ServiceBase service in servicesToRun)
            {
                Console.Write("Starting {0}...", service.ServiceName);
                onStartMethod.Invoke(service, new object[] { new string[] { } });
                Console.Write("Started");
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(
                "Press any key to stop the services and end the process...");
            Console.ReadKey();
            Console.WriteLine();

            MethodInfo onStopMethod = typeof(ServiceBase).GetMethod("OnStop",
                BindingFlags.Instance | BindingFlags.NonPublic);
            foreach (ServiceBase service in servicesToRun)
            {
                Console.Write("Stopping {0}...", service.ServiceName);
                onStopMethod.Invoke(service, null);
                Console.WriteLine("Stopped");
            }

            Console.WriteLine("All services stopped.");
            // Keep the console alive for a few seconds to allow the user to see the message.
            Thread.Sleep(5000);
        }
    }
}

Tags:

ASP.Net | C# | Windows Service

Mac OS Mount Windows or NAS File Share Path Using SMB/CIFS

by 11. November 2017 10:58

To mount a Windows or NAS file share path you can use either SMB or CIFS.  If you have issues using SMB try using CIFS as some versions of Mac OS have issues with SMB but work fine with CIFS.  Open the Finder window and press CMD+K to open the "Connect to Server" window.  Enter the file share path as either smb://... or cifs://...

Tags: