Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-8 of 8 total  RSS 

nginx gzip config

  # output compression saves bandwidth 
  gzip              on;
  gzip_proxied      any;
  gzip_http_version 1.1;
  #gzip_min_length   1100;
  gzip_comp_level   5;
  #gzip_buffers      4 8k;
  gzip_types        text/plain text/html text/xml text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/atom+xml;
  #gzip_vary        on;
  #gzip_disable     "MSIE [1-6]\.";

Very basic lighttpd configuration

The configuration of lighttpd is vast and complex. Here is a close to minimal configuration which allows for Perl and Ruby CGI.

server.document-root = "/opt/lighttpd/htdocs"

server.port = 3000

mimetype.assign = (
  ".html" => "text/html",
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png"
)

static-file.exclude-extensions = ( ".rb", ".pl", ".fcgi", ".php", ".rb", "~", ".inc" )
index-file.names = ( "index.html" )
server.modules += ( "mod_cgi" )

cgi.assign = (  ".rb" => "/opt/ruby/bin/ruby",
                ".pl" => "/usr/bin/perl")

bash aliases

For old duffers like me who were used to earlier shells when bash came along.

# These save typing, I use them a lot

alias sd='cd -' > /dev/null
alias cx='chmod +x'
alias which="type -path"

# This goes back to Unix v7, some time around 1985 I think.

alias lf='ls -CF'

# From my 'C' shell days. Those were almost 20 years ago as well. Sigh.

alias h='fc -l -20'
alias r='fc -s'

# Because real men use 'vi' and why use character mode if you have X?

alias vi='gvim'

.inputrc to make bash command-line editing like ksh

I was used to ksh and vi when bash came along, so I wanted the behaviour to remain the same. Some may think this odd.

set editing-mode vi
set keymap vi

vim configuration - graphics mode

This is my .gvim rc, the configuration file for gvim, vim's graphics mode. vim is "vi improved", a vi clone and so much more.

set guifont=Monospace\ 11

" Overrides settings in vim's configuration. I prefer minimal colour.

hi Normal			guifg=Black		guibg=White
hi NonText			guifg=Black		guibg=White
hi Comment	gui=none	guifg=DarkGray
hi Constant	gui=none	guifg=Magenta
hi Identifier	gui=none	guifg=DarkGreen
hi Statement	gui=none	guifg=Blue
hi PreProc	gui=none	guifg=Blue
hi Type		gui=none	guifg=Blue
hi Special	gui=none	guifg=DarkGreen
hi Ignore	gui=none	guifg=DarkGreen
hi Error	gui=none	guifg=DarkGreen
hi Todo		gui=none	guifg=DarkGreen
hi Cursor	gui=none	guifg=White		guibg=Black

autocmd GUIEnter * winpos 66 28
autocmd GUIEnter * winsize 80 45

" What is this menu for? No documentation, something to do with 'C'
" or C++ perhaps? Dunno, but I don't want it.

aunmenu Bicycle\ Repair\ Man

" If I have Python, create a dummy project menu and exececute the
" vimproject script.

if has ("python")
    if filereadable ("/home/mrw/bin/vimproject.py")
	amenu Project.Dummy dummy
	pyfile /home/mrw/bin/vimproject.py
    endif
endif

vim configuration

This is my .vimrc file -- configuration options for vim, the "vi improved" text editor for grown ups.

:autocmd!

set nohlsearch

" Press F2 to word-wrap a block of text. It's almost like using Word
" Star all over again.

map #2 !}fmt -65

" Personally, I wouldn't use a C++ keyword as a Java identifier, but
" if someone else does, I don't want an ugly display, so turn off
" flagging of this as an error:

let java_allow_cpp_keywords=1

set autoindent
set cmdheight=2

" Strewth, what a mess. Copied from the vim docs, if memory serves.

set comments=s:/*,mb:**,ex:*/,://,b:#,b:##,:%,:XCOMM,n:>,fb:-

set formatoptions=orc
set history=20
set incsearch
set ignorecase
set keywordprg=
set mouse=a
set mousehide
set mousemodel=popup_setpos
set nowrapscan
set path=.,/usr/include,/usr/local/include
set smartcase
set nosmartindent
set smarttab
set showmode
set textwidth=70
set viminfo='50,\"10000,n~/.viminfo
set wildchar=9
set wildignore+=*.class,*.pyc
set wildmenu

syntax on

:autocmd FileType *		set shiftwidth=4
:autocmd FileType xml,html	set shiftwidth=2
:autocmd FileType java,c,cc,cpp	set nocindent

set makeprg=ant

" Bleurgh! This makes sense of ant/jikes error messages so the ":make"
" command works. But, I ask you, how the f**k can anyone make sense of
" that mess?

set efm=\ %#[javac]\ %#%f:%l:%c:%*\\d:%*\\d:\ %t%[%^:]%#:%m,\%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#

" For the style of comments I like in 'C', C++ and Java.

autocmd BufNewFile,BufRead *.java set comments=s:/*,mb:**,ex:*/
autocmd BufNewFile,BufRead *.c set comments=s:/*,mb:**,ex:*/
autocmd BufNewFile,BufRead *.cc set comments=s:/*,mb:**,ex:*/

www.example.com => example.com in apache configuration

// www.example.com => example.com

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

App level configuration for your Rails apps

Hard coding stuff into your view templates isn't a great idea, and sometimes you want it out of your layouts too. If you have variables your app requires, but which may change between deployments, put them in /config/appconfig.yml in YAML format, then put this at the top of your /config/environment.rb:

require 'yaml'


And at the bottom of your /config/environment.rb:

APP_CONFIG = YAML::load(File.open("#{RAILS_ROOT}/config/appconfig.yml"))


Now your YAML variables are accessible anywhere from your controllers or views like so:

APP_CONFIG["variable"]


Easy peasy.
« Newer Snippets
Older Snippets »
Showing 1-8 of 8 total  RSS