Abstract Class vs Sealed Class

Abstract Class vs Sealed Class
Difference in Abstract vs Sealed Class

Abstract Class VS Sealed Class

 

The Abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.

The sealed keyword enables you to prevent the inheritance of a class or certain class members that were previously marked virtual.

Abstract Classes and Class Members

Classes can be declared as abstract by putting the keyword abstract before the class definition.

Example

public abstract class A
{
    // Class members here.
}

An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. For example, a class library may define an abstract class that is used as a parameter to many of its functions, and require programmers using that library to provide their own implementation of the class by creating a derived class.

Abstract classes may also define abstract methods. This is accomplished by adding the keyword abstract before the return type of the method. For example:

public abstract class A
{
    public abstract void DoWork(int i);
}

Abstract methods have no implementation, so the method definition is followed by a semicolon instead of a normal method block. Derived classes of the abstract class must implement all abstract methods. When an abstract class inherits a virtual method from a base class, the abstract class can override the virtual method with an abstract method. For example:

// compile with: /target:library
public class D
{
    public virtual void DoWork(int i)
    {
        // Original implementation.
    }
}

public abstract class E : D
{
    public abstract override void DoWork(int i);
}

public class F : E
{
    public override void DoWork(int i)
    {
        // New implementation.
    }
}

If a virtual method is declared abstract, it is still virtual to any class inheriting from the abstract class. A class inheriting an abstract method cannot access the original implementation of the method—in the previous example, DoWork on class F cannot call DoWork on class D. In this way, an abstract class can force derived classes to provide new method implementations for virtual methods.

Sealed Classes and Class Members

Classes can be declared as sealed by putting the keyword sealed before the class definition.

Example:

public sealed class D
{
    // Class members here.
}

A sealed class cannot be used as a base class. For this reason, it cannot also be an abstract class. Sealed classes prevent derivation. Because they can never be used as a base class, some run-time optimizations can make calling sealed class members slightly faster.

A method, indexer, property, or event, on a derived class that is overriding a virtual member of the base class can declare that member as sealed. This negates the virtual aspect of the member for any further derived class. This is accomplished by putting the sealed keyword before the override keyword in the class member declaration. For example:

public class D : C
{
    public sealed override void DoWork() { }
}

source: MSDN | C# Programming Guide

Advertisements

OOPS | Abstract in C# Class, Methods and Properties

How Abstraction works in C# | Classes, Methods and Properties
How Abstraction works in C# | Classes, Methods and Properties

abstract (C# Reference)

The abstract modifier indicates that the thing being modified has a missing or incomplete implementation. The abstract modifier can be used with classes, methods, properties, indexers, and events. Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes. Members marked as abstract, or included in an abstract class, must be implemented by classes that derive from the abstract class.

Example

In this example, the class Square must provide an implementation of Area because it derives from ShapesClass:

 
abstract class ShapesClass
{
    abstract public int Area();
}

class Square : ShapesClass
{
    int side = 0;

    public Square(int n)
    {
        side = n;
    }
    // Area method is required to avoid
    // a compile-time error.
    public override int Area()
    {
        return side * side;
    }

    static void Main() 
    {
        Square sq = new Square(12);
        Console.WriteLine("Area of the square = {0}", sq.Area());
    }

    interface I
    {
        void M();
    }
    abstract class C : I
    {
        public abstract void M();
    }

}
// Output: Area of the square = 144

Abstract classes features:

  1. An abstract class cannot be instantiated.
  2. An abstract class may contain abstract methods and accessors.
  3. It is not possible to modify an abstract class with the sealed modifier because the two modifers have opposite meanings. The sealed modifier prevents a class from being inherited and the abstract modifier requires a class to be inherited.
  4. A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.
  5. Use the abstract modifier in a method or property declaration to indicate that the method or property does not contain implementation.

Abstract methods features:

    1. An abstract method is implicitly a virtual method.
    2. Abstract method declarations are only permitted in abstract classes.
    3. Because an abstract method declaration provides no actual implementation, there is no method body; the method declaration simply ends with a semicolon and there are no curly braces ({ }) following the signature.

      Example

      public abstract void MyMethod();
      
    4. The implementation is provided by a method override, which is a member of a non-abstract class.
    5. It is an error to use the static or virtual modifiers in an abstract method declaration.
    6. Abstract properties behave like abstract methods, except for the differences in declaration and invocation syntax.
    7. It is an error to use the abstract modifier on a static property.
    8. An abstract inherited property can be overridden in a derived class by including a property declaration that uses the override modifier.
    9. An abstract class must provide implementation for all interface members.
    10. An abstract class that implements an interface might map the interface methods onto abstract methods. For example:
      interface I
      {
          void M();
      }
      abstract class C : I
      {
          public abstract void M();
      }
      

Example

In this example, the class DerivedClass is derived from an abstract class BaseClass. The abstract class contains an abstract method, AbstractMethod, and two abstract properties, X and Y.

abstract class BaseClass   // Abstract class
{
    protected int _x = 100;
    protected int _y = 150;
    public abstract void AbstractMethod();   // Abstract method
    public abstract int X    { get; }
    public abstract int Y    { get; }
}

class DerivedClass : BaseClass
{
    public override void AbstractMethod()
    {
        _x++;
        _y++;
    }

    public override int X   // overriding property
    {
        get
        {
            return _x + 10;
        }
    }

    public override int Y   // overriding property
    {
        get
        {
            return _y + 10;
        }
    }

    static void Main()
    {
        DerivedClass o = new DerivedClass();
        o.AbstractMethod();
        Console.WriteLine("x = {0}, y = {1}", o.X, o.Y);
    }
}
// Output: x = 111, y = 161

 

In the preceding example, if you attempt to instantiate the abstract class by using a statement like this:

BaseClass bc = new BaseClass();   // Error  

You will get an error saying that the compiler cannot create an instance of the abstract class ‘BaseClass’.

Source Article: MSDN | Abstract C# Reference

Unable to start debugging on the web server. The server committed a protocol violation. section=responsestatusline

This error usually occurs when you have set up Visual Studio to debug an existing web application running in IIS rather than the built in ASP.NET debug web server.

IIS by default listens for web requests on port 80. In this case, another application is already listening for requests on port 80. Typically, the offending application is Skype or Apache which by default takes over listening on ports 80 and 443 when installed.

If you do development in Apache too go to httpd.conf and find for below lines:


#Listen 12.34.56.78:80
Listen 80

ServerName localhost:80

Replace the port with some other port like 81 or 8080. Restart IIS and you are good to go.

If you think Skype is culprit do the following:

Skype -> Tools -> Options -> Advanced -> Connection:

Uncheck “Use port 80 and 443 as alternatives for incoming connections”

This will free those ports from skype; again Restart IIS and you are good to go!

NodeJS Packages and Resources

A curated list of delightful Node.js packages and resources.

Packages

Mad science

  • webtorrent – Streaming torrent client for Node.js and the browser.
  • peerflix – Streaming torrent client.
  • dat – Real-time replication and versioning for data sets.
  • ipfs – Distributed file system that seeks to connect all computing devices with the same system of files.
  • Breach – Modular and hackable browser written in JavaScript.
  • peerwiki – All of Wikipedia on BitTorrent.
  • peercast – Stream a torrent video to Chromecast.
  • BitcoinJS – Clean, readable, proven Bitcoin library.
  • js-git – JavaScript implementation of Git.
  • NodeOS – The first operating system powered by npm.
  • PDFKit – PDF generation library.
  • turf – Modular geospatial processing and analysis engine.

Command-line apps

  • pageres – Responsive website screenshots.
  • trash – A safer alternative to rm.
  • yo – Run Yeoman generators.
  • ESLint – The pluggable linting utility for JavaScript.
  • JSHint – A community-driven tool to detect errors and potential problems in JavaScript code.
  • JSCS – JavaScript Code Style checker.
  • cpy – Copy files.
  • torrent – Download torrents.
  • David – Tells you when your package npm dependencies are out of date.
  • vtop – More better top, with nice charts.
  • tmpin – Adds stdin support to any CLI app that accepts file input.
  • normit – Google Translate with speech synthesis in your terminal.
  • esformatter – JavaScript code beautifier/formatter.
  • is-up – Check whether a website is up or down.
  • ipify – Get your public IP address.
  • http-server – Simple, zero-config command-line HTTP server.
  • bcat – Pipe command output to web browsers.
  • slap – Sublime-like terminal-based text editor.
  • jsinspect – Detect copy-pasted and structurally similar code.
  • pjs – Pipeable JavaScript. Quickly filter, map, and reduce from the terminal.
  • license-checker – Check licenses of your app’s dependencies.

Functional programming

  • Lo-Dash – A utility library delivering consistency, customization, performance, & extras. A better and faster Underscore.js.
  • Mout – Utility library with the biggest difference between other existing solutions is that you can choose to load only the modules/functions that you need, no extra overhead.
  • mori – A library for using ClojureScript’s persistent data structures and supporting API from the comfort of vanilla JavaScript.
  • Folktale – A suite of libraries for generic functional programming in JavaScript that allows you to write elegant, modular applications with fewer bugs, and more reuse.
  • immutable – Immutable data collections.
  • underscore-contrib – The brass buckles on Underscore’s utility belt.
  • Bacon.js – Functional reactive programming.
  • Lazy.js – Utility library similar to Lo-Dash/Underscore but with lazy evaluation, which can translate to superior performance in many cases.

HTTP

  • request – Simplified HTTP request client.
  • got / sent – A nicer interface to the built-in http module.
  • superagent – A small progressive HTTP request library.
  • axios – Promise based HTTP client (works in the browser too).
  • hyperquest – Streaming HTTP requests.
  • spdy – Creates SPDY servers with the same API as the built-in https module.
  • Nock – A HTTP mocking and expectations library.
  • download – Download and extract files effortlessly.
  • wreck – HTTP Client Utilities.

Debugging / Profiling

  • node-inspector – Debugger based on Blink Developer Tools.
  • Theseus – A new type of JavaScript debugger featuring real-time code coverage, retroactive inspection and asynchronous call tree.
  • longjohn – Long stack traces with configurable call trace length.
  • debug – Tiny debugging utility.
  • jstrace – Dynamic tracing for JavaScript, similar to dtrace, ktap etc.
  • TraceGL – Transforms your JavaScript, injecting monitoring code that produces a log of everything that happens.
  • spy-js – Tracing tool for JavaScript, featuring configurable event capturing, searchable call stack, code coverage, recorded object values inspection, multi process and node cluster tracing support.
  • njsTrace – Instrument and trace your code, see all function calls, arguments, return values, as well as the time spent in each function.
  • vstream – Instrumentable streams mix-ins to inspect a pipeline of streams.
  • stackman – Enhance an error stacktrace with code excerpts and other goodies.

Logging

  • winston – A multi-transport async logging library.
  • Bunyan – A simple and fast JSON logging library.
  • intel – A comprehensive logging library (handlers, filters, formatters, console injection).

Web frameworks

  • Koa – A new web framework designed by the team behind Express, which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs.
  • Express – A minimal and flexible web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications.
  • Hapi – A rich framework for building applications and services.
  • LoopBack – Powerful framework for creating REST APIs and easily connecting to backend data sources.
  • Meteor – An ultra-simple, database-everywhere, data-on-the-wire, pure-Javascript web framework.
  • SailsJS – An MVC web framework with a modern twist, supporting WebSockets, streams, and a data-driven API.
  • Restify – A node framework built specifically to enable you to build correct REST web services.
  • Derby – MVC framework, making it easy to write realtime, collaborative applications that run in both Node.js and browsers.
  • Interfake – Rapid prototyping framework for making mock HTTP APIs, with a Node, command-line and HTTP interface.

Command-line utilities

  • chalk – Terminal string styling done right.
  • minimist – Parse command-line flags.
  • get-stdin – Easier stdin.
  • Inquirer.js – Interactive command-line prompt.
  • update-notifier – Update notifications for your CLI app.
  • sudo-block – Block users from running your app with root permissions.
  • configstore – Easily load and persist config without having to think about where and how.
  • insight – Helps you understand how your tool is being used by anonymously reporting usage metrics to Google Analytics.
  • sparkly – Generate sparklines ▁▂▃▅▂▇
  • blessed – A curses-like library.
  • cli-table – Pretty unicode tables.
  • drawille – Draw on the terminal with unicode braille characters.
  • progress – Flexible ascii progress bar.
  • log-symbols – Colored symbols for various log levels.
  • columnify – Create text-based columns suitable for console output. Supports cell wrapping.
  • googleauth – Create and load persistent Google authentication tokens for command-line apps.
  • figures – Unicode symbols with Windows CMD fallbacks.
  • cli-cursor – Toggle the CLI cursor.
  • ascii-charts – ACII bar chart in the terminal.

Package managers

  • npm – A package manager for Node.js and the web.
  • Bower – A package manager for the web.
  • Component – A package manager for building better web apps.
  • Duo – A next-generation package manager for the front-end.
  • jspm.io – Frictionless browser package management with support for ES6, CommonJS, AMD modules.

Build tools

  • gulp.js – Streaming and fast build system that favors code over config.
  • grunt – Task runner that can perform repetitive tasks like minification, compilation, unit testing, linting, etc.
  • Broccoli – A fast, reliable asset pipeline, supporting constant-time rebuilds and compact build definitions.
  • browserify – Browser-side require() the Node.js way.
  • webpack – Packs CommonJS/AMD modules for the browser.
  • Brunch – Front-end web app build tool with simple declarative config, fast incremental compilation, and an opinionated workflow.

Hardware

  • johnny-five – Firmata based Arduino Framework.
  • serialport – Access serial ports for reading and writing.
  • usb – USB library.
  • cylon.js – Next generation robotics framework with support for 26 different platforms.

Templating

  • handlebars.js – A superset of Mustache templates which adds powerful features like helpers and more advanced blocks.
  • hogan.js – Twitter’s small, fast, phase-separated compiler for Mustache templates.
  • Jade – High performance template engine heavily influenced by Haml.
  • nunjucks – A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired).

