Web #1

htmlcss3

What is HTML?

HTML stands for Hypertext Markup Language. It allows the user to create and structure sections, paragraphs, headings, links, and blockquotes for web pages and applications.
HTML is the standard markup language for Web pages
HTML elements are the building blocks of HTML pages
HTML elements are represented by <> tags
The three block level tags every HTML document needs to contain are:
The  html  tag is the highest level element that encloses every HTML page.
The  head  tag holds meta information such as the page’s title and charset.
Finally, the  body tag encloses all the content that appears on the page.

htmlcode.PNG

What is CSS?

CSS stands for Cascading Style Sheets with an emphasis placed on “Style.” While HTML is used to structure a web document (defining things like headlines and paragraphs, and allowing you to embed images, video, and other media), CSS comes through and specifies your document’s style—page layouts, colors, and fonts are all determined with CSS.
External stylesheets are stored in CSS files

css1.PNG

Example:

css2.jpg

Whats is Visual Studio Code (VSCode)?

vscode

Visual Studio Code is a source-code editor developed by Microsoft for Windows, Linux and macOS. It includes support for debugging, embedded Git control and GitHub, syntax highlighting, intelligent code completion, snippets, and code refactoring. It is highly customizable, allowing users to change the theme, keyboard shortcuts, preferences, and install extensions that add additional functionality. The source code is free and open source and released under the permissive MIT License. The compiled binaries are freeware and free for private or commercial use.
Visual Studio Code is based on Electron, a framework which is used to deploy Node.js applications for the desktop running on the Blink layout engine.

VSCode Home Page link

More topics covered:

  • Loading html pages from local hard drive
  • Embed CSS styles into HTML page: inline, style tag, file
  • What is Markup language?
  • VSCode loading from CMD using “code”
  • VSCode – “!” shortcut
  • HTML semantics
  • CSS selectors
  • HTML Tags: b, u, i, p, div, a, hr, h1..h6, img, ul, ol, li, br, btn
  • What is Bootstrap?
  • Developer tools – clicking F12 in Chrome
  • w3schools

Links:

Advanced topics

advance_dot_net9

Lazy<T>

Lazy initialization of an object means that its creation is deferred until it is first used. Lazy initialization is primarily used to improve performance, avoid wasteful computation, and reduce program memory requirements.

The lazy keyword which was introduced as part of .NET Framework 4.0 provides the built-in support for lazy initialization i.e. on-demand object initialization. If you want to make an object (such as Singleton) as lazily initialized then you just need to pass the type (Singleton) ) of the object to the lazy keyword as shown below.

private static readonly Lazy<Singleton> Instancelock = new Lazy<Singleton>(() => new Singleton());

The most important point that you need to remember is the Lazy<T> objects are by default thread-safe. In a multi-threaded environment, when multiple threads are trying to access the same Get Instance property at the same time, then the lazy object will take care of thread safety.

… read more

Volatile

The volatile keyword indicates that a field might be modified by multiple threads that are executing at the same time. The compiler, the runtime system, and even hardware may rearrange reads and writes to memory locations for performance reasons. Fields that are declared volatile are not subject to these optimizations. Adding the volatile modifier ensures that all threads will observe volatile writes performed by any other thread in the order in which they were performed. There is no guarantee of a single total ordering of volatile writes as seen from all threads of execution.

… read more

Windows Event Viewer

The Windows Event Viewer shows a log of application and system messages, including errors, information messages, and warnings. It’s a useful tool for troubleshooting all kinds of different Windows problems.

eve2

… read more

Windows Service

Windows Services are a core component of the Microsoft Windows operating system and enable the creation and management of long-running processes.
Unlike regular software that is launched by the end user and only runs when the user is logged on, Windows Services can start without user intervention and may continue to run long after the user has logged off. The services run in the background and will usually kick in when the machine is booted. Developers can create Services by creating applications that are installed as a Service, an option ideal for use on servers when long-running functionality is needed without interference with other users on the same system.

… read more

The 7 Layers of the OSI Model + TCP

The Open System Interconnection (OSI) model defines a networking framework to implement protocols in seven layers. Use this handy guide to compare the different layers of the OSI model and understand how they interact with each other.

osi7

… read more

read OSI model – wikipedia

More topics covered:

  • Developer Command Prompt for Visual Studio
  • Installutility.exe
  • Windows service tray icon
  • TCP- client
  • TCP – server
  • TCP- client fire AJAX
  • Implementing REST API in TCP

Class code:

Links:

Design Patterns – more

designp

Decorator pattern

The Decorator pattern extends (decorates) an object’s behavior dynamically. The ability to add new behavior at runtime is accomplished by a Decorator object which ‘wraps itself’ around the original object. Multiple decorators can add or override functionality to the original object.

