Skip to content

Instantly share code, notes, and snippets.

@Hiteshm01
Hiteshm01 / .bashrc
Last active January 7, 2019 08:33
Autocomplete remote machine names
complete -o default -o nospace -W "$(/usr/bin/env ruby -ne 'puts $_.split(/[,\s]+/)[1..-1].reject{|host| host.match(/\*|\?/)} if $_.match(/^\s*Host\s+/);' < $HOME/.ssh/config)" scp sftp ssh
_complete_hosts () {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
host_list=`{
for c in /etc/ssh_config /etc/ssh/ssh_config ~/.ssh/config
do [ -r $c ] && sed -n -e 's/^Host[[:space:]]//p' -e 's/^[[:space:]]*HostName[[:space:]]//p' $c
done
for k in /etc/ssh_known_hosts /etc/ssh/ssh_known_hosts ~/.ssh/known_hosts
do [ -r $k ] && egrep -v '^[#\[]' $k|cut -f 1 -d ' '|sed -e 's/[,:].*//g'
@Hiteshm01
Hiteshm01 / .bashrc
Created February 8, 2015 17:12
git branch name in bashrc
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
bold=$(tput bold)
reset=$(tput sgr0)
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != 'nothing to commit (working directory clean)' ]] && echo $red || echo $green
}
@Hiteshm01
Hiteshm01 / sid
Created February 8, 2015 17:17
Union Intersection and difference
cat a b | sort | uniq > c # c is a union b
cat a b | sort | uniq -d > c # c is a intersect b
cat a b b | sort | uniq -u > c # c is set difference a - b
@Hiteshm01
Hiteshm01 / gist:f326c8a6407348fd8088
Created February 8, 2015 17:32
Useful terminal commands
sudo !! # Runs last command with sudo privilege
python -m SimpleHTTPServer # Starts a HTTP server aat 8000 port in current folder, Great tool to share files!
@Hiteshm01
Hiteshm01 / gdb
Last active August 29, 2015 14:15
To update environment variable of a running process
$> sudo apt-get install gdb
$> sudo su
$> gdb
(gdb) attach process_id # insert process id instead of process_id
(gdb) call putenv ("env_var_name=env_var_value") # Add environmental variable
(gdb) detach # detach with option y
@Hiteshm01
Hiteshm01 / git
Created February 8, 2015 17:43
To create patch files of git branches
git diff origin/master > /tmp/patch.diff # replace origin/master with branch to compare with
# Move this patch file to new server via scp.
patch -p1 < /tmp/patch.diff # Assuming same location on remote machine.
# Or alternatively
# git apply -v /tmp/patch.diff
@Hiteshm01
Hiteshm01 / .bashrc
Created February 8, 2015 17:46
Bashrc file
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
'use strict';
var Harness = require('./support');
var post = Harness.definePostTable().as('postsss');
var customerAlias = Harness.defineCustomerAliasTable();
var user = Harness.defineUserTable();
// Harness.test({
// query: post.as('a').select(post.id.max()),
"use strict";
var AWS = require('aws-sdk');
var https = require('https');
var http = require('http');
var keys = {
accessKeyId: 'development',
secretAccessKey: 'development',
var Twitter = require('twitter');
var Sentiment = require('sentiment');
var debug = require('debug')('stream');
var request = require('request');
var config = {
consumer_key: '<Please your tokens here>',
consumer_secret: '<Please your tokens here>',
access_token_key: '<Please your tokens here>',
access_token_secret: '<Please your tokens here>',
};