Sunday, June 23, 2024

Takeaways: Ultralearning by Scott H Young

The more we learn the more we realize how much we don't know - Albert Einstein

Principles:

Metalearning

  • Understanding how to learn, observing seniors or leads to see how they learn, and adopting their techniques.
  • Setting up the best conditions to learn, being adaptable, and being willing to adjust your learning process.
  • Creating a plan for learning.

Focus

  • The ability to sustain interest and persistent attention.
  • Training to control your focus, using the Pomodoro technique, and attention management.
  • Limiting yourself from distractions to enable deep work.
  • Practicing deliberately and pushing your limits.

Directness

  • Learning by doing.
  • Achieving immersion or getting your hands dirty.
  • Applying knowledge directly; avoid getting lost in theory, practice what you learn.
  • Providing someone with a feature, but be careful not to provide something so overwhelming as to decrease the chance of demoralization.

Drill

  • Engage in focused practice by working on specific parts of the subject matter.
  • Explore different scenarios within a particular area of the subject to deepen understanding.
  • Emphasize repetition to solidify skills and knowledge.

Retrieval

  • Attempt to recall information mentally before resorting to looking it up; self-test to gauge learning.
  • Encourage independent problem-solving by not providing all the answers upfront.
  • Utilize simulations to apply knowledge in practical settings.
  • Implement spaced repetition to enhance long-term memory retention.

Feedback

  • Seek out individuals who can provide accurate and constructive feedback.
  • Participate in code reviews and catalytic coaching for professional development.
  • Remember that feedback can come from various sources, including AI or code analyzers, not just people.

Retention

  • Employ mnemonic devices, visualizations, and associations to memorize patterns and concepts.
  • Conduct regular reviews to reinforce learning and prevent forgetting.
  • Recognize the importance of recovery, such as getting adequate sleep, for memory consolidation.

Intuition

  • Cultivate intuition by consistently writing or documenting key learnings.
  • Enhance understanding by teaching the subject matter to others through brownbag sessions or demonstrations.
  • Recognize that intuition grows with experience; it enables seasoned professionals to envision a broader range of solutions to problems compared to novices.
  • Develop intuition through experience and pattern recognition, which allows for quicker and more effective problem-solving.

Experimentation

  • Integrate all ultralearning principles to synthesize knowledge and combine skills for a comprehensive learning experience.
  • Apply what you’ve learned by undertaking projects, which serve as practical tests of your new skills.
  • Embrace an iterative process: refine your approach, learn from mistakes, and iterate to achieve mastery.

Fostering an Ultralearning environment

Create an inspiring goal

  • Establish a compelling goal to ignite motivation, sustain persistence, and provide clear direction.
  • Goals should be well-defined, specific, measurable, and time-bound to ensure they are actionable and trackable.

Be careful with competition

  • Embrace positive competition as it motivates us to excel and elevate our standards.
  • Be cautious of negative competition, which can induce stress, anxiety, and burnout, potentially shifting focus from learning to merely outperforming others.
  • Prioritize areas where competition fosters personal growth and encourages collaboration.

Learning is the priority

  • Recognize that prioritizing learning leads to increased efficiency as we refine our methods over time.
  • Dedicate time specifically for learning and ensure it is used effectively with focused attention.
  • Learning enhances our ability to adapt swiftly, embrace new methodologies, and revise strategies as needed.
  • Implement time blocking, engage in regular reflection, and remain adaptable to maintain a productive learning environment.


References:
https://www.scotthyoung.com/
https://www.scotthyoung.com/blog/ultralearning/


Thursday, June 13, 2024

AI: A Threat or an Opportunity for Software Engineers?


As a software engineer, you’ve likely encountered AI-powered chatbots that can generate entire code snippets and implementations. It’s natural to wonder: Will AI eventually replace human software engineers? In this essay, we’ll explore both sides of the debate, considering how AI can either supplant or empower our roles in the ever-evolving tech landscape.

The Arrival of AI-Powered Chatbots
In 2022, AI-powered chatbots made their debut. As a seasoned software engineer, I initially questioned their necessity. After all, I’d successfully relied on Google, Stack Overflow, community groups, and blogs for over two decades. But gradually, my colleagues—both current and former—sang the praises of these chatbots. Their productivity gains were undeniable, so I decided to give them a shot.

Reference Tool Overload
I fired up one of the more renowned chatbots and began asking coding-related questions. First, I had an old code snippet in an outdated framework. Could the chatbot interpret it for modern frameworks? It generated an output, I tested it, and—lo and behold—it worked! Encouraged, I asked it to translate the code to another programming language. Again, it provided a solution, and it worked seamlessly. My initial reaction: sheer amazement. Suddenly, I could tackle not only simple projects but also complex ones. It felt like trading in an axe for a chainsaw.

AI vs. Software Engineers: The Memes
Then the memes surfaced: “AI will replace software engineers!” Some were amusing, but others revealed a lack of understanding. Yes, AI-powered chatbots churn out code—sometimes more advanced than what we write—but they’re still just pieces of the puzzle. It’s up to us humans to assemble those pieces into a cohesive project. The best solutions emerge from our collective expertise, creativity, and problem-solving skills.

So are software engineers going to get replaced by AI-powered chatbots? I don’t think so. Instead, this technology reinforces software engineers of this era to build more complex and advanced projects. It’s akin to people from the old age finding tools to create more sophisticated products—from wheelbarrows to tractors. It still takes a human to think of ideas or inventions, and with these tools, we push forward beyond our previous limitations.

Monday, April 13, 2020

Creating a simple Console App that Uses Entity Framework Core

This post is a step by step guide in creating a simple Console App that used Entity Framework Core 3.1 (latest version as of the moment). The IDE we are using is Visual Studio 2019. The database we will be using is for SQL Server.

1. Create a blank solution, we can do this by clicking on the Create a new project on the Visual Studio 2019 home/welcome screen.

2. On the Create a new project screen, we can type in "Solution" on the search box, select the Blank Solution option then click on the Next button found at the bottom right of the screen. 

3. Enter a solution name and select a folder to where the solution file would be saved.

4. Now that we have the solution let's add a new project, we can do this by right-clicking on the Solution Explorer pane, select Add then New Project.

5. First we create a C# Class Library project, type in "Class Library" for the Entity Framework Core data classes. You can enter your specific name for the class library. You can delete the auto-added Class1 class file as we are not going to use that.

6. Then let's create a new Class Library project for the Domain/Entities, this time you can select the Class Library from the Recent project templates
7. We then add the console app that would implement the domain service. On the Add new project screen, let's search for the C# Console app

8. Now that we have all our needed projects, let's add the project references of the Domain/Entities and Data projects to the Console App. On the console app tree,right-click Dependencies then click on Add Reference. Check the two projects there.
9. We also need to add a reference of the Domain/Entities project to the Data project, as we would be using the entities there to build our DbSets. DbSet class is used to perform the Create/Read/Update/Delete (CRUD). They are used to map the tables to the database.

10. We then need to install the Entity Framework Core packages as they are not added by default. We can do this by using the Package Manager console or the Manage NuGet Packages option, we are going to use the latter.

11. Right-click on the Data project, then select Manage NuGet Packages.

12. On the NuGet Package screen click on Browse, as this would allow us to search online for the package then on the search textbox enter "EntityFrameworkCore.SqlServer". This is the option that we will also choose as this would install all the required EF Core packages we need as well. Select the latest stable version then click on Install


13. We should now have the three EF Core packages installed on the Data class library:
  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.Relational
  • Microsoft.EntityFrameworkCore.SqlServer
14. Next up, we are going to add some sample Entities on our Domain class library:
  • ProductCategory
  • Product



This entities would represent the our database tables, notice on the Product class we added a reference to the ProductCategory, now EF Core is smart enough to determine the relationships between the classes and also the primary key it would use for the tables it would generate.

15. Next we need to add a Context class in our Data class library. This class is would let EntityFramework know which entities represents a table in our database. We define them by using the DbSet type ex. DbSet<ProductCategory> ProductCategories.


16. Now we implement this on our Console App. We also need to make sure that our Console App is the starting project, you can do this by right-clicking on the project and clicking on Set as Startup Project

Our Main.cs class code


EnsureCreated() makes sure that the Database and tables are already created in our DB, if not this execution would create them.

17. Now we execute the code by clicking on F5 or ctrl + F5 (No debugging). The initial loading should take a while as EF Core would be generating the database scripts first based on the DbSets we have. Then it would use them to create the database and tables based on the connection string we have set. You should get the results below: 


18. If you would check your database using SQL Server Manage Studio, you should be able to see your DB and table there:

19. As you can see from the Main class code, working on database is just like using collections and linq. For more information about Entity Framework Core, you check on the Microsoft Documentation site for it:

Happy coding!

Thursday, August 1, 2019

Content Security Policy Basics

What is Content Security Policy (CSP)?