An example of a decorator is security management where business objects are given additional access to privileged information depending on the privileges of the authenticated user. For example, an HR manager gets to work with an employee object that has appended (i.e. is decorated with) the employee’s salary record so that salary information can be viewed.

Decorators provide flexibility to statically typed languages by allowing runtime changes as opposed to inheritance which takes place at compile time. JavaScript, however, is a dynamic language and the ability to extend an object at runtime is baked into the language itself.

Decorator dofactory – link
Class code: pizza decorator
rabbit

Redis and Cache

What is Cache memory?

In computing, a cache is a hardware or software component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere. A cache hit occurs when the requested data can be found in a cache, while a cache miss occurs when it cannot. Cache hits are served by reading data from the cache, which is faster than recomputing a result or reading from a slower data store; thus, the more requests that can be served from the cache, the faster the system performs.

To be cost-effective and to enable efficient use of data, caches must be relatively small. Nevertheless, caches have proven themselves in many areas of computing, because typical computer applications access data with a high degree of locality of reference. Such access patterns exhibit temporal locality, where data is requested that has been recently requested already, and spatial locality, where data is requested that is stored physically close to data that has already been requested.

… full article

redis

Redis Cache is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster

redis.io home page – link

redis.io for windows – download page

redily2

Redily is a modern Redis GUI Client built to improve developer productivity

redily – home page download

More topics covered:

  • cache memory for data-base
  • Why use cache memory?
  • servicestack.redis nugget
  • redis-cli.exe
  • redis-server.exe

Links:

Design Patterns #11

designp

Adapter pattern

The Adapter pattern translates one interface (an object’s properties and methods) to another. Adapters allows programming components to work together that otherwise wouldn’t because of mismatched interfaces. The Adapter pattern is also referred to as the Wrapper Pattern.

One scenario where Adapters are commonly used is when new components need to be integrated and work together with existing components in the application.

Another scenario is refactoring in which parts of the program are rewritten with an improved interface, but the old code still expects the original interface.

Adapter dofactory – link
Class code: Adapter – 3D shape example
Class code: Adapter employee example
Class code: Adapter for flight system

rabbit

RabbitMQ is a message-queueing software also known as a message broker or queue manager. Simply said; it is software where queues are defined, to which applications connect in order to transfer a message or messages.

mq

A message can include any kind of information. It could, for example, have information about a process or task that should start on another application (which could even be on another server), or it could be just a simple text message. The queue-manager software stores the messages until a receiving application connects and takes a message off the queue. The receiving application then processes the message.

A message broker acts as a middleman for various services (e.g. a web application, as in this example). They can be used to reduce loads and delivery times of web application servers by delegating tasks that would normally take up a lot of time or resources to a third party that has no other job.

mq2

… full article

Possible message deliver mechanism:

  1. Work queues
  2. Publish/Subscribe
  3. Routing
  4. Topics
  5. RPC – remote procedure call (request-reply)
  6. Publisher confirms

… full article

RabbitMQ Enable Web Management Plugin

http://localhost:15672/
username: guest
password: guest rabbitgui

Download the RabbitMQ prerequisite – link
Download the RabbitMQ – link
Installation tutorial – link

RabbitMQ demo code

Class code: Rabbit Listener
Class code: Rabbit Producer

More topics covered:

  • different flavors of builder
  • usage or RabbitMQ in asp.net rest
  • observer less relevant today because of events

Links:

Design Patterns #10

designp

Command pattern

The Command pattern encapsulates actions as objects. Command objects allow for loosely coupled systems by separating the objects that issue a request from the objects that actually process the request. These requests are called events and the code that processes the requests are called event handlers.

Suppose you are building an application that supports the Cut, Copy, and Paste clipboard actions. These actions can be triggered in different ways throughout the app: by a menu system, a context menu (e.g. by right clicking on a textbox), or by a keyboard shortcut.

Command dofactory – link
Command dotnettutorials – link
Class code: Command – azure example
Class code: Command – javascript example

Fluent pattern

A fluent interface is normally implemented by using method chaining to implement method cascading, concretely by having each method return this (self). Stated more abstractly, a fluent interface relays the instruction context of a subsequent call in method chaining, where generally the context is

  • Defined through the return value of a called method
  • Self-referential, where the new context is equivalent to the last context
  • Terminated through the return of a void context

Note that a “fluent interface” means more than just method cascading via chaining…

Class code: fluent – LINQ
Class code: fluent Customer

Flyweight pattern

The Flyweight pattern conserves memory by sharing large numbers of fine-grained objects efficiently. Shared flyweight objects are immutable, that is, they cannot be changed as they represent the characteristics that are shared with other objects.

