IamCalvinBrown.com a Blog Site

Code Examples, Consulting Advice and lots of other cool things

AWS Connect to SQL Server using Lambda

/* there's a package that needs to be uploaded -- email calvin@kairuconsulting.com for this package. It's a zip that can be uploaded to AWS Lambda  */

const sql = require('mssql');

exports.handler = function(event, context, callback) {   

    const config = {

        user: 'your_user',

        password: 'your_password',

        server: 'abcd1234.us-east-1.rds.amazonaws.com',

        database: 'AdventureWork'

    };

    sql.connect(config, (err) => {

    

    if (err) 

    {

      console.log('Error ' + err);

      callback(err);

    } 

    else 

    {

        const req = new sql.Request();

        req.query('SELECT * FROM your_table', (error, result) => {

        if (error) 

        {

          console.log('Error' + error);

          callback(error);

        } 

        else 

        {

          console.log('Result' + result);

          sql.close();

          callback(null, result.recordset);

        }

      });

    }

  });

    

    //callback(null, "some success message");

};


AWS CLI - Delete all files matching a filter in an S3 bucket

Amazon AWS can be amazing and interesting to deal with at times. When you host a static website using S3 and Route 53, it sometimes creates files for each request the service receives. To purge these files and avoid having tens of thousands or even millions of useless files, use this command on your local CLI:

#Delete all files that name start with "2018" files from the bucket:

aws s3 rm s3://[your-aws-bucket-name]/ --recursive --exclude '*' --include '2018*'

Google Big Query - Patents DB

#standardSQL

SELECT

publication_number,

publication_date,

claims.text,

abstract.text as ab_text

FROM

  `patents-public-data.patents.publications_201710`,

  UNNEST(claims_localized) AS claims,

  UNNEST(abstract_localized) AS abstract

LIMIT  10

Run the same app twice on a MAC

Many of us have the need to run the same app twice. Especially during development testing. If you're like me, you'd like to see the iPad and iPhone versions of the app side-by-side. It's possible, and there's only 1 line required to make that happen.


open -n -a "APPLICATION NAME"

ex: open -n -a "Visual Studio"


You're welcome

What device am I on? - Xamarin Forms


When a customer uses their tablet versus their phone, your app may appear less than stellar. Here's the code necessary to determine which device your app is running on and make changes to item sizes (ex: fonts, spacing, etc) to make your app appear made for all devices.

if ( Device.Idiom == TargetIdiom.Tablet)

{

        // perform all operations tablet related

}

What to Look for When Hiring for DevOps Jobs


Calvin Brown is the DevOps Architect & Lead Developer for Kairu Consulting, LLC.

“The most important things to look for in both developers and operations persons (DevOps) is…”

How much they know about the other areas of the project. To explain, a project consists of these 3 elements: what the user sees, the code that runs, and the platform(s) that it runs on. That’s also usually broken into 3 careers: graphics, developers, and operations.

A good developer would know how to release their product to the world and how to check for security vulnerabilities, deploy machines, and use some of the same tools as the operations team. True, this is two career paths, but consultants like myself who must deliver a product online for our customers to see (and pay for) must know the basics of operations. The same is true for operations folks. Knowing how to build the code for release, write basic scripts, and deploy code is critical in today’s environment. The Cloud (especially Amazon AWS) makes this more of a reality. If a developer says they use AWS and understand EC2, they’re DevOps types of guys (and ladies). If operations candidates know CI/CD (continuous integration/continuous deployment), then they’re likely DevOps ready as well.

(original article available on Stackify at http://bit.ly/2xMas4k )

Smart answers for your next DevOps interview: How to prepare


General queries

What is DevOps?

Your response should reflect your knowledge of the main theme common to any DevOps effort: It’s about operationalizing and deploying software and services with greater speed, agility, and flexibility.

Point out that the “smooth deployment of software is what DevOps attempts to codify,” says Calvin Brown, enterprise architect and founder of custom software development and consulting firm Kairu Consulting. Comment on how the core of DevOps lies with components such as an agile relationship between software development and IT operations, the management of security and software development processes for improved release efficiency, and the automation of tasks, he says.

Read the full article on TechBeacon.com at http://bit.ly/2uFP6mg

(repost from the original article on TechBeacon.com)

How to query using linq to objects in .net

Want to query a collection without writing a loop in .NET? Here's a linq expression, and the sample code to help.

// our custom object of data

int[] listOfNumbers = { 12345678910 };

 // use LINQ to get all even numbers

    var result = from number in listOfNumbers
        where (number % 2) == 0
         select number;


To download the sample project, please visit http://bit.ly/2vGZriL