Keystone.js Framework Tips (2)

keystonejs

1. Test in keystone.js

I use Mocha as test runner to tell what passes and fails, and Chai for assertion or should libraries to run specific tests.

https://groups.google.com/forum/?nomobile=true#!topic/keystonejs/AvpvUpHNTn0

http://stackoverflow.com/questions/22231078/how-do-i-unit-test-keystonejs-models
https://gist.github.com/rtgibbons/e18d8066680a0350fe41

https://github.com/webteckie/keystonejs-stub

process.env.NODE_ENV = process.env.NODE_ENV || 'test';
require('dotenv').load();

var keystone = require('keystone');
var chai = require('chai');
var dbURI = process.env.MONGO_URL

keystone.init({
  'name': 'Post Model Test',
  's3 config': {} //has to be set, but isn't used in our models
});

var Post = null;

keystone.import('../../models');

chai.should();

describe('Posts', function() {
  beforeEach(function(done){
    if (keystone.mongoose.connection.db) return done();
    console.log('Connecting to ' + dbURI)
    keystone.mongoose.connect(dbURI, done);
  });

  it('should be a connection to Mongo', function(done){
    keystone.mongoose.connection.db.should.be.a('Object');
    done();
  });

  it('should be a Mongoose Model', function(done) {
    Post = keystone.list('Post');

    Post.should.be.a('Object');
    Post.should.have.property('model').be.a('Function');
    Post.should.have.property('schema').be.a('Object');

    done();
  });
});

2. create a gap between tr (table rows)

table {
    border-collapse: separate;
    border-spacing: 0 15px;
}

http://stackoverflow.com/questions/1264187/css-how-do-i-create-a-gap-between-rows-in-a-table

http://stackoverflow.com/questions/10690299/how-to-add-a-margin-to-a-table-row-tr

3.Keystone JS CMS Deployment error: cannot find module ‘../build/release/bson’ code ‘module_not_found’

http://stackoverflow.com/questions/28651028/cannot-find-module-build-release-bson-code-module-not-found-js-bson

Solution:

root@keystonejs:~# npm install -g npm-check-updates

debian@keystonejs:~/myproject/manalcjim$ npm-check-updates -u

debian@keystonejs:~/myproject/manalcjim$ npm install

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.

Resource:

A Smarter Way to Learn JavaScript. The new tech-assisted approach that requires half the effort

Secrets of the JavaScript Ninja

Node.js Design Patterns

Web Development with MongoDB and NodeJS

Node.js the Right Way: Practical, Server-Side JavaScript That Scales

Web Development with Node and Express: Leveraging the JavaScript Stack

Learn NodeJS in 1 Day: Complete Node JS Guide with Examples

Learning Node: Moving to the Server-Side

Getting MEAN with Mongo, Express, Angular, and Node

Posted in Uncategorized | Leave a comment

8 HTML, CSS, JavaScript and MongoDB Tips

Languages-cloudwords

1. A million dollar css mistake

Sometimes when you click or highlight a part of text, and it will blink or change to a different color. The reason why it happens is there are multiple style definition (color for active or visited status) for the same part of content, it’s usually created by mistake like the following example.

It intends to define style for keywords_link hover, active visited status, but if it omitted the scope for later two status and they work for globally.

(wrong)

.keywords_link:hover, :active, :visited {

    text-decoration: none;

color: #73c8bd;

}

(correct)

.keywords_link:hover, .keywords_link:active, .keywords_link:visited {

    text-decoration: none;

    color: #73c8bd;

}

2. Enter mongoDB shell and debug one (statement) by one

Cd /usr/local/var/mongodb

/usr/local/bin/mongo

Diff between MongoDB vs Mongoose

http://stackoverflow.com/questions/28712248/difference-between-mongodb-and-mongoose

Location of mongoDB database on mac

http://stackoverflow.com/questions/13827915/location-of-the-mongodb-database-on-mac

https://docs.mongodb.com/manual/reference/mongo-shell/

3. Scroll to related posts area to trigger fetching related posts

http://imakewebthings.com/waypoints/

https://github.com/imakewebthings/waypoints

http://stackoverflow.com/questions/21561480/trigger-event-when-user-scroll-to-specific-element-with-jquery

Trigger once for waypoint (load related posts)

http://imakewebthings.com/waypoints/api/destroy/

http://stackoverflow.com/questions/28113152/not-repeating-the-function-once-waypoint-reached

4. Nodejs libs