Documentation

  • Docco – A quick-and-dirty documentation generator which produces an HTML document that displays your comments intermingled with your code.
  • JSDoc – API documentation generator similar to JavaDoc or PHPDoc.
  • dox – JavaScript documentation generator using Markdown and JSDoc.
  • jsdox – JSDoc3 to Markdown documentation generator.
  • apiDoc – Inline documentation for RESTful web APIs.

Filesystem

  • del – Delete files/folders using globs.
  • globby – Glob files with support for multiple patterns.
  • cpy – Copy files.
  • rimraf – Recursively delete files like rm -rf.
  • mkdirp – Recursively create directories like mkdir -p.
  • graceful-fs – Drop-in replacement for the fs module with various improvements.
  • fs-extra – Extra methods for the fs module.
  • fs-write-stream-atomic – Like fs.createWriteStream(), but atomic.
  • lnfs – Force create symlinks like ln -fs.
  • chokidar – Filesystem watcher which stabilizes events from fs.watch and fs.watchFile as well as using native fsevents on OS X.
  • gaze – A globbing watch module which uses custom native binaries to listen to filesystem events.

Control flow

  • Callbacks
    • each-async – Async concurrent iterator like forEach.
    • async – Provides straight-forward, powerful functions for working with asynchronousity.
    • after-all-results – Bundle results of async functions calls into one callback with all the results.
  • Generators
    • co – The ultimate generator based flow-control goodness.
    • suspend – Generator-based control flow that plays nice with callbacks, promises, and thunks.
  • Promises
    • native-promise-only – A polyfill for native ES6 Promises.
    • Bluebird – A fully featured promise library with focus on innovative features and performance.
    • Q – A tool for making and composing asynchronous promises.
  • Streams
    • Highland.js – Manages synchronous and asynchronous code easily, using nothing more than standard JavaScript and Node-like Streams.
  • Channels
    • js-csp – Communicating sequential processes for JavaScript (like Clojurescript core.async, or Go).
  • Other
    • zone – Provides a way to group and track resources and errors across asynchronous operations.

