grep term highlighting even if piped through a pager (like less)

February 9th, 2012 No comments

handy search tip

when searching for a bunch of terms in a bunch of files, turn on highlighting (even if piped through 'less') (also, don't include .svn dir matches)

egrep -r --color=always  "domain|client_url|client_pid" * -v -e '.svn' | less -R

Categories: linux Tags: , ,

Perl vs Ruby time equivalents

April 18th, 2011 No comments

# perl
print time(); # number of seconds since epoch

# ruby - same thing
print Time.now.to_i

# perl
my(sec1, min, hour, mday, mon, year, wday) = gmtime();
wday = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')[wday];

#ruby
Date::DAYNAMES[Time.new.wday]

Categories: perl, ruby Tags:

mysql date format vs ruby date format specifiers

April 18th, 2011 No comments

In case you are converting some mysql sql statements into ruby equivalents, here is a comparison for the date format specifiers.

If one is not listed, it is the same thing for mysql and ruby.
In the cases of the difference, the ruby equivalent is listed with the prefix 'equiv: '

mysql                                       | ruby (1.8.7)
Specifier  Description                 | Specifier  Description 
                                            | %A - The full weekday name (``Sunday'')
                                            | %B - The full month name (``January'')
%c  Month, numeric (0..12)              | %c - The preferred local date 
                                            |      and time representation     
                                            |
                                            | equiv: %m - Month of the year (01..12)
                                            |
                                            |
%D  Day of the month with English       | equiv: NONE    
        suffix  (0th, 1st, 2nd, 3rd, ...)   |     
%e  Day of the month, numeric (0..31)   | equiv: %d - Day of the month (01..31) 
%f  Microseconds (000000..999999)       | equiv: NONE
%h  Hour (01..12)                       | equiv: %I - Hour of the day, 12-hour 
                                            |     clock (01..12) 
%i  Minutes, numeric (00..59)           | equiv: %M - Minute of the hour (00..59)
%k  Hour (0..23)                        | equiv: %H - Hour of the day, 24-hour clock (00..23)          
%l  Hour (1..12)                        | equiv: %I - Hour of the day, 12-hour clock (01..12) 
%M  Month name (January..December)      | %M - Minute of the hour (00..59)          
%T  Time, 24-hour (hh:mm:ss)            | equiv: NONE               
%u  Week (00..53), where Monday is      | equiv: %U               
        the first day of the week           | 
%V  Week (01..53), where Sunday is the  | equiv: %U                                                
        first day of the week; used with %X |                     
%v  Week (01..53), where Monday is the  | equiv: %W                                                                     
        first day of the week; used with %x |                     
%W  Weekday name (Sunday..Saturday)     | %W - Week number of the current year,
                                            |      starting with the first Monday
                                            |      as the first day of the first
                                            |      week (00..53)
                                            |
                                            | equiv: %A                                                                      
                                            |
                                            |
%X  Year for the week where Sunday is   | %X - Preferred representation for 
        the first day of the week, numeric, |      the time alone, no date 
        four digits; used with %V           | equiv: NONE                     
%x  Year for the week, where Monday is  | %x - Preferred representation for 
        the first day of the week, numeric, |      the date alone, no time                
        four digits; used with %v           | equiv: NONE                           
%x  x, for any “x” not listed above     | %Z - Time zone name   equiv: NONE      

NOTE, Ruby 1.9 has updated formats, see this cheatsheet: http://cheat.errtheblog.com/s/strftime/

for example, convert this SQL to Ruby:

SELECT date_format(date_add(now(), interval 15 hour), '%y%m%d%h%i04568-0400')

returns: 110419045404568-0400

(ActiveSupport helps)
irb(main):003:0> require 'active_support'
=> true
irb(main):004:0> Time.now.advance(:hours => 15).strftime('%y%m%d%I%M04568-0400')
=> "110419045404568-0400"

Categories: ruby Tags: , , ,

debian netatalk-2.0.3 mac osx 10.6.6 afp invalid username or password

February 9th, 2011 No comments

what I searched for: linux afp server mac osx 10.6.6 client invalid username or password

problem space:
back up a mac osx client via TIme Machine to a local NAS.

I set up a 'appletalk' (afp) share from a Linux server, all went well but for some reason, I could not log in, I would receive a 'invalid username or password' pop up prompt.

I used this to set up afp and this to resolve the issue.

basically, it seems something is amiss with the debian package of netatalk(?) building from source resolves the issue.

.vimrc some options and possibilities

January 29th, 2011 No comments

" basic .vimrc

" use with Project
set nocompatible

set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
"set sw=4
"set paste - breaks abbreviations ?
" commented text is too dark
"set background=dark

set autoindent

set expandtab
set tabstop=8
set shiftwidth=4
set softtabstop=4
set nowrap
set nohls
"syntax on
syntax enable "turn on syntax highlighting
set ruler
set number

" instead when hitting the 'TAB' key. And here's more options to fine-
" tune vim's autocompletion behaviour:
"
" "list" When more than one match, list all matches.
" "list:full" When more than one match, list all matches and
" complete first match.
" "list:longest" When more than one match, list all matches and
" complete till longest common stri
set wildmode=list

" unicode stuff http://vim.wikia.com/wiki/Working_with_Unicode
if has("multi_byte")
if &termencoding == ""
let &termencoding = &encoding
endif
set encoding=utf-8
setglobal fileencoding=utf-8 bomb
set fileencodings=ucs-bom,utf-8,latin1
endif

" vim hangs running vmware: http://taint.org/2008/03/12/122601a.html
set swapsync=
set nofsync

"To have vim mark a wrapped line with a few special characters at the beginning of
the wrapped part
set showbreak=+++

"http://wwwcdf.pd.infn.it/vim/spell.html#]s
"Finding suggestions for bad words: z=
setlocal spell spelllang=en_us

" tabs in vim7 by default wow!
" navigate tabs
" :b#/:bn/:bp

set t_Co=256 "enable 256 colors
colorscheme desert
"ls -l /home/y/share/vim/vim71/colors/
" http://ruturajv.wordpress.com/2006/12/21/vim-7-autocomplete/
" Once done, Open any PHP file and within the " press Ctrl-x Ctrl-o , and here is what happens
autocmd FileType php set omnifunc=phpcomplete#CompletePHP

autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

" not one for perl :(
"autocmd FileType perl set omnifunc=perlcomplete#CompletePERL
"javascriptcomplete.vim
"ccomplete.vim
"phpcomplete.vim
"xmlcomplete.vim
"csscomplete.vim
"htmlcomplete.vim
"sqlcomplete.vim
"rubycomplete.vim
"syntaxcomplete.vim
"pythoncomplete.vim
"adacomplete.vim
"javascriptcomplete.vim
"ccomplete.vim
"phpcomplete.vim
"xmlcomplete.vim
"csscomplete.vim
"htmlcomplete.vim
"sqlcomplete.vim
"rubycomplete.vim
"syntaxcomplete.vim
"pythoncomplete.vim
"adacomplete.vim

"To do this, jump inside the if-statement type zfi{
"http://www.vim.org/tips/tip.php?tip_id=419
"Tip #419: Auto-fold perl subs (and possibly other languages)
" :help perl.vim
"If you want to use folding with perl, set perl_fold: >
"Once you open a perl file, you'll see all functions are folded.
" You can then move to a function and (space) or "zo" to open it, "zc" to close it,
" "zR" to open all folds (normal file) and "zM" to re-fold all folds. It makes skimming over a file a breeze.
"See ":help folding" for more info on folding in general. "can also set in vim vim: set fdl=0 fdm=marker:
let perl_fold=1

"If you want to fold blocks in if statements, etc. as well set the following: >
let perl_fold_blocks = 1

"To avoid folding packages or subs when perl_fold is let, let the appropriate variable(s): >
":unlet perl_nofold_packages
":unlet perl_nofold_subs

":help php.vim
"If you like SQL syntax highlighting inside Strings: >
let php_sql_query = 1

"For highlighting the Baselib methods: >
let php_baselib = 1

"Enable HTML syntax highlighting inside strings: >
"let php_htmlInStrings = 1

"Enable folding for classes and functions: >
let php_folding = 1

" Preserve indentation with '# - perl
"filetype indent on
"autocmd FileType perl
"set cindent

" TAB as a visible character
highlight Tabs ctermbg=1
match Tabs "\t"

set list
set listchars=tab:>-

"set encoding=utf-8

"take care of the correct indentation automatically, no more ':set paste'
" reindent pasted text
nnoremap p p'[v']=