Response headers that allows web site administrators to control which resources are loaded on a given page. We control this by setting policies structured below:
Content-Security-Policy: <policy-directive>; <policy-directive>
The following example creates a default source to 'self' (server origin) and a style-src to 'self' and allows any css loaded from a somedomain.com domain:
Content-Secuirty-Policy: default src 'self'; style-src 'self' *.somedomain.com;

What is Cross-Site Scripting (XSS)?
Cross-SIte Scripting, is a client-side code injection attack. One type of vulnerable a page has to this kind of attacks if it does not validate or encode text that is entered to it's input control. With this a hacker can input a malicious script on the text then when saved and loaded back, the page would then execute that script.

Types of XSS Attacks

  • Embedding of External Resources on the Page
  • Writing Scripts to the Page Source
  • Modifying the Document Object Model (DOM)
Please find link on the References section below for more information about Cross-Site Scripting.

Commonly Used Directives

Policy Directive
Description
default-srcThis directive contains the default values, for example if script-src is not specified, it used what is set on the default-src
script-srcThis directive controls the script resources locations (.js files), if we have referenced remote scripts we can specify the url for that on this directive
style-srcThis directive controls the style resources locations
object-srcThis directive controls being loaded on the page ex. flash
media-srcThis directive controls the media resources being loaded ex. mp3
frame-ancestorsThis directive controls which sources can load the page into a child frame

For other directives please refer to the link found on the References section below

Built-in Directive Values

Source Name
Description
'self'Refers to the origin from which request/response is being served. This allows all scripts from the origin server.
'none'Explicitly disallow script sources
'unsafe-inline'
Allows scripts that are coded in-line:
ex: <button id='sampleId' onclick='confirm('are you sure?')' />
'unsafe-eval'
Allows scripts that use the eval() method, which creates javascript code from strings
ex: var value = eval(new String(a + b))

Monday, October 8, 2018

Angular CLI Primer

What is Angular CLI?

Angular Command Line Interface, makes it easy to create an application that works and follows best practices right out the box.
It takes care of most of managing the dependencies and boiler plate code when creating Angular projects.


Requirements 

  • Node (Version  8 or higher)
  • NPM (usually bundles with node, version 5 or higher)
  • Code editor tools (ex. Visual Studio Code)


Checking for node version:

> node -v

Checking npm version

> npm -v

Installing Angular CLI

> npm install -g @angular/cli


Creating a new application

> ng new application_name

Some Useful Options Flag

  • --help This applies to almost all, if not all, the command line interfaces used
  • --dryRun or -d Displays files that would be generated when running the cli command
  • --directory Specifies directory to where the application would be generated
  • --skip-install Skips installation of dependency packages

Running the application

> ng serve -o



References

Friday, August 17, 2018

SOLID Principles in OOP

(S)ingle Responsibility Principle
This states that a class should only have a single responsibility.

(O)pen Closed Principle
Open for extension and closed for modifications.

(L)iskov Substitution Principle
Objects should be replaceable with instances of their subtypes

(I)nterface Segregation Principle
Many client-specific interfaces are better than one general-purpose interface

(D)ependency Inversion Principle
Depend upon abstractions, not concretions



Reference
https://en.wikipedia.org/wiki/SOLID

Entity Framework Core Notes Part 1

We execute command line commands to add/update database or to generate model from a database.
We can either execute them on the command line,  powershell or Visual Studio's package manager console.

On previous versions of Entity Framework, we need to execute the command below to setup migrations on the project, to create the migrations folder:

> enable-migrations 

This is already considered obsolete in Entity Framework Core. The Add-Migrations script automatically creates for you the migrations folder, unless you have specified it explicitly with specific command line parameters.


Commands (Package Manager Console):

Adding migration scripts to the project.

> Add-Migration

Specifying a Migration name

> Add-Migration MyFirstMigration

Specifying a Migrations output directory

> Add-Migration MyOtherMigration -OutputDir OtherMigrationsDirectory

Targeting a Project for Migration

> Add-Migration SpecifiedProjectMigration -Project OtherCodeFirstProject

Applying the Migration scripts to the Database

> Update-Database

The following command removes the previous Migration

> Remove-Migration


Creating your models from an existing database


> Scaffold-DbContext "<ConnectionString>" Microsoft.EntityFramework.SqlServer -OutputDir Models

Thursday, August 9, 2018

Entity Framework Core 2.1 Package Installation

Entity Framework Core Packages
On your project install the following NuGet Packages


  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.Design
  • Microsoft.EntityFrameworkCore.Relational
  • Microsoft.EntityFrameworkCore.SqlServer  -- Provider based
  • Microsoft.EntityFrameworkCore.Tools -- (optional)

Installing the packages using Package Manager Console (Tools > NuGet Package Manager > Package Manager Console)
  1. Make sure you are in the correct directory by typing in dir then press enter.
  2. Install-Package <Package Name> 

Installing the packages using Visual Studio's NuGet Package Manager
  1. Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution
  2. Search for Microsoft.EntityFrameworkCore

Installing the packages by editing the Project (Visual Studio 2017)

Another way of installing the EF packages is by editing the project. Paste in the following inside the <Project> scope.

<ItemGroup>
   <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.3" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.3" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.3" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.3" />
</ItemGroup>

Save project then on the Package Manager Console, enter the command below to restore the packages to the project:

> dotnet restore

Wednesday, July 25, 2018

TypeScript Fields

Just like regular OOP classes, you can define fields in a Typescript class. On the next section are samples on how you define them.

By default access modifiers on the fields are public, however you can explicitly set it to private or public.


class SampleFields {
id: number;
name: string;
description: string;
}

On the above example, field types are explicitly set.

A similar C# class would look like the following:

public class SampleFields
{
    public int id;
    public string name;
    public string description;
}

Do note that type can be inferred:

class SampleFields {
id = 0;
name = "";
description = "";
}


Fields can also be defined on the constructor:

class SampleFields {
constructor (public id = 0, public name = "", public description = "") {
}
}
or
class SampleFields {
constructor (public id: number, public name: string, public description: string) {
}
}

This is called shorthanding

The following statement would only set the fields as local to the constructor block, thus is different from the examples above.

class SampleFields {
constructor (id: number, name: string, description: string) {
}
}

Do note that when accessing class scoped fields, we need to use the this keyword

class SampleFields {
constructor (public id: number, public name: string, public description: string) {
}

setFields() {
this.id = 1;
this.name = "SomeName";
this.description = "Some Description";
}
}


This is it for Typescript fields for now, do leave me a comment if you have corrections or questions.

K, Bye!

Friday, September 22, 2017

TypeScript Setup for Visual Studio Code

  1. Go to https://nodejs.org/

  2. Download the installer you wish to install.
  3. Run the installer

  4. Open either command prompt or powershell and type in (-g parameter means global):
    npm install -g typescript

  5. To verify that we have installed TypeScript successfully, type in the following in powershell:
    tsc --version
  6. Open Visual Studio Code
  7. Add a TypeScript configuration file (tsconfig.json) to the folder. A sample TypeScript config file can be found on the Visual Studio Code site: https://code.visualstudio.com/docs/languages/typescript

  8. Now let's add a Type script file, add a HelloWorld.ts file
  9. Place in the following code:
    export class HelloWorld {
    shout() {
    console.log("hello world");
    }
    }

    let helloWorld = new HelloWorld();
    helloWorld.shout();
  10. Click on Task -> Run Build Task


  11. Select tsc: build - tsconfig.json



  12. Open windows powershell, go to file folder and type in the following:
    node helloWorld.









Sunday, September 16, 2007

Finalize vs Dispose

In my opinion the difference between "Finalize" and "Dispose":

  • Finalize is always called by the GC, so we could never determine when this would happen.
  • Finalize cannot be overriden or called.
  • In order to use Dispose(), the class should impelement the IDisposable interface.
  • Dispose() is the right place for freeing up unmanaged resources like DB connection, handles, etc...
  • Dispose() is called when using the "using" block.

Thursday, August 2, 2007

Criteria of Structures

  • Logically represents a single value
  • Has an instance size less than 16 bytes
  • Will not be changed after creation
  • Will not be cast to a reference type

Thursday, June 21, 2007

Layers vs Tiers

In application designing, we always here about this tiers and layers words... N-tier, N-layer, etc... now what is the difference between the two? Simple, layers indicate the logical separation of code, wherein you assign a specific responsibility per layer while tiers relate to the physical distribution of the application for example it is more about where the process runs (client pc - web server - database server).

The Three Principal Layers

Presentation Layer - Display of information, collection of user input, command-line input, interfaces to external systems

Application Logic - Processing data, managing transactions

Data Access Layer - Interaction with data store, messaging systems, remote system access

Wednesday, May 30, 2007

Abstract Class VS Interfaces

As i was going thru some of my reviewers, I noticed that there are two types of classes in C# wherein they can't be instantiated and if you inherit either one of them, you should implement their methods. This are the abstract class and the Interface.

