Skip to content

Instantly share code, notes, and snippets.

View iMagesh's full-sized avatar
🏠
Working from home

Magesh iMagesh

🏠
Working from home
View GitHub Profile
@iMagesh
iMagesh / list-express-routes.js
Created February 9, 2022 14:41
Code to list all the routes of your express app (node)
//If you are using express router
var route, routes = [];
app._router.stack.forEach(function(middleware){
if(middleware.route){ // routes registered directly on the app
routes.push(middleware.route);
} else if(middleware.name === 'router'){ // router middleware
middleware.handle.stack.forEach(function(handler){
route = handler.route;
@iMagesh
iMagesh / service.js
Created November 18, 2019 10:52 — forked from paulsturgess/service.js
An example Service class wrapper for Axios
import axios from 'axios';
class Service {
constructor() {
let service = axios.create({
headers: {csrf: 'token'}
});
service.interceptors.response.use(this.handleSuccess, this.handleError);
this.service = service;
}

Problem

I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).

Solution

Use ssh keys and define host aliases in ssh config file (each alias for an account).

How to?

  1. Generate ssh key pairs for accounts and add them to GitHub accounts.
@iMagesh
iMagesh / move_to_rds.rb
Created February 5, 2019 05:45 — forked from guenter/move_to_rds.rb
A quick and dirty script to move a database into Amazon RDS (or any other database). Can transfer part of the data beforehand.
require 'fileutils'
start_time = Time.now
SOURCE_DB = {
:name => 'db_name',
:user => 'db_user',
:password => 'db_pass',
:host => 'localhost'
For new user
adduser user_name
add sudo permission to the user
adduser user_name sudo
For generate key(local)
ssh-keygen -b 4096
copy key to server (ubuntu)
kill $(ps aux | grep '[d]elayed_job' | awk '{print $2}')
Credit:
http://stackoverflow.com/questions/3510673/find-and-kill-a-process-in-one-line-using-bash-and-regex
@iMagesh
iMagesh / precompile.md
Created February 15, 2016 11:26 — forked from mrbongiolo/precompile.md
HOW TO: Rails 4.2 add 'vendor/asset' to precompile list

To enable the precompilation of all non.js/.css assets within vendor/assets just add this to config/initializers/assets.rb:

Rails.application.config.assets.precompile << Proc.new { |path, fn| fn =~ /vendor\/assets/ && !%w(.js .css).include?(File.extname(path)) }

Be aware that this will precompile ALL non .js/.css assets that you have there, some plugins or libraries might have .txt or other files around, and those would end up into your precompiled list also.

If you need to precompile images only, you could use this:

Rails.application.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
#user nobody;
worker_processes 10;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@iMagesh
iMagesh / whining-web-server.html
Created December 19, 2013 18:51
Funny 404 Page - Web server whines on hitting a 404
<html>
<body>
<form>
<textarea class="span12" rows="20" cols="100"></textarea>
</form>
<script language="Javascript"><!--
var tl=new Array(
"The requested document is no more.",
'No file found.',
@iMagesh
iMagesh / emacs.el
Created November 19, 2013 10:59
Laptop emacs setting
(setq inhibit-startup-message t) ;; Removes startup message
(setq-default indent-tabs-mode nil)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(auto-save-default t)