Connecting to MySQL Database in Node.js

Connecting Node.js to your MySQL database is extremely important to know for any system you will build where data storage is necessary. You can setup a local MySQL database on your system using MAMP and MySQL Workbench.

var mysql = require("mysql");

var connection = mysql.createConnection({
  host: "localhost",
  port: 3306,
  user: "root",
  password: "root", 
  database: "database_name"
});

Example of NodeJS with Geocoder, Inquirer, and Weather-js

First install your 3 dependencies in the same folder.

// Install Geocoder
$ npm install geocoder
// Install Inquirer
$ npm install inquirer
// Install WeatherJS
$ npm install weather-js

Then, you’ll need to have both userprompt.js, geocode.js and package.json in the same folder you are running the terminal command line from.

USERPROMPT.JS

The userprompt.js file should look like this:

var inquirer = require("inquirer");

inquirer.prompt([

  {
    type: "input",
    name: "name",
    message: "Who are you???"
  },

  {
    type: "list",
    name: "doingWhat",
    message: "What are you doing in my house??",
    choices: ["I made you cookies!", "No lie dude. I'm here to rob you.", "Uh. This is my house... Who are YOU???"]
  },

  {
    type: "checkbox",
    name: "carryingWhat",
    message: "What are you carrying in your hands??",
    choices: ["TV", "Slice of Toast", "Butter Knife"]
  },

  {
    type: "confirm",
    name: "canLeave",
    message: "Can you leave now?"
  },

  {
    type: "password",
    name: "myPassword",
    message: "Okay fine. You can stay. But only if you say the magic password."
  }

]).then(function(user) {

  
  if (user.myPassword === "myPassword") {

    console.log("==============================================");
    console.log("");
    console.log("Well a deal's a deal " + user.name);
    console.log("You can stay as long as you like.");
    console.log("Just put down the " + user.carryingWhat.join(" and ") + ". It's kind of freaking me out.");
    console.log("");
    console.log("==============================================");
  }
  else {

    console.log("==============================================");
    console.log("");
    console.log("Sorry " + user.name);
    console.log("I'm calling the cops!");
    console.log("");
    console.log("==============================================");

  }
});

the geocode.js file looks like this:

var geocoder = require("geocoder");
var inquirer = require("inquirer");
inquirer.prompt([
  {
    type: "input",
    name: "userInput",
    message: "Which location or landmark would you like to geocode?"
  }
]).then(function(location) {
  geocoder.geocode(location.userInput, function(err, data) {
    console.log(JSON.stringify(data, null, 2));
  });
});

Finally, run the following command, note that node does not require you to put the .js at the end of a file.

node userprompt

node geocode

Google Material Design Input Boxes

What is Google Material Design?

Google Design Elements
Google continues to expand the capabilities of web design with their “Google Material Design” a CSS3 styling technique utilizing Polymer allowing you to create rich animated applications.

Test out this CSS code on your next input box.

Check out Google’s Polymer design elements here.

Here is a list of dynamic references inside of Polymer:

8 Polymer Elements

paper-checkbox : User can tap the checkbox to check or uncheck it. Usually you use checkboxes to allow user to select multiple options from a set. If you have a single ON/OFF option, avoid using a single checkbox and use paper-toggle-button instead.

paper-dropdown-menu : is similar to a native browser select element. paper-dropdown-menu works with selectable content.

paper-input : is a single-line text field with Material Design styling.

paper-listbox : implements an accessible listbox control with Material Design styling. The focused item is highlighted, and the selected item has bolded text.

paper-radio-button : is a button that can be either checked or unchecked. User can tap the radio button to check or uncheck it. Use a to group a set of radio buttons. When radio buttons are inside a radio group, exactly one radio button in the group can be checked at any time.

paper-radio-group : A group of Material Design radio buttons

paper-slider : A Material Design slider

paper-toggle-button : Paper-toggle-button provides a ON/OFF switch that user can toggle the state by tapping or by dragging the switch.