" use with tagslist
filetype on
"let Tlist_Auto_Open=1
let Tlist_Use_Right_Window=1
let Tlist_Enable_Fold_Column=0
let Tlist_Inc_Winwidth=0
let Tlist_Compact_Format=1

"http://www.vim.org/tips/tip.php?tip_id=696
" dont let mouse switch into selection mode
set mouse-=a

"make .t files perl syntax
"autocmd BufNewFile,BufRead *.t setf perl
au BufReadPost *.t set syntax=perl
au BufReadPost *.cgi set syntax=perl

" see page 482 'Editor configurations' from Perl Best Prac.
" I assume you own a copy of PBP, (if not buy it!) in which case you can use this illegal
" copy http://perl.find-info.ru/perl/028/perlbp-app-c-sect-1.html

"set autoindent "Preserve current indent on new lines
set textwidth=78 "Wrap at this column
set backspace=indent,eol,start "Make backspaces delete sensibly
"set tabstop=4 "Indentation levels every four columns
"set expandtab "Convert all tabs typed to spaces
"set shiftwidth=4 "Indent/outdent by four columns
""set shiftround "Indent/outdent to nearest tabstop
set matchpairs+=<:> "Allow % to bounce between angles too
set matchpairs+==:; "jump between a '=' of an assignment and the corresponding end of the statement, indicated by ';'

" Note: \012 newlines, [CTRL-V][ENTER] in insert mode

" NOTE!!! the following dont' work when set nocompatible is on ?

"Inserting these abbreviations inserts the corresponding Perl statement...
iab ppsb #! /usr/local/bin/perl -w
iab ppbp ^Muse strict;^Muse warnings;^M^Muse criticism 'brutal'; #uncomment on dev only ; enforces PBP coding^M^Muse vars qw{$VERSION};^M^M$VERSION = '0.0.1';^M^M
iab pudd use Data::Dumper 'Dumper';^Mwarn Dumper [];^[hi
iab pubm use Benchmark qw( cmpthese );^Mcmpthese -10, {};^[O
iab pusc use Smart::Comments;^M^M###
iab putm use Test::More qw( no_plan );

" ^[ is produced by hitting Ctrl-V then Esc
" ^M is produced by hitting Ctrl-V then Enter
iab papp ^[:r ~/perl/templates/script.pl^M
iab pmod ^[:r ~/perl/templates/module.pm^M

"" custom color schemas - in terminal
"" color terminal definitions
"set t_Co=256 "enable 256 colors
set t_Co=280 "enable 280 colors
"set t_Co=262-273
hi SpecialKey ctermfg=darkgreen
hi NonText cterm=bold ctermfg=darkblue
hi Directory ctermfg=darkcyan
hi ErrorMsg cterm=bold ctermfg=7 ctermbg=1
hi IncSearch cterm=NONE ctermfg=yellow ctermbg=green
hi Search cterm=NONE ctermfg=grey ctermbg=blue
hi MoreMsg ctermfg=darkgreen
hi ModeMsg cterm=NONE ctermfg=brown
hi LineNr ctermfg=3
hi Question ctermfg=green
hi StatusLine cterm=bold,reverse
hi StatusLineNC cterm=reverse
hi VertSplit cterm=reverse
hi Title ctermfg=5
hi Visual cterm=reverse
hi VisualNOS cterm=bold,underline
hi WarningMsg ctermfg=1
hi WildMenu ctermfg=0 ctermbg=3
hi Folded ctermfg=darkgrey ctermbg=NONE
hi FoldColumn ctermfg=darkgrey ctermbg=NONE
hi DiffAdd ctermbg=4
hi DiffChange ctermbg=5
hi DiffDelete cterm=bold ctermfg=4 ctermbg=6
hi DiffText cterm=bold ctermbg=1
hi Comment ctermfg=darkcyan
hi Constant ctermfg=brown
hi Special ctermfg=5
"hi Identifier ctermfg=2
"hi Identifier ctermfg=6
"hi Identifier ctermfg=darkgrey
"hi Identifier ctermfg=lightred
"hi Identifier ctermfg=lightblue ctermbg=white cterm=reverse,underline
"hi Identifier ctermfg=yellow
hi Identifier ctermfg=7
hi Statement ctermfg=3
hi PreProc ctermfg=5
hi Type ctermfg=2
hi Underlined cterm=underline ctermfg=5
hi Ignore ctermfg=darkgrey
hi Error cterm=bold ctermfg=7 ctermbg=1

Categories: vim Tags:

.zshrc some opts

January 29th, 2011 No comments

# .zshrc

# vim bindings on command line (also set -o vi [bash])
bindkey -v
# enable backspace
# http://docs.cs.byu.edu/index.php/ZSH
bindkey -M viins ^? backward-delete-char
bindkey -M viins ^H backward-delete-char

export TERM=xterm
export CLICOLOR "true"
#export LSCOLORS "exfxcxdxbxegedabagacad"
export LSCOLORS "fxfxcxdxbxegedabagacad"
export EDITOR=`which vim`
export HISTSIZE=1000
export APPEND_HISTORY=1
export HISTFILE=${HOME}/.zhistory
export SAVEHIST=1000
export PROMPT='[%n@%m %1/]$ '

export NOBEEP=1
export ZBEEP='\e[?5h\e[?5l' # reverse video

umask 022

Categories: zsh Tags: ,

Ruby, Time object from string

December 13th, 2010 No comments

convert string to Time object.

irb(main):022:0* require 'time'
=> true
irb(main):023:0> Time.parse('2008-08-11 19:10:25')
=> Mon Aug 11 19:10:25 -0700 2008
irb(main):024:0> Time.parse('2008-08-11 19:10:25').strftime("%Y-%m-%d %H:%M:%S")
=> "2008-08-11 19:10:25"

Categories: ruby Tags: , ,

pip install -U Django==1.1.1 OSError: [Errno 18] Invalid cross-device link

October 30th, 2010 2 comments

problem space:

Using Pinax stable release 0.7.X (at 0.7.3)
Want to upgrade to newest Django, (1.2.3)

Does Pinax work on Django 1.2?
Our stable release 0.7.X (at 0.7.1) does not support Django 1.2

Ok, other options?

Yes. Pinax 0.7 ships with Django 1.0.4 by default.
To use Django 1.1 in your Pinax project simply follow our installation documentation and once you are in the virtual environment run:

pip install -U Django==1.1.1
This will install Django 1.1.1 over 1.0.4.

Ok, great.

(pinax-env)[dwright@system76-netbook site]$ pip install -U Django==1.1.1
Downloading/unpacking Django==1.1.1
  Downloading Django-1.1.1.tar.gz (5.6Mb): 5.6Mb downloaded
  Running setup.py egg_info for package Django
Installing collected packages: Django
  Found existing installation: Django 1.0.4
    Uninstalling Django:
Exception:
Traceback (most recent call last):
  File "/home/dwright/projects/virtualenv/pinax-env/lib/python2.6/site-packages/pip-0.6.1-py2.6.egg/pip.py", line 482, in main
    self.run(options, args)
  File "/home/dwright/projects/virtualenv/pinax-env/lib/python2.6/site-packages/pip-0.6.1-py2.6.egg/pip.py", line 677, in run
    requirement_set.install(install_options)
  File "/home/dwright/projects/virtualenv/pinax-env/lib/python2.6/site-packages/pip-0.6.1-py2.6.egg/pip.py", line 2745, in install
    requirement.uninstall(auto_confirm=True)
  File "/home/dwright/projects/virtualenv/pinax-env/lib/python2.6/site-packages/pip-0.6.1-py2.6.egg/pip.py", line 2066, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/home/dwright/projects/virtualenv/pinax-env/lib/python2.6/site-packages/pip-0.6.1-py2.6.egg/pip.py", line 4718, in remove
    os.renames(full_path, new_path)
  File "/home/dwright/projects/virtualenv/pinax-env/lib/python2.6/os.py", line 199, in renames
    rename(old, new)
OSError: [Errno 18] Invalid cross-device link

Storing complete log in ./pip-log.txt

fark it all!

(pinax-env)[dwright@system76-netbook site]$ TMPDIR=/home/dwright/projects/virtualenv/pinax-env pip install  Django --upgrade     
Downloading/unpacking Django
  Running setup.py egg_info for package Django
Installing collected packages: Django
  Found existing installation: Django 1.0.4
    Uninstalling Django:
      Successfully uninstalled Django
  Running setup.py install for Django
    changing mode of build/scripts-2.6/django-admin.py from 644 to 755
    changing mode of /home/dwright/projects/virtualenv/pinax-env/bin/django-admin.py to 755
Successfully installed Django

Joy, at last!

(pinax-env)[dwright@system76-netbook site]$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15) 
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 1, 1, 'final', 0)

reference:
http://pinaxproject.com/docs/0.7/faq.html
http://hdknr.posterous.com/?tag=virtualenv

Categories: django, pinax, python Tags: , ,

favorite ‘new’ Ruby idiom

October 24th, 2010 No comments

This is straight from 'The Ruby Programming Language' book. (O'Reilly. Flanagan & Matsumoto)

This is a convenient and useful exception handling shortcut that is fun to use and easy to abuse.

syntactic sugar for the Ruby 'try/catch' block.

Simple 'try/catch' in Ruby:

begin
  # try something here
rescue
 # the above didn't work, recover here
end

you can do this.
value = expression rescue 'default value'

for example, recover from division by 0 gracefully.

irb(main):002:0> v = 5 / 0
ZeroDivisionError: divided by 0
  from (irb):2:in `/'
  from (irb):2
irb(main):003:0> v = 5 / 0 rescue nil
=> nil
irb(main):004:0> v = 5 / 0 rescue 'doh'
=> "doh"
irb(main):005:0> p v
"doh"
=> nil
irb(main):006:0> v = 5 / 0 rescue 0
=> 0

get it? cool, huh.

Categories: ruby Tags: , ,

mysql create utf8 db

October 17th, 2010 No comments

geez, cause I always forget.

mysql> CREATE DATABASE 'database name' CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> grant all on 'database name'.* to 'user'@'localhost' IDENTIFIED BY 'password';

Categories: MySQL Tags: , , , ,