https://github.com/sindresorhus/awesome-nodejs

https://blog.nodejitsu.com/6-must-have-nodejs-modules/

5. center a div

margin:0 auto;

http://stackoverflow.com/questions/618097/how-do-you-easily-horizontally-center-a-div-using-css

6. How to implement a load spinner

https://www.w3schools.com/howto/howto_css_loader.asp

http://stackoverflow.com/questions/19445639/how-to-implement-a-jquery-spinner-image-in-an-ajax-request

http://stackoverflow.com/questions/68485/how-to-show-loading-spinner-in-jquery

http://smallenvelop.com/display-loading-icon-page-loads-completely/

https://loading.io

7.  Select random document from MongoDB

Sample operation

https://docs.mongodb.com/manual/reference/operator/aggregation/sample/

skip random number (it might have performance issue)

http://stackoverflow.com/questions/2824157/random-record-from-mongodb

http://stackoverflow.com/questions/39277670/how-to-find-random-record-in-mongoose

8. Use hreflang tag to support multiple languages or regions

https://yoast.com/hreflang-ultimate-guide/

https://support.google.com/webmasters/answer/6059209

https://support.google.com/webmasters/answer/189077

https://support.google.com/webmasters/answer/189077?hl=en

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.

Resource:

A Smarter Way to Learn JavaScript. The new tech-assisted approach that requires half the effort

Secrets of the JavaScript Ninja

Node.js Design Patterns

Web Development with MongoDB and NodeJS

Node.js the Right Way: Practical, Server-Side JavaScript That Scales

Web Development with Node and Express: Leveraging the JavaScript Stack

Learn NodeJS in 1 Day: Complete Node JS Guide with Examples

Learning Node: Moving to the Server-Side

Getting MEAN with Mongo, Express, Angular, and Node

Posted in CS Research&Application, Uncategorized | Tagged , , , , | Leave a comment

Node.js Middleware Packages — sitemap, robots.txt

Dynamic sitemap generation for applications built on KeystoneJS
Express middleware for generating a robots.txt or responding with an existing file.
Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.

 

Resource:

A Smarter Way to Learn JavaScript. The new tech-assisted approach that requires half the effort

Secrets of the JavaScript Ninja

Node.js Design Patterns

Web Development with MongoDB and NodeJS

Node.js the Right Way: Practical, Server-Side JavaScript That Scales

Web Development with Node and Express: Leveraging the JavaScript Stack

Learn NodeJS in 1 Day: Complete Node JS Guide with Examples

Learning Node: Moving to the Server-Side

Getting MEAN with Mongo, Express, Angular, and Node

Posted in CS Research&Application, Uncategorized | Tagged , , , , | Leave a comment

iOS (Objective C) Development Tips

iOS-App-Development-Tips-1300x491

1. UITableView vs UICollectionView scroll to bottom

UITableView scroll to bottom (2nd answer)

UICollectionView scroll to bottom
Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.

 

Resource:

Professional iOS Programming

Advanced Swift: Updated for Swift 3

iOS Apps for Masterminds, 2nd Edition: How to take advantage of Swift 3 to create insanely great apps for iPhones and iPads

iOS Components and Frameworks: Understanding the Advanced Features of the iOS SDK (Developer’s Library)

iPhone Advanced Projects (Books for Professionals by Professionals)

iOS Core Animation: Advanced Techniques

Swift Cookbook – 50 Recipes to Help You Harness Swift

development of advanced and practical iOS 6(Chinese Edition)

Posted in Uncategorized, iOS | Tagged , , , , | Leave a comment

Node.js Interview Questions and Tips

1. ECMAScript 6 (ES6) New Features:

Arrows

Arrows are a function shorthand using the => syntax. They are syntactically similar to the related feature in Java 8, C# and CoffeeScript. They support both statement block bodies as well as expression bodies which return the value of the expression. Unlike functions, arrows share the same lexical this as their surrounding code.

Classes

ES6 classes are a simple sugar over the prototype-based Object Oriented pattern. Having a single convenient declarative form makes class patterns easier to use, and encourages interoperability. Classes support prototype-based inheritance, super calls, instance and static methods and constructors.

Enhanced Object Literals

Object literals are extended to support setting the prototype at construction, shorthand for foo: foo assignments, defining methods, making super calls, and computing property names with expressions. Together, these also bring object literals and class declarations closer together, and let object-based design benefit from some of the same conveniences.

Template Strings

