Categories
Uncategorized

Notes on Asperger Syndrome and Long-Term Relationships

This is an old read, decided to go through and skim it again to see if any of my thoughts have changed over time – I found that a lot of the things I highlighted from before, no longer apply. Maybe over time, things have just improved.

As I read this, I think about how a lot of the things mentioned about those with mild autism exhibit traits like:

  • Preference for structure
  • Depth over variety
  • Difficulty in social situations

A lot of these things sound like something an introverted person would prefer. Maybe just a correlation there.

The book mostly focuses on marriages between an Aspie and Neurotypical, and reads to the neurotypical. The variation is major, showing scenarios where the AS partner is pretty reasonable, and then having them be very hard to deal with.

Some other takeaways:

  • Aspies tend to stick with their first impression (I find this accurate)
  • Having a home is important for an Aspie, as it serves as a place of comfort.
  • The focusing tendencies of an Aspie makes for a double edged sword – easy to choose a single direction and move forward, but can cause tunnel vision.
  • Aspies don’t have a strong drive for socialization – which leads to a drive for less social activities.
Categories
Uncategorized

Automatically Apply EF Core Database Migrations in Azure Function App on Startup

To apply database migrations to an Azure Function app on startup, you’ll need to have the following set up first:

Once the above is set up, you can set up the application to apply all migrations on startup, making for a link between the running application and the database it is dependent on. This is especially useful for local development – as you won’t run into cases where a local schema is outdated.

Add the following code to the Startup.cs file:

...

[assembly: FunctionsStartup(typeof(YOUR_NAMESPACE.Startup))]

namespace YOUR_NAMESPACE
{
  class Startup : FunctionsStartup
  {
    public override void Configure(IFunctionsHostBuilder builder)
    {
      ConfigureDatabase(builder);
      ...
    }

    private void ConfigureDatabase(IFunctionsHostBuilder builder)
    {
      string SqlConnection =
                    Environment.GetEnvironmentVariable(
                      Constants.ConnectionStringKey);

      if (SqlConnection == null)
      {
        throw new ArgumentNullException(
          $"Environment variable {Constants.ConnectionStringKey} not set.");
      }

      builder.Services.AddDbContext<Context>(
        options => options.UseSqlServer(SqlConnection));

      var optionsBuilder = new DbContextOptionsBuilder<Context>();
      optionsBuilder.UseSqlServer(SqlConnection);

      using (var context = new Context(optionsBuilder.Options))
      {
        try
        {
          context.Database.Migrate();
        }
        catch (Exception e)
        {
          throw new Exception(
            $"Error when migrating database: {e.Message}");
        }
      }
    }
  }
}
Categories
Uncategorized

Checking Validity of a Private Key, CSR and Certificate

If you’re working with a certificate and need a means to check if the combination of the private key, CSR and certificate are all matching, you can run the following OpenSSL commands:

To check the private key:

openssl rsa -modulus -noout -in YOUR_KEY.pem | openssl md5

To check the CSR:

openssl req -noout -modulus -in YOUR_CSR.csr | openssl md5

To check the certificate:

openssl x509 -modulus -noout -in CERTIFICATE.crt | openssl md5

With each of these commands, you will have a value generated besides the (stdin) declaration, which needs to match across all of the different types to show compatibility.

Categories
Uncategorized

Copying a nopCommerce Environment

Copying a nopCommerce environment to a destination such as your local machine or to another environment requires two major steps:

  • Copying the database
  • Cloning the source code and configuring to use the copied database

Copy The Database

  1. Using SSMS, log in to the source database server using administrative credentials (usually the remote environment).
  2. On source database server, right-click on database and click Tasks -> Export Data-tier Application
  3. Save the .bacpac file to the destination machine.
  4. Connect to the destination database server (usually local).
  5. Right-click ‘Databases’ on the destination server and click ‘Import Data-tier Application’.
  6. Use the .bacpac file created from the source database.

Copy and Configure the Source Code

  1. Clone the source code to the destination machine.
  2. Create the /Presentation/Nop.Web/App_Data/dataSettings.json file with the following content:
{
  "DataProvider": "sqlserver",
  "DataConnectionString": "Data Source=<YOUR_DB_SERVER_NAME>;Initial Catalog=<YOUR_DB_NAME>;Integrated Security=True;",
  "RawDataSettings": {}
}

Example:

{
  "DataProvider": "sqlserver",
  "DataConnectionString": "Data Source=localhost\\SQLEXPRESS;Initial Catalog=uesaka;Integrated Security=True;",
  "RawDataSettings": {}
}

Next, verify the site can be accessed.

Finally, make sure to change the store URL to the new URL being used.

Troubleshooting with Nop-templates

If you’re using nop-templates, you’ll run into some issues when trying to copy.

I had to delete all contents from the following SQL table:

delete from SS_C_Condition

Of course, this currently disables all HTML Widgets – so there must be a better way to do this. Take a look at https://www.nopcommerce.com/boards/t/50457/adding-or-editing-quick-tab-item-with-same-key-already-added.aspx

Categories
Uncategorized

Converting nopCommerce to Store Images In Filesystem Instead of Database

By default, nopCommerce stores all of the images in the database, making for simple access. However, with a lot of images, this puts a lot of load on the database, alongside making for a larger database to maintain.

Some research shows that the performance doesnt differ greatly between the two options, but here’s a few reasons you might use either:

Storing in Database

  • Allows for easier backups & environment clones (only need to clone codebase and DB)
  • Single place for image storage (useful with multiple systems)

Storing on Fileserver

  • Separates large portion of data from DB (allows for smaller DB)
  • Lowers load on DB server.

First, back up your database – since this is a process that can cause major issues if something were to go wrong (or if you decide to revert back to storing images in the database).

To convert from storing images in the database to the file server, go to Admin -> Settings -> Media Settings. Click on ‘Change’:

After the conversion completes, nopCommerce will automatically convert all images into the /Content/Images folder. You’ll also notice the binaries no longer being stored in the Picture table.

Shrink Database

Once this is done, you have the potential to open a good amount of space on the database, since the binaries of the images are now stored on the fileserver themselves.

To reclaim this space, you’ll need to shrink the database. Run the following command in SQL:

DBCC SHRINKDATABASE (YOUR_DB, 10);
GO
Categories
Uncategorized

Set up Pi-Hole to Block Ads at the Network Level

You can use a Respberry Pi to block all ads coming in at a DNS level

Requirements:

  • CanaKit (provides Raspberry Pi, Power Supply)
  • Short ethernet cable
  • Monitor and keyboard for initial setup

Raspberry Pi Initial Installation and Configuration

Assemble and then plug in the Raspberry Pi, which should take you to the NOOBS setup window.

Install Raspbian, and work through until you get to the desktop screen for the Raspberry Pi.

Router Configuration

With the Raspberry Pi configured, connect to your router admin page and find the IP address of the Raspberry Pi. Assign a static IP to the Raspberry Pi.

Pi-Hole Installation

On the Raspberry Pi, run the following commands to start installation:

wget -O basic-install.sh https://install.pi-hole.net
sudo bash basic-install.sh

When asked for Upstream DNS Provider, select Cloudflare.

For everything else, just select the default options.

After installation finishes, you’ll be able to log into the web admin with the password provided at the end of installation.

You may want to change the password used to login, you can run the following command on the Raspberry Pi:

pihole -a -p

Pi-Hole Configuration

Access the web interface using http://<IP_ADDRESS>/admin, and log in using the password above.

Change the DNS server on your router to the IP address above.

Verification

An easy way to verify is to check a page that uses ads (here’s a good example). See if any ads appear, and then check the Pi-Hole admin:

Reference

https://kb.netgear.com/25722/How-do-I-reserve-an-IP-address-on-my-NETGEAR-router

https://cleanbrowsing.org/guides/cleanbrowsing-netgear-orbi-dns-configuration

Categories
Uncategorized

Changing Default Token Expiration for Azure AD

To change the default token expiration timeframe when using Azure AD for authentication, you can do the following.

First, if you haven’t yet, install the AzureADPreview PowerShell Module:

Install-Module AzureADPreview

Now, connect to Azure AD using an account that has access to manage App Registrations:

Connect-AzureAD

After that, check and delete any policies that currently exist

After that, create a new policy (this one is set for 30 minutes as an example):

$policy = New-AzureADPolicy -Definition @('{"TokenLifetimePolicy":{"Version":1,"AccessTokenLifetime":"00:30:00","MaxAgeSessionSingleFactor":"00:30:00"}}') -DisplayName "CustomPolicy" -IsOrganizationDefault $false -Type "TokenLifetimePolicy"

And apply that policy to the service principal tied to the Azure AD integration:

$sp = Get-AzureADServicePrincipal -Filter "DisplayName eq '<service principal display name>'"

Add-AzureADServicePrincipalPolicy -Id $sp.ObjectId -RefObjectId $policy.Id

Now verify that the policy is in place:

Reference

https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-configurable-token-lifetimes

Categories
Uncategorized

Converting P7B Certificates into PFX Certificates

To convert a P7B certificate into a PFX certificate, you’ll need the following:

  • The .p7b certificate created after the CSR is generated.
  • The private key (likely .pem or .key) generated when generating the CSR.

First, doublr click the .p7b file and export out all of the certs that appear in Certificate Manager as Base64 encoded .CER files:

Once this is done, you’ll be able to create the .PFX file with the following openssl command:

openssl pkcs12 -export -in certificatename.cer -inkey privateKey.key -out certificatename.pfx -certfile cacert1.cer -certfile cacert2.cer 
Categories
Uncategorized

Generating CSRs the Easy Way In Windows

First, download the DigiCert Certificate Utility.

Afterwards, click on “Create CSR”, and fill out the appropriate information to generate the CSR.

Accessing the Private Key for the CSR

When a CSR is generated, there is a private key that associates with the CSR (and eventual certificate). You can access this in certmgr.exe:

To get the private key, go to ‘All Tasks’ -> ‘Export’ and export the private key as needed. Windows will export it as a .pfx file, which you can convert using openssl:

openssl pkcs12 -in exported_cert.pfx  -nocerts -out key.pem

When requested for the password and PEM passphrase, use the password provided in the export step above.

Categories
Uncategorized

Adding Icons to an Angular Web Site

Changing out the icons for an Angular website is just a few steps. This guide assumes you have an icon already in place, preferably in PNG format.

First, use a tool like Real Favicon Generator to create the source files, which will include a favicon.ico file alongside a series of apple-touch-icon* files. Add these files to the /src directory.

After that, make the following change to your index.html file:

<head>
    ...
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
    <link rel="manifest" href="/site.webmanifest">
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="theme-color" content="#ffffff">
</head>

And finally make the change to angular.json to ensure the files are delivered correctly on build:

"assets": [
            ...
            "src/android-chrome-192x192.png",
            "src/android-chrome-512x512.png",
            "src/apple-touch-icon.png",
            "src/browserconfig.xml",
            "src/favicon-16x16.png",
            "src/favicon-32x32.png",
            "src/mstile-150x150.png",
            "src/safari-pinned-tab.svg",
            "src/site.webmanifest"
          ],

To test that everything worked successfully, make sure to run a build:

ng build

After this finishes, check the /dist folder to see the icon files added in the step above.