Essentially Flyweight is an ‘object normalization technique’ in which common properties are factored out into shared flyweight objects. (Note: the idea is similar to data model normalization, a process in which the modeler attempts to minimize redundancy). An example of the Flyweight Pattern could be a is a list of immutable strings that are shared across the application.

Other examples include characters and line-styles in a word processor, or ‘digit receivers’ in a public switched telephone network application. You will find flyweights mostly in utility type applications such as word processors, graphics programs, and network apps; they are less often used in data-driven business type applications.

Flyweight dofactory – link
Flyweight dotnettutorials – link
Class code: Flyweight – big numbers
Class code: Flyweight – java GUI example

Weak reference

Objects that are referenced must be kept in memory until they are unreachable. use the WeakReference type, which leaves objects accessible in memory until they are collected by the Garbage Collector (GC).

If you have cache layer implemented with C# it’s much better too put your data in cache as weak references, it could help to improve your cache layer performance. Think that approach also could be applied to session implementation. Because session is long living object most of the time, it could be some case when you have no memory for new user. In that case it will be much better to delete some else user session object then throwing OutOfMemoryException.

Also, if you have a large object in your application (some big lookup table, etc), that should be used quite seldom and recreating of such an object isn’t a very expensive procedure. Then better have it like a week reference to have a way to free your memory when you really need that.

Class code: weak reference

Weak reference regenerate

More topics covered:

  • GC.Collect( )
  • Gather commands in different invokers
  • Add a button which invokes a command
  • WPF command

Links:

Design Patterns #9

designp

Builder pattern

The Builder pattern allows a client to construct a complex object by specifying the type and content only. Construction details are hidden from the client entirely.

The most common motivation for using Builder is to simplify client code that creates complex objects. The client can still direct the steps taken by the Builder without knowing how the actual work is accomplished. Builders frequently encapsulate construction of Composite objects because the procedures involved are often repetitive and complex. Usually it is the last step that returns the newly created object which makes it easy for a Builder to participate in fluent interfaces in which multiple method calls, separated by dot operators, are chained together (note: fluent interfaces are implementation of the Chaining Pattern as presented in the Modern patterns section).

Builder dofactory – link
Builder dotnettutorials – link
Class code: builder – hamburger!

Observer pattern

The Observer pattern offers a subscription model in which objects subscribe to an event and get notified when the event occurs. This pattern is the cornerstone of event driven programming, The Observer pattern facilitates good object-oriented design and promotes loose coupling.

When building web apps you end up writing many event handlers. Event handlers are functions that will be notified when a certain event fires. These notifications optionally receive an event argument with details about the event (for example the x and y position of the mouse at a click event).

The observer pattern was the key idea behind events and delegates

Observer dofactory – link
Class code: observer – observing stock market – in Java!

Mediator pattern

The Mediator pattern provides central authority over a group of objects by encapsulating how these objects interact. This model is useful for scenarios where there is a need to manage complex conditions in which every object is aware of any state change in any other object in the group.

The Mediator patterns are useful in the development of complex forms. Take for example a page in which you enter options to make a flight reservation. A simple Mediator rule would be: you must enter a valid departure date, a valid return date, the return date must be after the departure date, a valid departure airport, a valid arrival airport, a valid number of travelers, and only then the Search button can be activated.

Another example of Mediator is of course a chat room when every message passes through a mediator which publishes only appropriate messages

Mediator dotnettutorials – chat room
Mediator dofactory – link
Class code: mediator – selling stocks – in Java!

More topics covered:

  • different flavors of builder
  • observer less relevant today because of events

Links:

Design Patterns #8

designp

Bridge pattern

The Bridge pattern allows two components, a client and a service, to work together with each component having its own interface. Bridge is a high-level architectural pattern and its main goal is to write better code through two levels of abstraction. It facilitates very loose coupling of objects. It is sometimes referred to as a double Adapter pattern.

An example of the Bridge pattern is an application (the client) and a database driver (the service). The application writes to a well-defined database API, for example ODBC, but behind this API you will find that each driver’s implementation is totally different for each database vendor (SQL Server, MySQL, Oracle, etc.).

Bridge is very similar to strategy!

Bridge dofactory – link

Bridge pattern vs Strategy pattern

“They both look the same on the surface to me as well. The main difference I see is the fact that in the Bridge pattern, the abstraction is PART OF the object, but in the Strategy pattern the abstraction is performed BY the object.

Bridge: ( A structural pattern)

Bridge pattern decouples abstraction and implementation and allows both to vary independently.

Use this pattern when :

  1. Abstractions and implementations have not been decided at compile time
  2. Abstractions and implementations should be changed independently
  3. Changes in implementation of abstraction should not affect caller application
  4. Client should be insulated from implementation details.