Now in my opinion this are the difference between the two:
  • An abstract class can have constructors while an Interface can't - Interfaces acts just like a blueprint of class except that it don't have any implementations, so what's the need of having a constructor if you wouldn't put in any implementation on it.
  • An abstract class can have concrete methods an Interface can't - Like a normal class an abstract class can have fields, concrete methods and constructors. An abstract class also could have access modifiers, again, just like a normal class.
  • You can do multiple inheritance with an Interface however this is not possible in an abstract class - an abstract class is like an incomplete class, and C# does not support multiple class inheritance, it would be a disaster.

So to sum it all up an abstract class is really like a class except that some of it's methods are not implemented or defined however an Interface is like a blueprint or a contract, it's methods should be implemented in the deriving class. Another thing is when you implement the methods of an abstract class you should add the override modifier to it, in interfaces you don't need to add it.

Wednesday, May 16, 2007

ADO.Net Transaction Object

A Transaction is an atomic unit of work that must be completed in its entirety. The transaction succeeds if it is committed and otherwise fails if it is aborted.

Essential properties of transactions (ACID):
  • Atomicity - work cannot be broken into smaller parts.
  • Consistency - data must always be consistent.
  • Isolation - the transaction should be running by itself and should not be affected nor affect other transactions.
  • Durability - committed transactions should always be persisted.

ex:

using (SqlConnection cn = new SqlConnection()) {
cn.ConnectionString = "CONNECTION STRING HERE!";
cn.Open();
using (SqlTransaction tran = cn.BeginTransaction()) {
try {

using (SqlCommand cmd = cn.CreateCommand()) {
cmd.Transaction = tran;
cmd.CommandText = "SQL TEXT HERE!";
// SQL EXECUTE HERE!
}
tran.Commit();
}
catch (Exception xcp) {
tran.Rollback();
}
}
}

Wednesday, May 2, 2007

Type of Scope Modifiers in C#

  • internal - defines a type, method or data member as public scope in the context of an assembly. The type, method, or data member cannot be accessed from outside the assembly.
  • internal protected - just like the internal scope method however the method or data member has public scope in the subclassed type.
  • private - defines a data member or method that is not accessible outside of the type defining the method or data member.
  • protected - methods and data members are scoped as private however if the method or data member is callable from a subclassed type.
  • public - defines method and data members accessible regardless of the assembly or program scope.

Tuesday, April 24, 2007

Guidelines for using method permission requests in C#

  • Use SecurityAction.PermitOnly declarations to limit the permissions available to each method.
  • Use Security.Deny declarations to further refine the permissions available to each method.
  • Use CodeAccessPermissoin.Assert when you want to allow partially trusted code to call a method that requires permissions the caller might lack.
  • Use CodeAccessPermission.PermitOnly to imperatively reduce permissions when a section of a method requires fewer permissions than the rest of the method.
  • Use CodeAccessPermission.Demand only when your assembly implements customized functionality that does not rely on functionality built into the .Net Framework, such as calls to unmanaged code.

Wednesday, April 18, 2007

Some info about Windows Services in 2.0

This are some tips i've learned about windows services:
  • to debug a windows service, we need to start the service first and attach the debugger to the service's process.
  • you must always create installation components for windows services.
  • the Main method of the service application should always issue the Run command for the services.
  • error messages should be logged in the windows event logger.
  • run your service with the fewest privileges possible to minimize potential damage.

Monday, April 16, 2007

String VS StringBuilder

A few months ago i was wondering what is the purpose of the stringbuilder class in C#, if what it can do can also be done in a simple String/string variable type... and is done, imao, with more ease.

For example let's look at string concatenation:

//StringBuilder
StringBuilder sbExample = new StringBuilder();
sbExample.Append("Some ");
sbExample.Append("Text Here...");
return sbExample.ToString();


//String
String strExample = "Some ";
strExample = strExample + "Text Here...";
return strExample;


In this example, it is much easier to perform string concatenation with a plain simple string type than the stringbuilder, now what exactly is the difference between the two?

The answer: i've been reading the MS Book Application Foundation and here i've learned that a string memory address is immutable... if you concatenate or replace the string value, it does not overwrite its current memory location and instead allocates a new memory location for the new string value, meanwhile with the stringbuilder it always use the same memory it is allocated with whenever you try to modify it's value...

eureka! now i know, for better optimization, when dealing with strings use stringbuilder instead of the basic string value type, there might be an increase in the effort in coding, but what is a little sacrifice for a little more optimized performance.

small things can become big things too ;)