Skip to content

Instantly share code, notes, and snippets.

View kheengz's full-sized avatar

Kingsley Chinaka kheengz

View GitHub Profile
@kheengz
kheengz / git-autodeploy.md
Created February 11, 2019 12:19
How To Set Up Automatic Deployment with Git

When you use Git, the workflow generally is toward version control only. You have a local repository where you work and a remote repository where you keep everything in sync and can work with a team and different machines. But you can also use Git to move your application to production.

Server Setup

Your server live directory: /var/www/domain.com

Your server repository: /var/repos/website.git

What should we do if we want to push to website.git and at the same time make all the content available at /var/www/domain.com?

@kheengz
kheengz / mongodb-aggregation.js
Last active January 28, 2021 08:54
Query Posts by user -> paginated results and a total count.
// Aggregation using MongoDB
/**
* Query posts by user -> paginated results and a total count.
* @param userId {ObjectId} ID of user to retrieve posts for
* @param skip {Number} First row to return in results
* @param limit {Number} Last row to return in results
* @param sort {Object} sort query object
* @returns {Object} Object -> `{ rows, count }`
*/
function queryPostsByUser (userId, skip, limit, sort) {
@kheengz
kheengz / script.sh
Last active October 1, 2018 11:20
Auto Backup DB to AWS S3
1. Install pip > See http://www.saltycrane.com/blog/2010/02/how-install-pip-ubuntu/
2. Install AWS CLI > use: `$ pip install awscli`
3. Go to AWS Console to create a IAM user and download the credentials (Access Key ID and Secret Access Key)
4. Run `$ aws configure` and follow the prompts
*NB: If you get a permission denied error while running *4* : run `$ chmod u+x /usr/bin/aws`*
5. Create S3 bucket on AWS
6. Copy and modify the following commands into a file called `mysql_backup.sh` and using the folder structure 7. below.
```sh
@kheengz
kheengz / index.jsx
Created September 14, 2018 20:21
React Auto Load data on bottom scroll of page
var InfiniteData = React.createClass({
getInitialState: function () {
return ({data: [], requestSent: false});
},
componentDidMount: function () {
window.addEventListener('scroll', this.handleOnScroll);
this.initFakeData();
},