Strategy: ( Behavioural pattern)

Strategy patterns enable you to switch between multiple algorithms from a family of algorithms at run time.

Use Strategy pattern when :

  1. Multiple versions of algorithms are required
  2. The behaviour of class has to be changed dynamically at run time
  3. Avoid conditional statements”

Iterator pattern

The Iterator pattern allows clients to effectively loop over a collection of objects. A common programming task is to traverse and manipulate a collection of objects. These collections may be stored as an array or perhaps something more complex, such as a tree or graph structure. In addition, you may need to access the items in the collection in a certain order, such as, front to back, back to front, depth first (as in tree searches), skip evenly numbered objects, etc. The Iterator design pattern solves this problem by separating the collection of objects from the traversal of these objects by implementing a specialized iterator.

Today, many languages have Iterators built-in by supporting ‘for-each’-type constructs and IEnumerable and IEnumerator interfaces.

Iterator dofactory – link

foreach + yield + IEnumerable

yield1

yield2

yield3

You use a yield return statement to return each element one at a time.

The sequence returned from an iterator method can be consumed by using a foreach statement or LINQ query. Each iteration of the foreach loop calls the iterator method. When a yield return statement is reached in the iterator method, expression is returned, and the current location in code is retained. Execution is restarted from that location the next time that the iterator function is called.

You can use a yield break statement to end the iteration.

… full article
nice article on yield
Class code: foreach yield
Youtube code: foreach yield list

foreach + GetEnumerator

y22

y111

y3

The foreach statement executes a statement or a block of statements for each element in an instance of the type that contains GetEnumerator method. The foreach statement is not limited to those types and can be applied to an instance of any type that satisfies the following conditions:

  • has the public parameterless GetEnumerator method whose return type is either class, struct, or interface type
  • the return type of the GetEnumerator — which has public Current property, public parameterless MoveNext method whose return type is Boolean and public Reset

(of course you can also implement System.Collections.IEnumerable or System.Collections.Generic.IEnumerable interfaces)

Class code: foreach a class using enumerator
Youtube code: foreach my data collection

More topics covered:

  • advantages of IEnumerable
  • enumerate a non-existing collection
  • ASP.NET REST IEnumerable

Links:

Design Patterns #7

designp

Strategy pattern

The Strategy pattern encapsulates alternative algorithms (or strategies) for a particular task. It allows a method to be swapped out at runtime by any other method (strategy) without the client realizing it. Essentially, Strategy is a group of algorithms that are interchangeable.

Say we like to test the performance of different sorting algorithms to an array of numbers: shell sort, heap sort, bubble sort, quicksort, etc. Applying the Strategy pattern to these algorithms allows the test program to loop through all algorithms, simply by changing them at runtime and test each of these against the array. For Strategy to work all method signatures must be the same so that they can vary without the client program knowing about it.

Strategy dofactory – link
Class code: strategy demo in JAVA!

Abstract factory pattern

An Abstract Factory creates objects that are related by a common theme. In object-oriented programming a Factory is an object that creates other objects. An Abstract Factory has abstracted out a theme which is shared by the newly created objects.

Suppose we have two Abstract Factories whose task it is to create page controls, such as, buttons, textboxes, radio buttons, and listboxes. One is the Light Factory which creates controls that are white and the other the Dark Factory which creates controls that are black. Both Factories creates the same types of controls, but they differ in color, which is their common theme. This is an implementation of the Abstract Factory pattern.

This includes scenarios in which the creation process involves object caching, sharing or re-using of objects, complex logic, or applications that maintain object and type counts, and objects that interact with different resources or devices. If your application needs more control over the object creation process, consider using a Factory.

Abstract factory dofactory – link
Class code: abs factory demo in JAVA!

Apache log4net

log4net is a tool to help the programmer output log statements to a variety of output targets. In case of problems with an application, it is helpful to enable logging so that the problem can be located. With log4net it is possible to enable logging at runtime without modifying the application binary. The log4net package is designed so that log statements can remain in production code without incurring a high performance cost. It follows that the speed of logging (or rather not logging) is crucial.

At the same time, log output can be so voluminous that it quickly becomes overwhelming. One of the distinctive features of log4net (and common to all of the log4x libraries) is the notion of hierarchical loggers. Using these loggers it is possible to selectively control which log statements are output at arbitrary granularity.

Apache log4net – home site!
Log4net appenders list
Log4net – demo project
Log4net – stackify demo!

Nice interview question

formula: “AA,ABC@BC,DD@CDA”….

for the question – click here

JSON viewer

Json viewer stack.hu – click here

More topics covered:

  • choosing strategy based on input
  • changing strategy at run-time

Links: