Skip to content

Instantly share code, notes, and snippets.

View sandheepg's full-sized avatar

Sandeep Guduru sandheepg

View GitHub Profile
@sandheepg
sandheepg / mongo-nrecords.md
Created August 1, 2017 07:02
Last N records from MongoDB collection

If you want the last 5 records of a collection with latest coming first

db.getCollection('collection-name').find().limit(5).sort({$natural:-1})
@sandheepg
sandheepg / sql-commands-definition.md
Created July 28, 2017 13:19
SQL Commands Definition
Data definition
CREATE - Creates a new database or a table.  
ALTER - Modifies the structure of a database or a table.  
DROP - Deletes a database or a table.  
TRUNCATE - Removes all table records, including allocated table spaces.  
Data manipulation
@sandheepg
sandheepg / nginx-restart.md
Created July 28, 2017 12:46
Nginx Restart

After modifying the configuration files for nginx, type

sudo nginx -t

to check for any syntax errors.

sudo nginx -s reload
@sandheepg
sandheepg / manage-services-linux.md
Last active July 28, 2017 12:45
Manage Services in Linux

There are many ways out there to manage a Linux service depending on the distribution you are using.

This mainly boils down to if your distribution uses systemd or init. Based on that, systemctl and service are two officially adopted service managers for controlling services.

Intrestingly, service command still works even for those distributions that have migrated to systemd and systemctl.

Lets take the example of restarting nginx service to see how this can be done.

Type the below commands in the terminal to restart nginx for the changes to take effect.

@sandheepg
sandheepg / listening-ports.md
Last active July 24, 2017 11:23
Check for listening ports in Linux

As a developer / administrator, its important to know which ports are listening on the server's network interfaces. They are important for a variety of reasons. To name a few,

  • To check if a port is already in use by a different application
  • To troubleshoot any issues
  • To detect any intrusion

To determine if a port is in use under an Unix-like system you can use lsof, netstat, nmap commands.

@sandheepg
sandheepg / rails-robots-txt.md
Last active December 30, 2024 15:48
Dynamic Robots.txt file in Rails

robots.txt file controls what pages of your allplications gets crawled by the serach engine bots. As part of robots.txt file we can allow or disallow single pages or directories within the application.

robots.txt file lives in the root folder of your application. A simple, static solution in Rails would be, to put a robots.txt file into you /public folder in your rails app but then you can't dynamically set the content of this file.

If you want a different file for staging and production server or want some dynamic routes in your robots.txt, then you need to generate this file with rails. Make sure you remove/rename robots.txt from /public folder.

@sandheepg
sandheepg / homebrew-node-versions.md
Created July 20, 2017 06:47
Manage multiple Node versions on Mac

This assumes that you have Homebrew installed in first place and used it to install Node. To manage multiple Node versions on your development server, first search for your desired pacakage

brew search node

Pick a version of your choice and run

brew install node@6
@sandheepg
sandheepg / node-npm-mac.md
Created July 19, 2017 12:57
Manage Node and NPM on Mac

Installing Node.js and NPM is pretty straightforward using Homebrew. Assuming that you have Homebrew and XCode installed on your Mac, open Terminal and type

brew install node

To see if Node and NPM are installed, type

node -v
npm -v
@sandheepg
sandheepg / mysql-remote.md
Created July 19, 2017 09:39
MySQL remote connection

To make sure MySQL server listens to remote requests (other than orginating from localhost), edit MySQL configuration file using sudo

/etc/mysql/my.cnf
OR
any other file mentioned in the config file w/ includedir directives

and update

bind-address = 127.0.0.1
TO
@sandheepg
sandheepg / ssl-old-ubuntu.md
Last active July 17, 2017 18:36
Setting up Lets Encrypt SSL on older versions of Ubuntu

The default “certbot” client will not work on older versions of Ubuntu because of outdated python and openssl versions. Here is a quick script that does the job. https://github.com/Neilpang/acme.sh

After installing the script, run

acme.sh --issue -d domain.in -d www.domain.in -w /var/www/document-root \
--certpath /etc/ssl/certs/domain.in.crt \
--keypath /etc/ssl/certs/domain.in.key \
--fullchainpath /etc/ssl/certs/intermediate.pem \