Template strings provide syntactic sugar for constructing strings. This is similar to string interpolation features in Perl, Python and more. Optionally, a tag can be added to allow the string construction to be customized, avoiding injection attacks or constructing higher level data structures from string contents.

Destructuring

Destructuring allows binding using pattern matching, with support for matching arrays and objects. Destructuring is fail-soft, similar to standard object lookup foo["bar"], producing undefined values when not found.

Let + Const

Block-scoped binding constructs. let is the new var. const is single-assignment. Static restrictions prevent use before assignment.

Iterators + For..Of

Iterator objects enable custom iteration like CLR IEnumerable or Java Iterable. Generalize for..in to custom iterator-based iteration with for..of. Don’t require realizing an array, enabling lazy design patterns like LINQ.

Iteration is based on these duck-typed interfaces (using TypeScript type syntax for exposition only):

Generators

Generators simplify iterator-authoring using function* and yield. A function declared as function* returns a Generator instance. Generators are subtypes of iterators which include additional next and throw. These enable values to flow back into the generator, so yield is an expression form which returns a value (or throws).

Note: Can also be used to enable ‘await’-like async programming, see also ES7 await proposal.

Unicode

Non-breaking additions to support full Unicode, including new Unicode literal form in strings and new RegExp u mode to handle code points, as well as new APIs to process strings at the 21bit code points level. These additions support building global apps in JavaScript.

Modules

Language-level support for modules for component definition. Codifies patterns from popular JavaScript module loaders (AMD, CommonJS). Runtime behaviour defined by a host-defined default loader. Implicitly async model – no code executes until requested modules are available and processed.

Some additional features include export default and export *:

Module Loaders

Module loaders support:

  • Dynamic loading
  • State isolation
  • Global namespace isolation
  • Compilation hooks
  • Nested virtualization

The default module loader can be configured, and new loaders can be constructed to evaluate and load code in isolated or constrained contexts.

Map + Set + WeakMap + WeakSet

Efficient data structures for common algorithms. WeakMaps provides leak-free object-key’d side tables.

Proxies

Proxies enable creation of objects with the full range of behaviors available to host objects. Can be used for interception, object virtualization, logging/profiling, etc.

Symbols

Symbols enable access control for object state. Symbols allow properties to be keyed by either string (as in ES5) or symbol. Symbols are a new primitive type. Optional description parameter used in debugging – but is not part of identity. Symbols are unique (like gensym), but not private since they are exposed via reflection features like Object.getOwnPropertySymbols.

Subclassable Built-ins

In ES6, built-ins like Array, Date and DOM Elements can be subclassed.

Object construction for a function named Ctor now uses two-phases (both virtually dispatched):

  • Call Ctor[@@create] to allocate the object, installing any special behavior
  • Invoke constructor on new instance to initialize

The known @@create symbol is available via Symbol.create. Built-ins now expose their @@create explicitly.

Math + Number + String + Array + Object APIs

Many new library additions, including core Math libraries, Array conversion helpers, String helpers, and Object.assign for copying.

Binary and Octal Literals

Two new numeric literal forms are added for binary (b) and octal (o).

Promises

Promises are a library for asynchronous programming. Promises are a first class representation of a value that may be made available in the future. Promises are used in many existing JavaScript libraries.

Reflect API

Full reflection API exposing the runtime-level meta-operations on objects. This is effectively the inverse of the Proxy API, and allows making calls corresponding to the same meta-operations as the proxy traps. Especially useful for implementing proxies.

Tail Calls

Calls in tail-position are guaranteed to not grow the stack unboundedly. Makes recursive algorithms safe in the face of unbounded inputs.

 

2. Tools are used in Node.js development

#1 Mocha.js

Mocha.js is a JavaScript test framework based on Node.js. It enables you to test both in console and in the browser. You can use this really fast testing suite to do the unit and integration testing plus it works for TDD (Test-Driven Development) and BDD (Behaviour Driven Development) perfectly. A big advantage of Mocha.js is that it’s modularity so you can easily use other libraries with is, such as Chai, Sinon or Should.js.

#2 Chai

Chai is a TDD and BDD assertion framework for Node.js which can be paired with any testing framework (like Mocha.js we just mentioned). We use Mocha.js to run asynchronous testes, but Chai helps us verify the test results. Chai can be run in a browser or with Node.js. As an assertion tool, we use Chai with its rich plugins (ex. chai-as-promised, chai-subset, chai-things). If we need to test Node.js HTTP servers, we usually use SuperTest https://github.com/visionmedia/supertest (it either makes real requests or simulates them while connected to Express.js)