Streams

  • through2 – Tiny wrapper around streams2 Transform to avoid explicit subclassing noise.
  • concat-stream – Concatenates a stream into strings or binary data.
  • simple-bufferstream – Turn a Buffer into a ReadableStream.
  • co-streamco generator stream.
  • byline – Super-simple line-by-line Stream reader.
  • first-chunk-stream – Transform the first chunk in a stream.
  • duplexify – Turn a writeable and readable stream into a single streams2 duplex stream.
  • pumpify – Combine an array of streams into a single duplex stream.
  • from2 – Convenience wrapper for ReadableStream, inspired by through2.
  • from2-array – Create a from2 stream based on an array of source values.
  • peek-stream – Transform stream that lets you peek the first line before deciding how to parse it.
  • binary-split – A fast newline (or any delimiter) splitter stream.
  • multistream – Combine multiple streams into a single stream.
  • graphicsmagick-stream – Fast conversion/scaling of images using a pool of long lived graphicsmagick processes.
  • readable-stream – Mirror of Streams2 and Streams3 implementations in core.
  • s3-upload-stream – Upload a stream to an Amazon S3 bucket using multipart upload.
  • through2-concurrent – Transform object streams concurrently.

Real-time

  • Socket.io – Enables real-time bidirectional event-based communication.
  • SockJS – Low latency, full duplex, cross-domain channel browser-server, with WebSockets or without.
  • SocketCluster – Scalable HTTP + WebSocket engine which can run on multiple CPU cores.
  • Primus – An abstraction layer for real-time frameworks to prevent module lock-in.
  • Straw – Real-time dataflow framework.

Date

Image

  • sharp – The fastest module for resizing JPEG, PNG, WebP and TIFF images.
  • image-type – Detect the image type of a Buffer/Uint8Array.
  • gm – GraphicsMagick and ImageMagick wrapper.

Text

  • Underscore.string – Collection of string manipulation utilities.
  • he – A robust HTML entity encoder/decoder.
  • iconv-lite – Convert character encodings.
  • escape-string-regexp – Escape RegExp special characters.
  • indent-string – Indent each line in a string.
  • strip-indent – Strip leading whitespace from every line in a string.
  • detect-indent – Detect the indentation of code.
  • i18n-node – Simple translation module with dynamic JSON storage.
  • string-length – Get the real length of a string – by correctly counting astral symbols and ignoring ansi escape codes.
  • speakingurl – Generate a slug from a string with transliteration.

Math

  • ndarray – Multidimensional arrays.
  • mathjs – An extensive math library.

Data validation

  • joi – Object schema description language and validator for JavaScript objects.

Parsing

  • css – CSS parser / stringifier.
  • strip-json-comments – Strip comments from JSON.
  • marked – A markdown parser and compiler built for speed.
  • remarkable – A very fast markdown parser with 100% CommonMark support, extensions and syntax plugins.
  • js-yaml – Very fast YAML parser.
  • URI.js – URL mutation.
  • JSONStream – Streaming JSON.parse and stringify.
  • csv-parser – Streaming CSV parser that aims to be faster than everyone else.
  • excel-stream – Streaming Excel spreadsheet to JSON parser.
  • parse5 – Fast full-featured spec compliant HTML parser.
  • htmlparser2 – Forgiving HTML/XML parser.
  • PostCSS – Framework for CSS postprocessors, to modify CSS.
  • PEG.js – Simple parser generator that produces fast parsers with excellent error reporting.

