Last active
December 15, 2015 08:19
-
-
Save floydpink/5229763 to your computer and use it in GitHub Desktop.
Start a new WEBrick instance at command prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HISTCONTROL=ignoredups:erasedups | |
HISTIGNORE=clear | |
PROMPT_COMMAND='history -a' | |
export LC_ALL=en_US.UTF-8 | |
export LANG=en_US.UTF-8 | |
[[ -s $USERPROFILE/.pik/.pikrc ]] && source $USERPROFILE/.pik/.pikrc | |
SSH_ENV="$HOME/.ssh/environment" | |
# start WEBrick here without caching | |
function serve { | |
ruby ~/WEBrick.rb | |
} | |
# start WEBrick here | |
function serve2 { | |
port="${1:-3000}" | |
ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => $port, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start" | |
} | |
# start the ssh-agent | |
function start_agent { | |
echo "Initializing new SSH agent..." | |
# spawn ssh-agent | |
ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV" | |
echo succeeded | |
chmod 600 "$SSH_ENV" | |
. "$SSH_ENV" > /dev/null | |
ssh-add | |
} | |
# test for identities | |
function test_identities { | |
# test whether standard identities have been added to the agent already | |
ssh-add -l | grep "The agent has no identities" > /dev/null | |
if [ $? -eq 0 ]; then | |
ssh-add | |
# $SSH_AUTH_SOCK broken so we start a new proper agent | |
if [ $? -eq 2 ];then | |
start_agent | |
fi | |
fi | |
} | |
# check for running ssh-agent with proper $SSH_AGENT_PID | |
if [ -n "$SSH_AGENT_PID" ]; then | |
ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null | |
if [ $? -eq 0 ]; then | |
test_identities | |
fi | |
# if $SSH_AGENT_PID is not properly set, we might be able to load one from | |
# $SSH_ENV | |
else | |
if [ -f "$SSH_ENV" ]; then | |
. "$SSH_ENV" > /dev/null | |
fi | |
ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null | |
if [ $? -eq 0 ]; then | |
test_identities | |
else | |
start_agent | |
fi | |
fi | |
eval "$(grunt --completion=bash)" | |
. ~/z.sh | |
LS_COLORS='di=1;34:fi=0;32:ln=31:pi=5:so=5:bd=5:cd=5:or=35:mi=0:ex=31:*.rpm=90' | |
export LS_COLORS | |
alias ls='ls --color --show-control-chars' | |
export PS1='\[\033[01;32m\]\u@\h\[\033[01;33m\] \w\[\033[01;31m\]$(__git_ps1)\[\033[01;35m\] \$\[\033[00m\] ' | |
export GIT_PS1_SHOWDIRTYSTATE=1 | |
alias log="git log --decorate --graph --pretty=format:'%C(bold red)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold yellow)<%an>%Creset' --abbrev-commit" | |
alias octopress="bundle exec rake" | |
alias timesheetlog="prettylog --all --since '8 days ago' --author 'Haridas'" | |
alias deploytravisweb="git checkout -b deploy-web; grunt web; rm -r -f node_modules/; git rm -rf --quiet js/app/ js/lib/ package.json localServer.js .travis.yml Gruntfile.js README.md .jshintrc; git commit -am 'commit for the web' -s; git push origin deploy-web:gh-pages --force; git checkout master ; git branch -D deploy-web;" | |
alias tree="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'" | |
alias mongod="/E/Hari/Personal/tools/mongo/bin/mongod --dbpath /E/Hari/Personal/tools/mongo/data --rest" | |
alias mongo="/E/Hari/Personal/tools/mongo/bin/mongo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'webrick' | |
class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler | |
def prevent_caching(res) | |
res['ETag'] = nil | |
res['Last-Modified'] = Time.now + 100**4 | |
res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0' | |
res['Pragma'] = 'no-cache' | |
res['Expires'] = Time.now - 100**4 | |
end | |
def do_GET(req, res) | |
super | |
prevent_caching(res) | |
end | |
end | |
mime_types = WEBrick::HTTPUtils::DefaultMimeTypes | |
mime_types.store 'js', 'application/javascript' | |
server = WEBrick::HTTPServer.new(:Port => 3000, :MimeTypes => mime_types) | |
server.mount '/', NonCachingFileHandler , Dir.pwd | |
trap('INT') { server.stop } | |
server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment