Skip to content

Instantly share code, notes, and snippets.

View cookie-ag's full-sized avatar
:octocat:
I may be slow to respond.

Gautam Anand cookie-ag

:octocat:
I may be slow to respond.
View GitHub Profile
@cookie-ag
cookie-ag / Install node using nvm
Created November 16, 2017 13:45
Install / Uninstall Node on OSX
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | sudo bash
nvm install node
nvm run node --version
@cookie-ag
cookie-ag / Fix.txt
Created October 19, 2017 01:08
Fixing: sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- Problem: sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- Cause of this: sudo chown -R $(whoami) /usr/{lib/node_modules,bin,share}.
- Explaination of the root cause:
- "chown -R": change file owner and group information. Use the chmod command to change file access permissions such as read, write, and access.
- "$(whoami)" : Throws the present user
- "/usr": Only the folders {node_modules,bin,share} will have user rights as tp
- The "/usr" directory should have "root" as user.
Solution: The Chown cannot be reverted, so re-install is the safest way.
@cookie-ag
cookie-ag / Challenges.txt
Last active October 26, 2017 10:21
LetsEncrypt SSL for Node.js - Installation and Renewal
- In Standalone phase, one will be asked to clear "TLS-SNI-01 challenge". This can be made valid only by enabling HTTP mode.
@cookie-ag
cookie-ag / Privelliges-Linux.txt
Created October 17, 2017 08:58
Give privileges to a folder on OSX/Linux
sudo chown -R $USER:$GROUP [$Path]
@cookie-ag
cookie-ag / checkRamUsageByProgramName.sh
Last active September 4, 2017 03:41
Memory tools for Linux
#!/bin/sh
ps -eo rss,pid,user,command | sort -rn | head -10 | awk '{ hr[1024**2]="GB"; hr[1024]="MB";
for (x=1024**3; x>=1024; x/=1024) {
if ($1>=x) { printf ("%-6.2f %s ", $1/x, hr[x]); break }
} } { printf ("%-6s %-10s ", $2, $3) }
{ for ( x=4 ; x<=NF ; x++ ) { printf ("%s ",$x) } print ("\n") }
'
@cookie-ag
cookie-ag / chmod.txt
Created August 23, 2017 08:46
Change ownership of a specific folder on Ubuntu
sudo chown -R $USER:$USER Uploads/
@cookie-ag
cookie-ag / npm-global-without-sudo-osx-linux.txt
Last active August 20, 2017 03:05
Using npm without sudo (OSX/Linux)
# Goto home dir
- cd "${HOME}"
# Check where npm is installed
- npm config get prefix (The output is generally "/usr/local"
# Change the permissions
- sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
@cookie-ag
cookie-ag / mongodb-grunt.js
Last active August 18, 2017 03:58
Backup/Restore from MongoDB
//npm i -g grunt-cli
//npm i grunt grunt-mongo-backup
//tested on 0.0.2
'use strict';
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-mongo-backup');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
mongobackup: {
@cookie-ag
cookie-ag / auth.js
Created August 4, 2017 06:40
HTTP auth in Node.js
'use strict';
var basic_Auth = require('basic-auth');
//HTTP Authentication
exports.enableAuth = function(req, res, next) {
function unauthorized(res) {
res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
return res.sendStatus(401);
}
@cookie-ag
cookie-ag / HTTPReq.js
Last active September 7, 2017 04:31
Query logging database (MongoDB)
db.getCollection('Logging').count({"status":{$eq: 200}}) //Equal to 200
db.getCollection('Logging').count({"status":{$gt: 399}}) //Greater than to 399, HTTP Errors
db.getCollection('Logging').count({"status":{$lt: 399}}) //Less than 399, HTTP Success