Humanize

  • pretty-bytes – Convert bytes to a human readable string: 13371.34 kB.
  • pretty-ms – Convert milliseconds to a human readable string: 133700000015d 11h 23m 20s.
  • ms – Tiny millisecond conversion utility.
  • pretty-error – Errors with less clutter.
  • humanize – Data formatter for human readability.
  • node-read – Extract readable content from any page.

Compression

  • Archiver – Streaming interface for archive generation, supporting ZIP and TAR.
  • decompress-zip – Unzip.
  • tar-stream – Streaming tar parser and generator. Also see tar-fs.
  • decompress – A pluggable decompression module with support for tar, tar.gz and zip files out of the box.

Network

  • get-port – Get an available port.
  • ipify – Get your public IP address.

Static site generators

  • Metalsmith – An extremely simple, pluggable static site generator.
  • Wintersmith – Flexible, minimalistic, multi-platform static site generator.
  • Assemble – Static site generator for Node.js, Grunt.js, and Yeoman.

Content management systems

  • KeystoneJS – CMS and web application platform built on Express and MongoDB.
  • Calipso – A simple content management system, built along similar themes to Drupal and WordPress, that is designed to be fast, flexible and simple.
  • Apostrophe2 – A content management system with an emphasis on intuitive front end content editing and administration built on Express and MongoDB.

Forum

  • nodeBB – A better forum platform for the modern web.

Blogging

  • ghost – Simple, powerful publishing platform that allows you to share your story with the world.
  • Hexo – Fast, simple and powerful blogging framework.

Database

  • Drivers
    • LevelUP – LevelDB.
    • MongoDB – MongoDB driver.
    • PostgreSQL – PostgreSQL client. Pure JavaScript and native libpq bindings.
    • MySQL – MySQL client.
    • Redis – Redis client.
  • ODM / ORM
    • Bookshelf – ORM for PostgreSQL, MySQL and SQLite3 in the style of Backbone.js.
    • JugglingDB – Multi-database ORM with a common API. Supports Redis, PostgreSQL, MongoDB, MySQL, SQLite, Neo4j, memory, and more.
    • Mongoose – Elegant MongoDB object modeling.
    • Sequelize – Multi-dialect ORM. Supports PostgreSQL, SQLite, MySQL.
    • Waterline – Datastore-agnostic tool that dramatically simplifies interaction with one or more databases.
    • Iridium – A high performance MongoDB ORM with support for promises, distributed caching, preprocessing, validation and plugins.
    • OpenRecord – ORM for PostgreSQL, MySQL, SQLite3 and RESTful datastores. Similar to ActiveRecord.
  • Query builder
    • Knex – A query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.

Testing

  • tapeTAP-producing test harness.
  • Mocha – A feature-rich test framework making asynchronous testing simple and fun.
  • Mochify – TDD with Browserify, Mocha, PhantomJS and WebDriver.
  • loadtest – Run load tests for your web application, with an API for automation.
  • istanbul – A code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests.
  • Sinon.JS – Test spies, stubs and mocks.
  • Karma – Executes code in multiple real browsers.
  • Nightmare – High-level PhantomJS wrapper that lets you automate browser tasks.

Benchmarking

  • Benchmark.js – A robust benchmarking library that works on nearly all JavaScript platforms, supports high-resolution timers, and returns statistically significant results.
  • matcha – A caffeine driven, simplistic approach to benchmarking.

Minifiers

