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)
@iMagesh
iMagesh / nginx.conf
Created July 17, 2015 12:07
nginx ssl config rails
upstream myapp{
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a single worker for timing out).
server 127.0.0.1:3000;
}
server {
#listen 80 ssl;
listen 443 ssl;
var pageUrl = "http://something.com/gsm";
var interactionId = "email-form"; //id of the product
document.getElementsByClassName(interactionId).onsubmit = function AfterFunction(e){
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
Lib.ajax.getJSON({
url: 'https://api.twitter.com/1/statuses/user_timeline.json?&screen_name=gabromanato&callback=?&count=1',
type: 'jsonp'
}, function(tweet) {
document.querySelector('#tweet').innerHTML = tweet[0].text;
});