ReactJS : Bootstrap Thumbnail Matrix / Grid Gallery




Demo code: Download


for running :]

<script type="text/babel">

'use strict';

var ThumbnailMatrixItem= React.createClass({
render: function() {
return (
 <div className="col-lg-3 col-md-4 col-xs-6">
          <a href="#" className="d-block mb-4 h-100">
            <img className="img-fluid img-thumbnail" src={this.props.imgUrl} 
alt="" />
          </a>
        </div>
 );
 }
});

var ThumbnailMatrix= React.createClass({
render: function() {
var productNodes= this.props.items.map(function (product) {
 return (
  <ThumbnailMatrixItem name={product.name} description={
product.description} price={product.price} imgUrl={product.imgUrl}>
</ThumbnailMatrixItem>
        );
 });

return (
 <div className="container"> 
       <h1 className="my-4 text-center text-lg-left">{this.props.title}</h1>

        <div className="row text-center text-lg-left">
 {productNodes}
 </div>
 </div>
       );
}
});

ReactDOM.render(<ThumbnailMatrix title="Bootstrap Thumbnail Gallery" items={
productData}/>, document.getElementById('thumbnailGridDemo'));



//product data

var productData= [
{name: "Priduct 1", description: "product1 description goes here",imgUrl:
 "img/400x300.png", price: "$150"},
{name: "Product 2", description: "product2 description goes here",imgUrl:
 "img/400x300.png",price: "$50"},
{name: "Product 3", description: "product3 description goes here",imgUrl:
 "img/400x300.png",price: "$30"},
{name: "Priduct 41", description: "product1 description goes here",imgUrl:
 "img/400x300.png",price: "$150"},
{name: "Product 52", description: "product2 description goes here",imgUrl:
 "img/400x300.png",price: "$50"},
{name: "Product 63", description: "product3 description goes here",imgUrl:

 "img/400x300.png",price: "$30"},
{name: "Priduct 71", description: "product1 description goes here",imgUrl: 
"img/400x300.png",price: "$150"},
{name: "Product 82", description: "product2 description goes here",imgUrl: 
"img/400x300.png",price: "$50"},
{name: "Product 93", description: "product3 description goes here",imgUrl: 
"img/400x300.png",price: "$30"},
{name: "Product 95", description: "product3 description goes here",imgUrl:
 "img/400x300.png",price: "$30"},
{name: "Product 96", description: "product3 description goes here",imgUrl: 
"img/400x300.png",price: "$30"},
{name: "Product 99", description: "product3 description goes here",imgUrl: 
"img/400x300.png",price: "$30"},
 ];
</script>

Dependencies:

    <script src="libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="libs/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
    <script src="libs/react/0.14.2/react.js"></script>
    <script src="libs/react/0.14.2/react-dom.js"></script>
    <script src="libs/babel/babel-core/5.8.23/browser.min.js"></script>


Spring Security + Hibernate : Enabling database login via Annotations

Hibernate Entities:

Employee.java
===========
package com.mycompany.myapp.entity;

import javax.persistence.*;
import java.util.*;

@Entity
@Table(name = "employee")
public class Employee {

    private long id;
    private String username;
    private String password;

    @Column(name = "enabled", columnDefinition = "boolean default true",
     nullable = false)
    private Boolean enabled = true;

    @Id
    @GeneratedValue
    @Column(name = "id")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

//...

//other getters, setters

}

EmployeeRoles.java:
============
package com.mycompany.myapp.entity;

import javax.persistence.*;


@Entity
@Table(name = "employee_roles")
public class EmployeeRoles{

 private int id;
 private String employeeCode;
 private String role;

 @Id
 @GeneratedValue
 @Column(name = "id")
 public int getId()
 {

     return id;

 }

 
 public void setId(int id)
 {

     this.id = id;

 }

//other getters, setters
}

Initial Roles:

src/main/resources/import.sql:
====================================
insert into employee_roles(employee_code,role) 
values('SOME_EMPLOYEE_CODE','ROLE_USER');

Spring Security config:

WebSecurityConfig.java:
===================
package com.mycompany.myapp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication
.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders
.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration
.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configuration
.EnableWebSecurity;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation
.ResourceHandlerRegistry;
import javax.sql.*;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/webjars/**","/webjars/","/img/**",
                 "/styles/**","/js/**","/api/1.0/get**", "/about.html")
                 .permitAll().anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
                
    }


    @Autowired
    DataSource dataSource;
    
    @Autowired
    public void configAuthentication(AuthenticationManagerBuilder auth) 
throws Exception {
         
            auth.jdbcAuthentication().dataSource(dataSource)
       .usersByUsernameQuery(
          "select username,password, enabled 
                           from employee where username=?")
         .authoritiesByUsernameQuery(
            "select employee_code, role 
                        from employee_roles where employee_code=?");
    }
}

Configuring legacy Cisco UCS C240 M3 v2 server power restore policy for automatic startup on power restore

Untitled

Server automatic start-up policy on power on/restore may come useful incase office building suffers temporary frequent power outages:

Setting up CIMC:

Restart and during server startup press F8 and it should bring up BIOS CIMC(Cisco Integrated Management Console):

  • Set NIC mode = Dedicated
  • Set NIC redundancy = None
  • Uncheck IPv6 and DHCP**
  • Set CIMC IP ( different from server IP ),subnet mask ( usually same as server ) and gateway ( usually same as server )
  • Set default user password for user ‘admin
  • Press F10 to save configuration
  • Restart server.

Locating CIMC port:

At this point you have only provided all must have configurations for CIMC to be accesed. While browsing through server BIOS I could not find an option like ‘Power On on Power Restore’. I was struggling to find an answer on serverfault.com. Credit goes to Rob who introduced me to all these CIMC stuffs [ Thank you Rob :) ].

So, what is CIMC:

CIMC is a system management chip seperate from BIOS which runs an SSH service + an HTTP service independent of operating system. Many servers include a dedicated ethernet port for accessing CIMC. Our next job would be:

  • Locate CIMC port on server ( it should be an ethernet port marked ‘M’ on the back of the server ).
  • Connect server CIMC port to server switch via a CAT6 ethernet cable.

At this point we are finished our setup & are ready to access CIMC. CIMC can be accessed from any machine within local network via browser(http) or terminal(ssh).

Accessing CIMC through browser:

  • In case of Google Chrome, fire up a new browser tab and open http://CIMC_IP/
  • Chrome should warn unsafe connection. Click Advanced and Proceed Anyway.
  • Chrome may ask permission for running Flash. Click Allow.
  • At this point we should be redirected to a login page. Specify username ( default is admin ) & password.
  • For setting power policies click Power Policies and set Power Restore Policy* to Power On**.
  • Set Power Delay Type = fixed
  • Set Power Delay Value = 120 ( Warning: delay must be set to some suitable value like 1 or 2 minutes (e.g. 120 seconds). It takes some time for server itself to get completely ready, before executing ‘Power On’ event upon power restore. In our case ‘Power On’ did not work because we had set it 0 or 5/6 seconds. Setting 120 seconds delay solved it. )

Accessing CIMC through ssh:

Google Chrome will terminate flash support following December 2020. So, lets stick to ssh: * Fire up a new terminal window and type in following command, and run:

ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 admin@CIMC_IP

We need diffie-hellman-group1-sha1 because legacy Cisco devices offer old diffie-hellman-group1-sha1 as a key exchange algorithms.

Run following commands:

Note that you have to commit every changes to persist them in server config.

References:

https://www.cisco.com/c/en/us/td/docs/unified_computing/ucs/c/sw/gui/config/guide/1-0_1x/b_Cisco_UCS_C-Series_Servers_Integrated_Management_Controller_Configuration_Guide_1-0_1x.pdf
https://vinf.net/2014/09/18/press-f8-to-enter-cimc-configuration-does-not-work-on-cisco-c-class-rack-mount-server/ https://www.cisco.com/c/en/us/td/docs/unified_computing/ucs/c/sw/cli/config/guide/4_0/b_Cisco_UCS_C-Series_CLI_Configuration_Guide_40/b_Cisco_UCS_C-Series_CLI_Configuration_Guide_40_chapter_011.html