#3 Sinon.JS

Sinon.js is a standalone testing framework for JavaScript. The great thing about is that it works with any testing framework. It supports stubs, spies and mocks. It also supports most browsers (cross-browser support) and runs on the server using Node.js.

#4 Express.js

Express.js is a must-use minimalist framework for Node.js web applications. A combination of Node.js and Express.js enables you to build software with JavaScript on the server side. Long story short, you could build a whole website with those two: using Node.js to build server-side part of the app and Express.js to publish the app on your website.

#5 WebStrom IDE

WebStorm IDE is an awesome IDE for Javascript. It’s lightweight and it has everything you need for building Node.js applications on the client side and server side. It’s a great tool if you’re doing only JavaScript/HTML/CSS development – WebStorm IDE is a tool made for JS <3.

You can do debugging, tracking (with built-in tool spy-js) and unit testing (with easy to integrate Karma or Mocha.js).

#6 Passport.js

Passport.js is an authentication middleware for Node.js. It gives you a choice of over 300 different ways of authenticating your app including username and password model, login via Facebook, Google, Twitter etc., and many other. It’s extremely easy to implement with any Express.js app.

#7 Socket.io

Socket.io is a framework that enables a bi-directional communication in real-time, based on events. It doesn’t matter which device or platform you’re using – it will work great on anything. The package includes real-time analytics with counters, logs and charts. It’s perfect for chat apps and it’s loved by both big companies such as Microsoft, Zendesk, Trello and small startups.

#8 Webpack

The main function of Webpack is to bundle JavaScript files for usage in a browser. You can create one or many bundles that are asynchronously loaded at a runtime – this reduces the initial loading time.

#9 BlueBird.js

BlueBird.js is a promise library, that helps you to control your asynchronous code. You can separate with it your code into different files without any problem. It’s a must-have if you care about a quality of your code. As an alternative, you can try the Q.

#10 PM2

PM2 is a process manager for Node.js applications. It ‘s simple to use and provides many useful built-in features (like load balancer or watch mode).

#11 Electrode.io

It’s an universal platform for React.js/Node.js applications. It’s brought by WalmartLabs which means that this set of tools had been tested on a huge amount of data. It’s not only a set of best practices, standardized structure and modern technologies – it also includes Electrode Explorer and Electrify. These tools let you explore all docs and components of your platform as well as visualize in a clear and appealing way the module tree of electrode.io + Webpack project bundles.

#12 Meteor.js

Meteor.js is a framework built for rapid prototyping of JavaScript apps and writing cross-platform code (Web, Android, iOS). It’s based on Node.js, integrated with MongoDB and you can use it with any JavaScript UI widget library. Even Y Combinator, the most influential startup accelerator, recommends this tool.

While Meteor.js is great for prototyping apps, it’s good to keep in mind that it might not be the best solution for maintaining the already finished ones.

#13 Vue.js

A great alternative for those who use Angular.js is Vue.js . If you don’t want to build a complex web app and have to configure routings, controllers and services then Vue.js could be the lightweight solution you’re looking for. This framework is focused on a ViewModel – you get features of larger frameworks in a lighter version for your single page applications.

#14 MEAN.JS

MEAN.js is a full-stack JavaScript solution for building web apps. The MEAN stack consists of MongoDB, Express.js, Angular.js and Node.js which means you can build web applications on the client and server side with one stack of tools.

#15 Babel

Babel is a JavaScript compiler. With Babel, you can compile an ECMAScript 6 to ECMAScript 5 easily. It allows you to use ES6 features in your projects and then compiles ES5 for you to use in production.

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.

 

Resource:

A Smarter Way to Learn JavaScript. The new tech-assisted approach that requires half the effort

Secrets of the JavaScript Ninja

Node.js Design Patterns

Web Development with MongoDB and NodeJS

Node.js the Right Way: Practical, Server-Side JavaScript That Scales

Web Development with Node and Express: Leveraging the JavaScript Stack

Learn NodeJS in 1 Day: Complete Node JS Guide with Examples

Learning Node: Moving to the Server-Side

Getting MEAN with Mongo, Express, Angular, and Node

Posted in CS Research&Application, Uncategorized | Tagged , , | Leave a comment

Leet Code Summary and Reflection

 

Array

Tips: keep two points and shrink from left and right to center, check to meet certain requirement (sum equals a target number) until left index is over right one.