Authentication

  • Passport – Simple, unobtrusive authentication.
  • everyauth – Authentication and authorization (password, facebook, & more) for your Connect and Express apps.
  • passwordless – Token-based authentication middleware for Express allowing authentication without passwords.
  • Lockit – Full featured authentication solution for Express. Supports a variety of databases, predefined routes, email and two-factor authentication.

Node.js management

  • n – Node.js version management.
  • nave – Virtual Environments for Node.js.
  • nodeenv – A Node.js virtual environment compatible to Python’s virtualenv.
  • nvm for Windows – Version management for Windows.

Email

Polyfills

Natural language processing

  • natural – A general natural language facility.
  • retext – An extensible natural language system.
  • franc – Detect the language of text.
  • leven – Measure the difference between two strings using the Levenshtein distance algorithm.

Process management

  • node-windows – Run scripts as a native Windows service and log to the Event viewer.
  • node-mac – Run scripts as a native Mac daemon and log to the console app.
  • node-linux – Run scripts as native system service and log to syslog.
  • forever – A simple CLI tool for ensuring that a given script runs continuously (i.e. forever).
  • supervisor – Restart scripts when they crash or restart when a *.js file changes.
  • PM2 – Advanced Process Manager.
  • Phusion Passenger – Friendly process manager that integrates directly into Nginx.

AST

  • Acorn – A tiny, fast JavaScript parser.
  • Rocambole – Recursively walk and transform JavaScript AST.

Weird

Miscellaneous

  • multiline – Multiline strings in JavaScript.
  • opn – Opens stuff like websites, files, executables.
  • semversemver parser.
  • cheerio – Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
  • require-uncached – Require a module bypassing the cache.
  • Faker.js – Generate massive amounts of fake data.
  • Bottleneck – A powerful rate limiter that makes throttling easy.
  • stringify-object – Stringify an object/array like JSON.stringify just without all the double-quotes.
  • strip-bom – Strip UTF-8 byte order mark (BOM) from a string/buffer/stream.
  • shelljs – Portable Unix shell commands.
  • nan – A header file filled with macro and utility goodness for making add-on development for across Node.js versions easier.
  • ssh2 – An SSH2 client module.
  • lazy-req – Require modules lazily.
  • webworker-threads – Lightweight Web Worker API implementation with native threads.
  • node-pre-gyp – Makes it easy to publish and install Node.js C++ addons from binaries.
  • opencv – Bindings for OpenCV. The defacto computer vision library.
  • common-errors – Common error classes and utility functions.
  • atom-shell – Cross-platform desktop application shell.
  • agenda – Lightweight job scheduling on MongoDB.

Resources

Tutorials

Discovery

  • node-modules.com – An alternative npm search engine with a more intelligent and personal results ranking.

Articles

Newsletters

  • node weekly – Weekly e-mail round-up of Node.js news and articles.

Videos

Podcasts

Books

Blogs

  • Node.js blog
  • HowToNode – Teaching how to do various tasks in Node.js as well as teach fundamental concepts that are needed to write effective code.

Courses

Cheatsheets

Tools

  • GitHub Linker – Chrome extension that linkifies dependencies in package.json on GitHub.

Miscellaneous

  • nodebots – Robots powered by JavaScript.

How to attach a file from MemoryStream to a Mail in C#

Here’s a simplified snippet for sending an in-memory string as an email attachment (a CSV file in this particular case).
If you are trying this with PDF, put special mention on stream.position = 0. As it will make the writer write the file from starting position always.
Whatever the source-type you care coming with convert that to memory-stream and the use the memory stream to create the attachment.
That’s it!!

using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream))    // using UTF-8 encoding by default
using (var mailClient = new SmtpClient("localhost", 25))
using (var message = new MailMessage("me@example.com", "you@example.com", "Just testing", "See attachment..."))
{
    writer.WriteLine("Comma,Seperated,Values,...");
    writer.Flush();
    stream.Position = 0;     // read from the start of what was written

    message.Attachments.Add(new Attachment(stream, "filename.csv", "text/csv"));

    mailClient.Send(message);
}