Example Code

* { box-sizing:border-box; }

/* basic stylings ------------------------------------------ */
body 				 { background:url(http://scotch.io/wp-content/uploads/2014/07/61.jpg); }
.container 		{ 
  font-family:'Roboto';
  width:600px; 
  margin:30px auto 0; 
  display:block; 
  background:#FFF;
  padding:10px 50px 50px;
}
h2 		 { 
  text-align:center; 
  margin-bottom:50px; 
}
h2 small { 
  font-weight:normal; 
  color:#888; 
  display:block; 
}
.footer 	{ text-align:center; }
.footer a  { color:#53B2C8; }

/* form starting stylings ------------------------------- */
.group 			  { 
  position:relative; 
  margin-bottom:45px; 
}
input 				{
  font-size:18px;
  padding:10px 10px 10px 5px;
  display:block;
  width:300px;
  border:none;
  border-bottom:1px solid #757575;
}
input:focus 		{ outline:none; }

/* LABEL ======================================= */
label 				 {
  color:#999; 
  font-size:18px;
  font-weight:normal;
  position:absolute;
  pointer-events:none;
  left:5px;
  top:10px;
  transition:0.2s ease all; 
  -moz-transition:0.2s ease all; 
  -webkit-transition:0.2s ease all;
}

/* active state */
input:focus ~ label, input:valid ~ label 		{
  top:-20px;
  font-size:14px;
  color:#5264AE;
}

/* BOTTOM BARS ================================= */
.bar 	{ position:relative; display:block; width:300px; }
.bar:before, .bar:after 	{
  content:'';
  height:2px; 
  width:0;
  bottom:1px; 
  position:absolute;
  background:#5264AE; 
  transition:0.2s ease all; 
  -moz-transition:0.2s ease all; 
  -webkit-transition:0.2s ease all;
}
.bar:before {
  left:50%;
}
.bar:after {
  right:50%; 
}

/* active state */
input:focus ~ .bar:before, input:focus ~ .bar:after {
  width:50%;
}

/* HIGHLIGHTER ================================== */
.highlight {
  position:absolute;
  height:60%; 
  width:100px; 
  top:25%; 
  left:0;
  pointer-events:none;
  opacity:0.5;
}

/* active state */
input:focus ~ .highlight {
  -webkit-animation:inputHighlighter 0.3s ease;
  -moz-animation:inputHighlighter 0.3s ease;
  animation:inputHighlighter 0.3s ease;
}

/* ANIMATIONS ================ */
@-webkit-keyframes inputHighlighter {
	from { background:#5264AE; }
  to 	{ width:0; background:transparent; }
}
@-moz-keyframes inputHighlighter {
	from { background:#5264AE; }
  to 	{ width:0; background:transparent; }
}
@keyframes inputHighlighter {
	from { background:#5264AE; }
  to 	{ width:0; background:transparent; }
}

C# Example of Math Expressions, Variables, and If Statements

Anyone getting into C# and ASP.NET development will likely be starting with basic expressions, variables, and if statements. Get familiar with these concepts:


private void radioButton1_CheckedChanged(object sender, EventArgs e) 
{ 
    string x = this.textBox1.Text; 
    string y = this.textBox2.Text; 
    if (x == "") //See if x has no value 
    { 
        x = "0"; //Set x to 0 
    } 
    if (y == "") //See if x has no value 
    { 
        y = "0"; //Set y to 0 
    } 
    int x_number = Convert.ToInt32(x); //Converts the string x to a number then stores it in x_number 
    int y_number = Convert.ToInt32(y); 
    int random = x_number + y_number; //Sets the integer variable random to the value of x_number plus y_number 
    string random_string = Convert.ToString(random); //Converts the integer random to the string random_string 
    this.label3.Text = random_string; 
}

SQL INNER JOIN and Full OUTERJOIN

The INNER JOIN keyword selects records that have matching values in both tables.

SELECT column_name(s)
FROM table1
INNER JOIN table2 ON table1.column_name = table2.column_name;

/// EXAMPLE ///

SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;

SQL FULL OUTER JOIN

The FULL OUTER JOIN keyword return all records when there is a match in either left (table1) or right (table2) table records.

Note: FULL OUTER JOIN can potentially return very large result-sets!

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;

SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;

What Are The C# Access Modifiers

public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.

private
The type or member can be accessed only by code in the same class or struct.

protected
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.

protected internal
The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.

What is MVC or Model, View, Controller

In object-oriented programming development, model-view-controller (MVC) is the name of a methodology or design pattern for successfully and efficiently relating the user interface to underlying data models. The MVC pattern is popular when coding with Java, C, and C++.

A Model : Represents the underlying, logical structure of data in a software application and the high-level class associated with it. This object model does not contain any information about the user interface.

A View : Is a collection of classes representing the elements in the user interface (all of the things the user can see and respond to on the screen, buttons, display boxes, etc.)

A Controller : Represents the classes connecting the model and the view, and is used to communicate between classes in the model and view.

More Basic:
Model = Handles data and business logic.
View = Presents data to the user in any layout form.
Controller = Receives user requests and calls appropriate resources to execute them.

MVC Follows This Basic Flow:

Let’s take the program Spotify

1. The user interacts with the user interface in some way, say they press the button to add a song to the playlist.

2. A controller handles the input event from the user interface, often via a registered handler or callback.

3. The controller notifies the model of the user action, possibly resulting in a change in the model’s state. In this instance the song is added to a playlist.

4. A view uses the model (indirectly) to generate an appropriate user interface (i.e. the view produces a screen displaying your music list made in Spotify). The view gets its own data from the model. The model has no direct knowledge of the view.

5. The user interface waits for further user interactions, which begins the cycle again.

Example of a MVC pattern : A calculator

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
// Note: The view should not send to the model but it is often useful
// for the view to receive update event information from the model. 
// However you should not update the model from the view.
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        frmCalcView view = new frmCalcView();
        CalculatorModel model = new CalculatorModel();
        CalcController controller = new CalcController(model, view);
        Application.Run(view);
    }
}
/// <summary>
/// The controller process the user requests.
/// Based on the user request, the Controller calls methods in the View and
/// Model to accomplish the requested action. 
/// </summary>
class CalcController : IController
{
    ICalcModel model;
    ICalcView view;

    public CalcController( ICalcModel model, ICalcView view)
    {
        this.model = model;
        this.view = view;
        this.view.AddListener(this); // Pass controller to view here.
    }

    public void OnClick( int number )
    {
        view.Total = model.SetInput(number).ToString();
    }

    public void OnAdd()
    {
        model.ChangeToAddState(); 
    }
}

Example of a MVC pattern : IController

/// <summary>
/// Windows Form that will host our MVC based functionality.
/// 
/// </summary>
public partial class frmCalcView : Form, ICalcView
{
    IController controller;
    public frmCalcView( )
    {
        InitializeComponent();
    }
    /// <summary>
    /// The view needs to interact with the controller to pass the click events
    /// This could be done with delegates instead.
    /// </summary>
    /// <param name="controller"></param>
    public void AddListener( IController controller )
    {
        this.controller = controller;
    }
    private void lbl_Click(object sender, EventArgs e)
    {
        // Get the text out of the label to determine the letter and pass the
        // click info to the controller to distribute.
        controller.OnClick((Int32.Parse(((Label)sender).Text)));
    }
    private void lblPlus_Click(object sender, EventArgs e)
    {
        controller.OnAdd();
    }

#region ICalcView Members
    public string Total
    {
        get
        {
            return textBox1.Text;
        }
        set
        {
            textBox1.Text = value;
        }
      }
#endregion
}

Here is a look at the model

 /// <summary>
    /// Calculator model, The model is independent of the user interface.
    /// It doesn't know if it's being used from a text-based, graphical, or web interface
    /// This particular model holds the state of the application and the current value.
    /// The current value is updated by SetInput
    /// </summary>
    class CalculatorModel : ICalcModel
    {
        public enum States { NoOperation, Add, Subtract };
        States state;
        int currentValue;
        public States State
        {
            set { state = value; }
        }
        public int SetInput ( int number )
        {
            if (state == States.NoOperation)
            {
                currentValue = number;
            }
             else if (state == States.Add)
            {
                currentValue = Add(currentValue , number );
            }
            return currentValue;
        }
        public void ChangeToAddState()
        {
            this.state = States.Add;
        }
        public int Add( int value1, int value2 )
        {
            return value1 + value2;
        }
        public int Subtract(int value1, int value2)
        {
            throw new System.ApplicationException(" Not implemented yet");
        }
}

4 Pillars of Object Oriented Programming

1.Abstraction
Abstraction is a process of exposing essential feature of an entity while hiding other irrelevant detail. Why would you want to use abstraction? abstraction reduces code complexity and at the same time it makes your aesthetically pleasant.

2.Encapsulation
We have to take in consideration that Encapsulation is somehow related to Data Hiding.
Encapsulation is when you hide your modules internal data and all other implementation details/mechanism from other modules. it is also a way of restricting access to certain properties or component. Remember, Encapsulation is not data hiding, but Encapsulation leads to data hiding

3.Inheritance
The ability of creating a new class from an existing class. Like the word Inheritance literally means it is a practice of passing on property, titles, debts, rights and obligations upon the death of an individual. in OOP this is somehow true(Except the death of an individual) ,where The base class(the existing class sometimes called as the Parent class) has properties and methods that will be inherited by the sub class (sometimes called a subtype or child class) and it can have additional properties or methods.

Inheritance is also a way to use code of an existing objects.

4. Polymorphism
Just like in biology, Polymorphism refers to the ability to take into different forms or stages.A subclass can define its own unique behaviour and still share the same functionalities or behavior of its parent/base class.Yes, you got it right, subclass can have their own behavior and share some behaviour from its parent class BUT!! not vice versa. A parent class cannot have the behaviour of its subclass.

What are Stacks and Bubble Sorts

Stacks are a type of list in which all inserts and removals happen at one end

class stack
{
  public:
    stack(void);                // Constructor and Initializer

    bool push(int data);        // Push onto stack
    bool pop(int data);         // Pop from stack
    int  peek(int depth);       // Peek several layers down

  private:
    const int MAX_SIZE;         // Maximum stack size
    int   stack_data[MAX_SIZE]; // Stack Data Array
    int   stack_top;            // Keeps track of Stack Top
};

BUBBLE SORT

// By convention, 'n' is usually the size of the
// array to be sorted.
void bubblesort( int array[], int n )
{
  for ( int i = 0; i < n-1; ++i )
    for ( int j = 1; j < n-i; ++j )
      if ( array[j-1] > array[j] )
        // Note the use here of swap()
        swap( array[j-1], array[j] );
}

Top New Game Engine List

Game development is becoming a huge money making industry. Game developers have countless tools, engines, and platforms to develop with. Here is a list of popular game development platforms and engines. Some can be used with almost little coding knowledge while others will require an advanced understanding of languages like C#, Javascript, HTML5 etc.

So get learning, you could easily with a few months of work develop the next big iPhone, Android, Xbox, or PlayStation game!

cocos2dx-game-engine

Cocos 2D-X

Develop: Mobile Application Games
Environments:
OSX / Windows
Cocos2D-X is an open source cross-platform game framework written in C++ / Javascript / Lua. It can be used to build games, apps and other interactive programs. There are some independent editors in the cocos2d community, such as those contributing in the areas of SpriteSheet editing, particle editing, font editing and Tilemap editing as well as world editors including SpriteBuilder and CocoStudio. Games include Angry Bird Fight, Clash of Kings, and Brave Frontier.


cg-compile-games-engine-logo

Compile Games

Develop: Platform / 2D Games / Mobile Applications
Environments:
Windows / Ubuntu / Linux / OSX / iOS/Android
GDevelop is an open source, cross-platform game creator designed to be used by everyone – no programming skills required.


torque3d-game-engine-logo

Torque3D

Develop: 3D Games
Environments: Windows / OSX / Linux
Torque has been around for a while, and used for everything from driving simulators to MMOs to interactive coral reefs. Under the permissive MIT open-source license, you can do what you want with the source code. Some notable games include; Frozen Cortex, Tower Wars, and Airship Dragoon.


open-ra-game-engine

OpenRA

Develop: Real-Time Strategy Games
Environments: Windows / OSX / Debain / Ubuntu / Fedora / Linux / Others
OpenRA recreates and modernizes the classic Command & Conquer real time strategy games. It’s a flexible open source game engine that provides a common platform for reimagining classic 2D and 2.5D real-time strategy games. Native support for modern operating systems and screen resolutions and also integrates online multiplayer functionality.


openage-game-logo

Openage

Develop: Real-Time Strategy Games
Environments: Windows / OSX
Openage is a volunteer project to create a free engine clone of Age of Empires II, primarily aimed at POSIX platforms such as GNU/Linux, comparable in its goals to projects like OpenMW, OpenRA, OpenTTD and OpenRCT2. Openage uses the original game assets (such as sounds and graphics), but (for obvious reasons) doesn’t ship them. To play, you require an original AoE II : TC installation or AoE II: HD (installation via Wine or Steam-Linux).


unity-game-engine-logo

Unity 3D

Develop: 2D / 3D Games
Environments: Windows / OSX / Linux
Unity is a cross-platform game engine developed by Unity Technologies and used to develop video games for PC, consoles, mobile devices and websites. First announced only for OS X, at Apple’s Worldwide Developers Conference in 2005, it has since been extended to target 27 platforms.


atomic-game-engine-logo

Atomic Engine

Develop: 2D / 3D Games
Environments: Windows / OSX / Linux
The Atomic Game Engine is powerful 2D/3D technology developed by industry veterans and contributors from around the world. It is lean, full source, technology for mobile and desktop. It has a powerful core API with access to raw, down to the metal, native performance.


construct-game-engine-logo

Construct2

Develop: Web-Based Games
Environments: Windows
Construct is an HTML5-based 2D game editor. It is aimed primarily at non-programmers, allowing quick creation of games in a drag-and-drop fashion using a visual editor and a behavior-based logic system.


game-maker-engine-logo

GameMaker Studio

Develop: 2D / 3D Games
Environments: Windows / OSX
With a drag-and-drop development environment, GameMaker eliminates the barrier most people face when starting out in game development. Using the built-in GML language, you learn to program as you go and not jump in at the deep end of coding. A single development workflow allows you export your game directly to Windows, Mac OS X, Ubuntu, Android, iOS, and HTML5. Bring your games to life with 2D physics, create a thriving player base with cross-platform network play, and create stunning visual effects using shaders.


gameblox-game-engine-logo

Gameblox

Develop: Web-Based Games
Environments: Browser
Gameblox is a game editor that uses a blocks based programming language to allow anyone to make games. It’s free and no downloads are required. You can make games online that you can play both on this site and on your mobile device.


MonoGame

Develop: 2D / 3D Games
Environments: Windows / OSX / Linux
By leveraging C# and other .NET languages on Microsoft and Mono platforms you can write modern, fast, and reliable game code. Currently supports iOS, Android, MacOS, Linux, all Windows platforms, OUYA, PS4, PSVita, and Xbox One. Over 1,000 shipped games Mono has built up a vibrant community of developers.


twine-game-engine-logo

Twine

Develop: Story Lines Games
Environments: Windows / OSX / Linux
Twine is an open-source tool for telling interactive, nonlinear stories, such as which way games. You can utilize graphics and sounds for developing simple yet fun story games.