Problems: Two Sum, 3Sum, 3Sum Closest, 4Sum, etc.

 

Linked List

Tips:

  1. combine with other data structure like tree, min heap
  2. combine with other algorithms like merge and quick sort
  3. most time use two pointers (slow and fast) to check circular or not, sometimes to find the middle point in linked list
  4. most interview questions emphasize changing node position and keep linking
  5. Take into account whether the change is taking place at the head of the list or someplace else.

Problems: Add Two Numbers, Convert Sorted List to Binary Search Tree, Merge Two Sorted Lists, Partition List, Remove Duplicates from Sorted List, Remove Duplicates from Sorted List II, Remove Nth Node From End of List, Reverse Linked List II, Reverse Nodes in k-Group, Rotate List, Swap Nodes in Pairs

 

Stack

Tips: Input is reversal order of output (Stacks can provide a reversal characteristic.)

Problems: binary tree inorder/preorder/postorder traversal (stack can hold temp node and queue has to deal with it immediately)

 

Dynamic Programming (DP)

Tips:

  1. divide the problem into smaller pieces (smallest as base case)
  2. solve the smaller pieces in some way (toward base case)
  3. reassemble the whole problem to get the result
  4. most times it can be abstracted as: subproblem is moving from a point with 2 directions (right, down), which starts from a certain point (base case) whose condition is fixed, either it’s the destination (bottom right node in a matrix) or elements in last row or level of a tree.

Problems: unique path, triangle, maximal rectangle, minimum path sum, etc.

 

Binary Search

Tips:

Binary tree preorder traversal: easiest one, it could process the current, current left and right nodes immediately, so it doesn’t have to put current node in while loop condition as in-order and take care of previous node.

Binary tree inorder traversal: it has to take care of the current node (record left, self and right order as well, can replace with set) or it can use stack peek method and set (current node is visited or not) to check and then deal with left, self, right node in order.

Binary tree postorder traversal: it has to use a stack and two pointers (current, previous) to check left node, left and right have been visited or not, if not push left and right one by one in stack, then process the current node, if yes, process the current node directly.

Clone Graph: BFS traversal all nodes in neighborhood and store in a queue, then process these nodes one by one. Set to store visited nodes to avoid unlimited cycling, HashMap to store all existing nodes to avoid duplicates and Queue to store nodes in neighborhoods.

Best Time to Buy and Sell Stock: get the min number and the larger one after it (only trade once), or if the current one is larger than previous then trade (trade unlimited times), get max profit so far and max profit from current to the end (trade twice)

Search in Rotated Sorted Array: check which half is sorted, and then narrow the range based on the target number in certain half, skip duplicate input numbers if necessary.

Subsets: recursive, when reach the required number limitation and then return the current subset, skip duplicate input numbers if necessary.

 

 

Recursion (recursion as a form of iteration)

Tips:

  1. Recursion is a method of solving problems that involves breaking a problem down into smaller and smaller subproblems until you get to a small enough problem that it can be solved trivially.
  2.  Usually recursion involves a function calling itself.

Problems: Combination I, Combinations II, Combination Sum, Letter Combinations of Phone Numbers: recursively process the number sequence, add to the temporary results collection, go to next level until reach certain condition (depth equals to length of number array), return upper level and remove the last element added into the temporary results collection, continue to process next number.

 

Big O

Hardware is different, so need a way to measure program efficiency and then use how many times instructions run and how much space (byte, bit) take to finish the program

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.
Resources:
Posted in CS Research&Application, Intern&Job, IT, Uncategorized | Tagged , , | Leave a comment

How to install New Relic Agent in Google App Engine Flexible Environment

og-newrelic-logo

New Relic provides Application Performance Monitoring (APM) for a lot of platforms (AWS, Heroku, etc.) and frameworks (Symphony, Magento, etc.), but there is no much information on the internet so far about steps to install New Relic Agent in Google App Engine (GAE) Flexible Environment (Flex Env), so I did try installing successfully on my production project and then will talk about it here.

Step 1: Create a custom docker image based on Google cloud platform php docker, php nginx image — on local (i.e. mac)

/php-docker/php-nginx/build-scripts/install_new_relic.sh

# A shell script for installing New Relic agent.
set -xe

DEBIAN_FRONTEND=noninteractive echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | tee /etc/apt/sources.list.d/newrelic.list

DEBIAN_FRONTEND=noninteractive apt-get -y install wget
DEBIAN_FRONTEND=noninteractive wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add -

DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y vim less
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends apt-utils

DEBIAN_FRONTEND=noninteractive apt-get install -yq newrelic-php5
DEBIAN_FRONTEND=noninteractive newrelic-install install

/php-docker/php-nginx/Dockerfile

# Setup environment variables for initializing New Relic
ENV NR_INSTALL_SILENT 1
ENV NEW_RELIC_APP_NAME "YourAppName"
ENV NR_APP_NAME "YourAppName"
ENV NR_INSTALL_KEY YourLicenseKey
RUN /bin/bash /build-scripts/install_new_relic.sh

Step 2: Build, tag and upload to Google Cloud Storage (work under application directory) — on local (i.e. mac)

docker build -t php-nginx-new_relic .
docker tag php-nginx-new_relic gcr.io/project-id/php-nginx-new_relic
gcloud docker -- push gcr.io/project-id/php-nginx-new_relic

Step 3: Deploy your project to Google App Engine Flexible Environment — on local (i.e. mac)

gcloud app deploy app.yaml --project project-id --verbosity debug || exit $?

(/YourApp/Dockerfile)

FROM gcr.io/project-id/php-nginx-new_relic

Step 4: ssh to the GAE Flex Env instance and enter docker container — remote GAE Flex Env instance

(Tips: SSH button is located in Google Cloud Platform dashboard, App Engine page, instances sub page, then click the SSH button will let you ssh to the instance)

Step 5: enter docker container — remote GAE Flex Env instance

sudo docker exec -t -i gaeapp /bin/bash

Step 6Install New Relic with installation script manually — remote GAE Flex Env instance docker container gaeapp

wget -r -l1 -nd -A"linux.tar.gz" https://download.newrelic.com/php_agent/release/

gzip -dc newrelic*.tar.gz | tar xf -

cd newrelic-php5*

rm -f /opt/php56/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20131226/newrelic.so

cp ./agent/x64/newrelic-20131226.so /opt/php56/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20131226/newrelic.so

cp ./daemon/newrelic-daemon.x64 /usr/bin/newrelic-daemon

(Set your license key and application name. Be sure to replace yourLicenseKey and yourApplicationName with your real license key and the app name you desire.)

sed -i -e 's/"REPLACE_WITH_REAL_KEY"/yourLicenseKey/g' ./scripts/newrelic.ini.template

sed -i -e 's/PHP Application/yourApplicationName/g' ./scripts/newrelic.ini.template

(((cp ./scripts/newrelic.ini.template /opt/php56/lib/ext.enabled:/opt/php56/lib/conf.d:/app/newrelic.ini, it’s suggested by New Relic but complained error for me, so I separate into 3 steps as following)))

cp ./scripts/newrelic.ini.template /opt/php56/lib/ext.enabled/newrelic.ini

cp ./scripts/newrelic.ini.template /opt/php56/lib/conf.d/newrelic.ini

cp ./scripts/newrelic.ini.template /app/newrelic.ini

/usr/bin/newrelic-daemon start

Step 7: Restart everything and reload the page
kill -HUP 1
(Restart your webserver and reload this page. If New Relic is loaded you should see a congratulatory message.)
congrats
Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.
Reference:
Caveat and tips:

1. Copy paste in GAE Flex Env docker container: tips to scroll and copy at GAE instance docker container (for debugging by view text file with vim which was configured to install in php-nginx Dockerfile if you need vim)

Mac touchpad to select all in the current screen and use Fn+Shift+Down to go up to previous screen and select again with touchpad until select all content in the text file
2. New Relic to monitor Docker container application
3. dockerizing a php application
4. If you want to install New Relic agent in pure automatic way:

Use runtime:custom and add required piece in your Dockerfile, except for the `/usr/bin/newrelic-daemon start` line.
Then have a file named `additional-supervisord.conf` with the following:

“`

[program:newrelic-daemon]

command = /usr/bin/newrelic-daemon -f

stdout_logfile = /dev/stdout

stdout_logfile_maxbytes=0

stderr_logfile = /dev/stderr

stderr_logfile_maxbytes=0

user = root

autostart = true

autorestart = true

priority = 5

stopwaitsecs = 20

“`

5. If you install New Relic on CentOS, yum and rpm installation don’t work for me, but tar ball file works for me and the command should be

./newrelic-install install

 

not

./newrelic-install

as the doc:

Posted in CS Research&Application, Uncategorized | Tagged , , , , , , | Leave a comment