Wednesday, February 5, 2014

Too Many Specs Failing?

Could be that you simply need to clone the structure of your development database into your test database.

Clone Your Test Database


bundle exec rake db:test:clone

Notes

  • The only specs that pass when the test database is not configured properly should be tests that don't reference the test database
  • db:test:clone is just a combination of db:schema:dump and db:test:load
  • db:test:load is the same as db:schema:load, but it runs against the test (not development) database

Run Specific Rspec Tests Under Specific Directory

You can run specific rspec tests under a specific directory by
  • specifying the directory
  • using an rspec tag option


For example, if you want to run model specs that you've tagged as work in progress (wip) do the following:

Add tag to spec


require 'spec_helper'

describe HomeController do
  render_views
  it "Logs in Person with non-blank name", :lex_tag => 'wip' do
    person = Factory(:Person, name: "non-blank name")
    get :login
    response.should redirect_to(people_path)
  end
  it "does not log in Person with blank name" do
    person = Factory(:Person, name: "") # blank name
    get :login
    response.should redirect_to(root_path)
  end
end

Run spec like so


$ be rspec --pattern spec/models/*_spec.rb --tag lex_tag:wip

In this example, we are running model specs that do not have a tag named ":lex_tag" with a value of "wip"

Summary

By specifying the directory, you limit the number of specs to run to a logical grouping.

By using rspec tags, you can be very specific about which individual tests you run.


Notes

  • You can negate a tag using the "~" character
  • To be compatible with the Cucumber syntax, tags can optionally start with a @, that will be ignored. Example: @lex_tag
  • There is nothing special about "lex_tag", you can name your tag nearly anything, but using a name allows multiple developers to annotate without confusion.
  • You would not want to check specs into your source code repository that had tag names that referenced individuals
  • You might want to use tags to group specs according to other user acceptance testing criteria or perhaps tag tests for particular server deployment environments
  • So, tags can be used to group specs, not by static folder directories but by any criteria you wish

References

https://www.relishapp.com/rspec/rspec-core/v/2-3/docs/command-line/tag-option#exclude-examples-with-a-name:value-tag

Sunday, January 12, 2014

Caskable Apps

I'd recommend using Homebrew to install apps such as curl and git on OSX and using brew-cask to install GUI apps such as node and parallels.

Current List of Caskable Apps


a-slower-speed-of-light
acorn
actiontastic
activity-audit
adapter
adium
adobe-air
adventure
aegisub
aerofs
air-video-server
airdisplay
airfoil
airmail-beta
airparrot
airserver
akai-lpk25-editor
alfred
aliwangwang
all2mp3
amadeus-pro
amazon-cloud-drive
amazon-cloud-player
amethyst
android-file-transfer
android-studio
anki
anonym
antirsi
anvil
anxiety
ap-grapher
apikitchen
apns-pusher
appcleaner
appcode
appdelete
appfresh
appmenuboy
apptivate
appzapper
aptana-studio
aquamacs
aquaterm
arduino
armitage
armory
arq
asepsis
asteroid
atext
atmonitor
audacity
audio-editor
audio-hijack-pro
audiobook-binder
audioslicer
authy-bluetooth
avidemux
awareness
back-in-time
backblaze-downloader
backuploupe
balsamiq-mockups
baretorrent
bartender
base
basecamp
basictex
bathyscaphe
battery-guardian
battery-report
battery-time-remaining
baygenie
bbedit
beamer
bettertouchtool
betterzip
betterzipql
bibdesk
bill
binreader
bitcoin-qt
bitmessage
bittorrent-sync
blender
blueharvest
bodega
bonjour-browser
bootchamp
bootxchanger
bowtie
boxcryptor-classic
boxer
brain-workshop
breakaway
brightness
broomstick
burn
caffeine
calcservice
calibre
calibre2opds
camino
camranger
camtasia
candybar
carbon-copy-cloner
carlson-minot
catch
ccleaner
ccmenu
cdto
cfxr
chainsaw
chameleon-ssd-optimizer
changes
charles
chatology
cheatsheet
chicken
chocolat
choosy
chromatic
chromecast
chromium
chronicle
chronoagent
chronomate
chronosync
cinch
clamxav
clarify
cleanmymac
clementine
clipmenu
clix
cloak
clonk-rage
cloud-pull
cloudapp
cloudup
cocktail
cocoa-packet-analyzer
cocoa-rest-client
cocoaspell
coconutbattery
coda
codebug
codekit
cog
colloquy
color-oracle
colorpicker-antetype
colorpicker-developer
colorpicker-hex
colorpicker-propicker
colors
colorschemer-studio
comic-book-lover-sync
comic-book-lover
commandq
concentrate
contexts
controllermate
controlplane
coolterm
copy
cord
cornerstone
coteditor
couchbase-server-community
couchbase-server-enterprise
crashlytics
crashplan
crushftp
cuppa
cups-pdf
cura
curse-client
cutesdr
cyberduck
daisydisk
darktable
dash
dashlane
dataurlmaker
day-o
dbeaver
deal-alert
debt-quencher
deeper
default-folder-x
delibar
delicious-library
delivery-status
deltawalker
deluge
desmume
dia
dict-unifier
diffmerge
disk-drill
disk-inventory-x
diskaid
diskmaker-x
diskwave
divvy
djview
dnscrypt
dogecoin
dolphin
dosbox
douban-radio
doubletwist
doxie
doxygen
dradio
dragthing
drobo-dashboard
dropbox-encore
dropbox
dropin
droplr
dropzone
dsp-radio
dukto
duplicate-annihilator
eagle
easy-vpn
easysimbl
eclipse-ide
eclipse-platform
ecoute
ejector
electric-sheep
electrum
emacs
enjoyable
entropy
espresso
etrecheck
evernote
evom
exhaust
expandrive
eye-fi
eyetv
f-lux
fairmount
fake
fakethunder
fantastical
fastscripts
feeder
feeds
fender-amp-drivers
fender-fuse
ffmpegx
fiji
filebot
filedrop
filezilla
find-any-file
firefox
flash-decompiler
flash
flickr-uploadr
flight-gear
flip4mac
flow
flowdock
fluid
flux
fm-designer
fm-fw-installer
folx
fontexplorer-x-pro
fontprep
forklift
fotomagico
fourk-video-downloader
fourpeaks
foxmail
fpc
free-ruler
freecad
freemind
freezer
fritzing
frizzix
fs-uae
fugu
functionflip
ganttproject
garagesale
garmin-training-center
gas-mask
gawker
geekbench
geektool
gemini
genymotion
gephi
gfxcardstatus
ghostlab
gifrocket
gimp-lisanet
gimp
git-annex
gitbox
github
gitifier
gitx-l
gitx-rowanj
gitx
glimmerblocker
gmail-notifr
gnucash
goagentx
gog-downloader
google-app-engine-launcher
google-chrome
google-drive
google-earth
google-hangouts
google-music-manager
google-notifier
google-quick-search-box
google-refine
google-web-designer
gopanda
gpgtools
gpower3
gqrx
grabbox
grandperspective
grandtotal
gridwars
grooveshark
groovesquid
growl-fork
growler
growlnotify
growlvoice
gurpscharactersheet
hall
hamachi
handbrake
handbrakebatch
hands-off
haroopad
harvest
haskell-platform
hazel
heroku-toolbelt
hexels
hexfiend
hipchat
hiss
hive
hockeycoach
hopper-disassembler-gdb
hopper-disassembler
horndis
hostbuddy
houdahgeo
houdahspot
httpscoop
hyperdock
hyperswitch
hyro
ibank
icefloor
ichm
icompta
icursor
id3-editor
identify
ideskcal
iexplorer
ifilex
igetter
imagealpha
imageoptim
img2icns
inboard
inc
induction
inkscape
instacast
insync
integrity
intellij-idea-community
intellij-idea-ultimate
iograph
ioquake3
ipalette
iphone-configuration-utility
iphoney
ireadfast
irip
isolator
istat-menus
istopmotion
istumbler
iterm2
itools
itunes-volume-control
itweax
jabref
java
jd-gui
jdownloader
jewelrybox
jing
jitsi
join-me
josm
jsonlook
jubler
julia
jumpcut
jumpshare
justlooking
kaleidoscope
kdiff3
keepassx
keka
kext-drop
kext-utility
kext-wizard
key-codes
keyboard-cleaner
keyboard-maestro
keyboardcleantool
keycue
keyfinder
keyremap4macbook
kindle
kismac
kiwi
knock
knox
kobito
komodo-edit
kompozer
lastfm
lastpass-universal
latexit
launchbar
launchcontrol
layervault
lazarus
league-of-legends
less-app
libreoffice
licecap
licensed
light-table
lightpaper
limechat
linein
linkinus
litecoin
liteicon
liteide
little-snitch
livereload
livestation
locko
logisim
logitech-control-center
logitech-unifying
logmein-ignition-beta
love
lyn
lyx
macdrops
macfusion
macintosh-explorer
macpardeluxe
macpass
macpilot
macports
macs-fan-control
mactex
mactracker
macupdate-desktop
macvim
magic-launch
mailfollowup
mailmate
mailplane
makemkv
makerware
mamp
manager
manico
maratis
marked2
marsedit
max
maxthon
media-converter
menubar-countdown
menubarfilter
menumeters
menuola
mesasqlite
meshlab
meteorologist
mi
middleclick
mikogo
milkytracker
minco
mindnode-pro
minecraft
miro-video-converter
miro
mirror-displays
mixlr
mixxx
mkvtoolnix
mocksmtp
money
moneymoney
moneywell
mongohub
mono-mdk
mono-mre
monolingual
monotype-skyfonts
moom
moreamp
mosh
mou
mover
movist-fork
mozart
mpeg-streamclip
mplayer-osx-extended
mplayerx
mucommander
mudlet
multibit
multibrowser
mumble
musescore
myphonedesktop
mysql-workbench
namebench
namechanger
namemangler
navicat-data-modeler
navicat-mariadb
navicat-mysql
navicat-oracle
navicat-postgresql
navicat-premium
navicat-sql-server
navicat-sqlite
neofinder
netbeans-cpp
netbeans-php
netbeans
nethack-cocoa
netlogo
netnewswire
netshade
netspot
neu
nightingale
nitrous-io
nocturne
node-webkit
node
noejectdelay
noiz2sa
nomacs
nosleep
notational-velocity
ntfs-free
nvalt
nzb-vortex
objektiv
obsidian-menu-bar-mountain-lion
omnidazzle
omnidisksweeper
omnifocus
omnigraffle
omnioutliner-pro
omnioutliner
omniplan
omniweb
onepassword
onyx
oovoo
openemu
openoffice
openscad
opera-mail
opera-mobile-emulator
opera-next
opera
optimal-layout
orange
origin
ormr
osxfuse
owncloud
p4merge
pacifist
pagico
paintbrush
pandoc
paparazzi
papers
parallels
paraview
password-practice
pastor
path-finder
pcalc
pckeyboardhack
pdfsam
pencil
pester
pg-commander
pgadmin3
phoenix-slides
phoneclean
photo-ninja
phpstorm
pi-filler
pianopub
picard
picasa
picturelife
picturesque
pins
pinta
pixel-check
pixelpeeper
pixelstick
plain-clip
platypus
pleasesleep
plex-home-theater
plex-media-server
plug
pngcommentator
poedit
pokerstars
pokertracker
port-map
porthole
postbox
power-manager-pro
power-manager
powerkey
preen
pref-setter
preference-manager
preferencecleaner
prefs-editor
prepros
prey
prizmo
processing
prolific-usb-serial-driver
propane
protege
provisioning
proximity
ps3-media-server
pupil
putio-adder
puush
pwnagetool
pycharm-community
pycharm-pro
qbittorrent
qlcolorcode
qlimagesize
qlmarkdown
qlprettypatch
qlstephen
qq-music
qq
qqbrowser
qt-creator
quassel-client
querious
quickcast
quickhue
quicklook-csv
quicklook-json
quickradar
quicksilver
quotefixformac
racket
rcdefaultapp
rcenvironment
rcwebcolorpicker
rdio
readytalk
recovery-disk-assistant
redis-desktop-manager
reflector
refresh-finder
reggy
renamer
repetier
rescuetime
rest-client
retinacapture
retinizer
retroshare
reveal
riffworkst4
right-zoom
ringtones
ripit
rname
robomongo
royal-tsx
rrootage
rss
rstudio
rtx
rubymine
runtastic-connect
sabnzbd
sandbox
satellite-eyes
sauce
scala-ide
screenflick
screenflow
screenhero
screens-connect
screensteps
scribus
scriptql
scrivener
scrup
scummvm
sdrdx
seafile
seamonkey
seashore
second-life
secondbar
selfcontrol
send-to-kindle
sequel-pro
serial-cloner
serial-tools
shadowsweeper
shelf-leveler
shiftit
shimo
shiori
shoes
shortcat
shotcut
shuttle
sidekick
sidestep
sidplay
sigil
silverlight
sim-pholders
simon
simpholders
simple-comic
simple-css
simplecap
simulator-folders
sitesucker
sizeup
sizzlingkeys
sketch
sketchup
skim
skitch
skydrive
skype
slack
slate
sleep-monitor
slice-eq
slicy
slimbatterymonitor
sloth
slowy
smaller
smartgithg
smcfancontrol
snagit
snip
snippets-me
sonic-visualiser
sonos
sophos-antivirus
soulseek
soulver
soundflower
soundnote
sourcetree
space-monkey
spark-inspector
sparkle
sparkleshare
sparrow
spectacle
speed-download
speedcrunch
speedlimit
speedtao
spek
spirited-away
splashtop-personal
splashtop-streamer
splayerx
spotdox
spotifree
spotify-menubar
spotify
spring-tool-suite
spyder
sql-explorer
sqleditor
sqlite-browser
squidman
squirrel
sqwiggle
sshfs
steam
steermouse
strongvpn
subethaedit
subler
sublime-text
subnetcalc
subsmarine
subtitle-master
subtitles
sunlogin-remote
super-otr
supercollider
superduper
surplusmeter
suspicious-package
sweet-home3d
swingfish
swinsian
synergy
synology-assistant
synthesia
tagalicious
tagr
tapaal
taskpaper
teamspeak-client
teamviewer
teamviz
teeworlds
teleport
testflight
texmacs
texmaker
texshop
textadept
textexpander
textmate
texts
textwrangler
the-hit-list
the-unarchiver
theremin
things
thumbsup
thunderbird
tickets
tikz-editor
tilemill
time-out
time-tracker-mac
timemachineeditor
timemachinescheduler
timings
tinkertool
tinygrab
tksuite-client
toad-mac
toau
todoist
toggldesktop
tomahawk
tomighty
tongbu
tor-browser
torus-trooper
totalfinder
totals
totalspaces
totalterminal
tower
trailrunner
transmission-remote-gui
transmission
transmit
trim-enabler
truecrypt
tune-instructor
tunewiki
tunnelbear
tunnelblick
tuxguitar
tv-show-tracker
tvbrowser
tvmobili
tvshows
twitterrific
uber-network-fuser
ukelele
uncrustifyx
undercover
unetbootin
uninstallpkg
unison-usenet
unison
unity3d
unpkg
unrarx
usb-overdrive
utorrent
vagrant
valentina-studio
versions
viber
vienna-rss
vimediamanager
vine-server
vinoteka
virtualbox
virtualhostx
viscosity
visit
vistrails
visualvm
vitamin-r
vlc-remote
vlc-streamer
vlc
vmware-fusion
vocabulist
voicemac
vox
wallpaper-wizard
waterroof
wavtap
webp-quicklook
webstorm
wedge
weka
welly
whatpulse
whatsapp-pocket
whiteclock
wineskin
wireshark
witch
woodhouse
wordservice
wraparound
wunderlist
x48
xamarin-studio
xbench
xbmc
xbox360-controller-driver
xiami
xld
xmarks-safari
xmind
xnviewmp
xquartz
xscope
xtrafinder
xunlei
yanvi
ynab
yorufukurou
youview
yubikey-personalization-gui
yubiswitch
zap-proxy
zepheer
zephyros
zero-ad
zero-xed
zipcleaner
zipeg
zooom
zotero
zterm


Easy way to get list of Caskable App Names

Go here https://github.com/phinze/homebrew-cask/tree/master/Casks and copy the list into your clipboard.

Use code below to extract just the app names:


x =<<TEXT
	..		
a-slower-speed-of-light.rb	Add A Slower Speed of Light	a month ago
acorn.rb	Fixes hardcoded version in Acorn cask	7 months ago
actiontastic.rb	Actiontastic beta8	2 months ago
activity-audit.rb	Adding cask for Activity Audit	8 days ago
adapter.rb	Add Adapter.app	6 months ago
. . .
zooom.rb	Minor fix to incorrect homepage URL.	6 months ago
zotero.rb	Update Zotero cask version to 4.0.17.	23 days ago
zterm.rb	ZTerm is a terminal emulation program for the Macintosh	5 months ago
TEXT


a = x.split("\n")
a.delete_at(0)  # Get rid of ".." that I accidentally copied
a.each{|i| puts i.split(' ')[0].split('.')[0]};nil

References

https://github.com/phinze/homebrew-cask/tree/master/Casks

Tuesday, December 31, 2013

Hard Link Directories in OSX

Ever had one of those days when things that worked fine just don't anymore?

Today, for some reason I have yet to discover, my soft linked directories (created with ln -s <SOURCE> <TARGET>) became unsearchable by the bash find command.

I had to resort to creating a C program, in order to use it's link function.

SOURCE


#include <unistd.h>
#include <stdio.h>
#include <string.h>
/*
Purpose:  To create a hard link to a directory
Install:  gcc hln.c -o hln
*/
int main(int argc, char* argv[]) {
    //Make sure we have the right arguments
    if (argc != 3) {
        fprintf(stderr,"Usage:   hln <SOURCE_DIRECTORY> <TARGET_DIRECTORY>\n\n");
        fprintf(stderr,"To later unlink target directory:   hln -u <TARGET_DIRECTORY>\n");
        return 1;
    }
    int ret = 0;
    if(strcmp(argv[1], "-u") == 0)
        ret = unlink(argv[2]);
    else
        ret = link(argv[1],argv[2]);
         
    if (ret != 0)
        perror("hardlink");
    return ret;
}

Compile it

After compiling, you'll want to copy the hln executable to a suitable directory, like /usr/bin.

$ gcc hln.c -o hln

All good

Now, I can create (hard) linked directories and unlink them (with the -u option).

Thursday, December 12, 2013

Displaying Escaped Characters Better with Back References

Have you ever received strings with literal characters, like the one below, that just look like a lot of noise?

Start with this


"body"=>"\"{\\\"class\\\":\\\"MigrationMgr\\\",\\\"args\\\":[null,\\\"migrate_product\\\",1,3]}\""

A little better

Open up an IRB or Ruby command console and when you use puts, it looks a little better...

[1] pry(main)> s=< "\"\"{\\\"class\\\":\\\"MigrationMgr\\\",\\\"args\\\":[null,\\\"migrate_product\\\",1,3]}\"\"\n"
[2] pry(main)> puts s
""{\"class\":\"MigrationMgr\",\"args\":[null,\"migrate_product\",1,3]}""
But it's still not as clean as you'd like.

Back References to the Rescue

First, create the back references

back_refs = {
   '\"' => '',
   "\\" => ''''
}


Next, use gsub and regex groupings to replace the back references with the desired, simpler characters.

hash_var['body'].gsub(/([\"\\])/) { back_refs[$1] }.gsub(',', ', ')

Result

Now, we have nicely formatted data that we can use for display purposes.

{class:MigrationMgr, args:[null, migrate_product, 1, 3]}

Wednesday, December 4, 2013

Upgrade from PostgreSQL 9.2.4 to 9.3.1 on OSX 10.9 and Centos 6.5

While testing a new async infrastructure, which requires more than 20 database connections, I ran out of connections and looked into upgrading PostgreSQL. The default setting for max_connections (found in /usr/local/var/postgres/postgresql.conf) is 100.

Ends up the upgrade from 9.2.4 to 9.3.1 is worthwhile for me since it greatly reduces System V shared memory requirements.

The upgrade was not time consuming, but required attention to details.

Here's what worked for me on OSX 10.9


$ brew upgrade postgresql

Keep Install Notes


==> Upgrading 1 outdated package, with result:
postgresql 9.3.1
==> Upgrading postgresql
==> Downloading http://ftp.postgresql.org/pub/source/v9.3.1/postgresql-9.3.1.tar.bz2
######################################################################## 100.0%
==> Patching
patching file contrib/uuid-ossp/uuid-ossp.c
==> ./configure --prefix=/usr/local/Cellar/postgresql/9.3.1 --datadir=/usr/local/Cellar/postgresql/9.3.1/share/postgresql --docdir=/usr/local/Cellar/postgresql/9.3.1/share/doc/postgresql --enable-thread-safety --with-bonjour --with-gssapi --with-krb5 --with-ldap --wi
==> make install-world
==> Caveats
initdb /usr/local/var/postgres -E utf8    # create a database cluster
postgres -D /usr/local/var/postgres       # serve that database
PGDATA=/usr/local/var/postgres postgres   # …alternatively

If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/mxcl/homebrew/issues/issue/2510

To migrate existing data from a previous major version (pre-9.3) of PostgreSQL, see:
  http://www.postgresql.org/docs/9.3/static/upgrading.html

When installing the postgres gem, including ARCHFLAGS is recommended:
  ARCHFLAGS="-arch x86_64" gem install pg

To install gems without sudo, see the Homebrew wiki.

To have launchd start postgresql at login:
    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
    pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
==> Summary
🍺  /usr/local/Cellar/postgresql/9.3.1: 2919 files, 39M, built in 78 seconds


Initialize new 9.3 database


$ cd /usr/local/var
$ mkdir postgres9.3
$ initdb /usr/local/var/postgres9.3 -E utf8

Migrate Data to New 9.3 Format


$ pg_upgrade \
-d /usr/local/var/postgres \
-D /usr/local/var/postgres9.3 \
-b /usr/local/Cellar/postgresql/9.2.4/bin/ \
-B /usr/local/Cellar/postgresql/9.3.1/bin/ \
-v

Create Link to Generic PostgreSQL directory


$ mv postgres postgres9.2.4
$ ln -s /usr/local/var/postgres9.3 /usr/local/var/postgres
$ psql postgres -c "select version()"

Increase System Memory for PostgreSQL


$ sudo sysctl -w kern.sysv.shmall=65536
$ sudo sysctl -w kern.sysv.shmmax=16777216

Create /etc/sysctl.conf file with following values


kern.sysv.shmall=65536
kern.sysv.shmmax=16777216

Reboot computer

Create postgres user


createuser -s -r postgres

Start postgreSQL

Note: I don't use launchd

$ pg_ctl -D /usr/local/var/postgres -l $PGDATA/server.log start

Verify PostgreSQL 9.3 Works


$ psql postgres -c "select version()"

Vacuum db


$ vacuumdb --all

Reinstall PG gem

Note: Uninstall the gem on the system command line and let Bundle Install reinstall your project's required version, which for me was version 0.17.

$ gem uninstall pg



$ cd <RAILS_PROJECT_DIR>

Possible Error

If you get the following...


Building native extensions. This could take a while... ERROR: Error installing pg:

ERROR: Failed to build gem native extension.


...then run the following after uninstalling the pg gem:


$ brew install apple-gcc42
$ gcc --version


A typical OSX DevTools install won't be enough, but you can run it anyway:

xcode-select --install

Install Command Line Tools (OS X Mavericks)

If you use PostgreSQL.App, you'll need to install Command Line Tools (OS X Mavericks) for Xcode - Late October 2013

Do the following:
  • $ gem uninstall pg
  • $ xcode
  • From Xcode menu: Xcode > Open Developer Tool > More Developer Tools... > Choose "Command Line Tools (OS X Mavericks) for Xcode - Late October 2013"
  • Run the installation program
  • $ gem install pg

Update following in Gemfile


gem 'pg', '~> 0.17'

Bundle Install


$ bundle package --all


Verify PostgreSQL 9.3 works with Rails

Change directory to your favorite Rails project open the Rails Console and do some ActiveRecord queries.

Cleanup


$ brew cleanup postgresql
$ rm -rf /usr/local/var/postgres9.2.4

Notes

  • Since directories have been moved and linked, do not run delete_old_cluster.sh
  • When tweaking system memory setting, keep in mind that SHMMAX must be an exact multiple of 4096
  • Special thanks to Matt Brictson, referenced below
  • This update will likely break your PostgreSQL admin tool like pgadmin
  • The pg_upgrade application only migrates the public schema.
  • Upgrade to lastest (v1.18.1) pgAdmin app, but backup your data first.
  • Do not remove the old version (9.2.4) until you are certain that all data has been migrated successfully.

Centos Install

This is still a work in progress...

$ su -
# cd softwares
# curl -O http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
# rpm -ivh pgdg-centos93-9.3-1.noarch.rpm
# yum install postgresql93 postgresql93-server postgresql93-contrib
# service postgresql-9.3 initdb
# chkconfig postgresql-9.3 on
# yum erase postgresql92*
# reboot

References

http://blog.55minutes.com/2013/09/postgresql-93-brew-upgrade http://www.postgresql.org/docs/current/static/release-9-3.html http://www.postgresql.org/docs/8.4/static/kernel-resources.html http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server http://postgresapp.com http://www.pgadmin.org/download/macosx.php

Tuesday, November 12, 2013

Create Graphs with Ruby, CSS and HTML

My high schooler had a homework lab assignment that required creating graphs.

She asked if I could help her by creating a nice looking graph to put in her composition lab book.

I thought, why not? ...and why not use some Ruby, CSS and HTML to make it happen?

Here's one of the graphs

CM
RAIN
TEMP
°C
36 36
34 32
32 28
30 24
28 20
26 16
24 12
22 8
20 4
18 0
16 -4
14 -8
12 -12
10 -16
8 -20
6 -24
4 -28
2 -32
0 -36


























Since I prefer to save trees I decided to fit 4 per page (see Final Results below).

Next year, when my soon-to-be high schooler asks me for help with the same lab, I'll refer her to this post :-)

Perhaps, it will help somebody else... The source can easily be modified to create a lot similar kinds of graphs.

Enjoy!

Ruby code for calculating labels

 ary2 = 36.downto(0).select{|n| 0 == n % 2 }  
 ary4 = 36.downto(-36).select{|n| 0 == n % 4 }  
 (0..ary2.size - 1).each {|i| puts "<tr> <td>#{ary2[i]}</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td>#{ary4[i]}</td> </tr>"}  

HTML Source

This is one time that it was just easier to copy and paste...
 <html>  
 <head>  
   <style type="text/css">  
    table,th, td  
    {  
      border: 1px solid black;  
      margin: 0;  
      padding: 0;  
    }  
    table {  
      border-spacing: 0;  
      border-collapse: collapse;  
      border: 0px;  
    }  
    tr {  
      height: 20px;  
    }  
    td {  
      width: 10px;  
      text-align: right;  
      padding-right: 10px;  
    }  
    .first-col {  
      width: 70px;  
      text-align: right;  
      border: 0px;  
      padding-right: 20px;  
    }  
    .last-col {  
      border: 0px;  
    }  
    #header-row td {  
      border: 0px;  
    }  
    #header-row .label {  
      position: relative;  
      left: 4px;  
    }  
    #row1-col1 {  
      float: left;  
      margin-bottom: 40px;  
    }  
    #row1-col2 {  
      float: left;  
      margin-bottom: 40px;  
    }  
    #row2-col1 {  
      float: left  
    }  
    #row2-col2 {  
      float: left  
    }  
   </style>  
 </head>  
 <body>  
   
   
 <div id="row1-col1">  
   <table>  
    <tr id="header-row">  
      <td>CM<br>RAIN</td> <td colspan="12"></td> <td class="label">TEMP<br>&deg;C</td>  
    </tr>  
    <tr> <td class="first-col">36</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">36</td> </tr>  
    <tr> <td class="first-col">34</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">32</td> </tr>  
    <tr> <td class="first-col">32</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">28</td> </tr>  
    <tr> <td class="first-col">30</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">24</td> </tr>  
    <tr> <td class="first-col">28</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">20</td> </tr>  
    <tr> <td class="first-col">26</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">16</td> </tr>  
    <tr> <td class="first-col">24</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">12</td> </tr>  
    <tr> <td class="first-col">22</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">8</td> </tr>  
    <tr> <td class="first-col">20</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">4</td> </tr>  
    <tr> <td class="first-col">18</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">0</td> </tr>  
    <tr> <td class="first-col">16</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-4</td> </tr>  
    <tr> <td class="first-col">14</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-8</td> </tr>  
    <tr> <td class="first-col">12</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-12</td> </tr>  
    <tr> <td class="first-col">10</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-16</td> </tr>  
    <tr> <td class="first-col">8</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-20</td> </tr>  
    <tr> <td class="first-col">6</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-24</td> </tr>  
    <tr> <td class="first-col">4</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-28</td> </tr>  
    <tr> <td class="first-col">2</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-32</td> </tr>  
    <tr> <td class="first-col">0</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-36</td> </tr>  
   </table>  
 </div>  
   
   
 <div id="row1-col2">  
   <table>  
    <tr id="header-row">  
      <td>CM<br>RAIN</td> <td colspan="12"></td> <td class="label">TEMP<br>&deg;C</td>  
    </tr>  
    <tr> <td class="first-col">36</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">36</td> </tr>  
    <tr> <td class="first-col">34</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">32</td> </tr>  
    <tr> <td class="first-col">32</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">28</td> </tr>  
    <tr> <td class="first-col">30</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">24</td> </tr>  
    <tr> <td class="first-col">28</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">20</td> </tr>  
    <tr> <td class="first-col">26</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">16</td> </tr>  
    <tr> <td class="first-col">24</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">12</td> </tr>  
    <tr> <td class="first-col">22</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">8</td> </tr>  
    <tr> <td class="first-col">20</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">4</td> </tr>  
    <tr> <td class="first-col">18</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">0</td> </tr>  
    <tr> <td class="first-col">16</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-4</td> </tr>  
    <tr> <td class="first-col">14</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-8</td> </tr>  
    <tr> <td class="first-col">12</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-12</td> </tr>  
    <tr> <td class="first-col">10</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-16</td> </tr>  
    <tr> <td class="first-col">8</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-20</td> </tr>  
    <tr> <td class="first-col">6</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-24</td> </tr>  
    <tr> <td class="first-col">4</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-28</td> </tr>  
    <tr> <td class="first-col">2</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-32</td> </tr>  
    <tr> <td class="first-col">0</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-36</td> </tr>  
   </table>  
 </div>  
   
 <br>  
 <div id="row2-col1">  
   <table>  
    <tr id="header-row">  
      <td>CM<br>RAIN</td> <td colspan="12"></td> <td class="label">TEMP<br>&deg;C</td>  
    </tr>  
    <tr> <td class="first-col">36</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">36</td> </tr>  
    <tr> <td class="first-col">34</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">32</td> </tr>  
    <tr> <td class="first-col">32</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">28</td> </tr>  
    <tr> <td class="first-col">30</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">24</td> </tr>  
    <tr> <td class="first-col">28</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">20</td> </tr>  
    <tr> <td class="first-col">26</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">16</td> </tr>  
    <tr> <td class="first-col">24</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">12</td> </tr>  
    <tr> <td class="first-col">22</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">8</td> </tr>  
    <tr> <td class="first-col">20</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">4</td> </tr>  
    <tr> <td class="first-col">18</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">0</td> </tr>  
    <tr> <td class="first-col">16</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-4</td> </tr>  
    <tr> <td class="first-col">14</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-8</td> </tr>  
    <tr> <td class="first-col">12</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-12</td> </tr>  
    <tr> <td class="first-col">10</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-16</td> </tr>  
    <tr> <td class="first-col">8</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-20</td> </tr>  
    <tr> <td class="first-col">6</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-24</td> </tr>  
    <tr> <td class="first-col">4</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-28</td> </tr>  
    <tr> <td class="first-col">2</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-32</td> </tr>  
    <tr> <td class="first-col">0</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-36</td> </tr>  
   </table>  
 </div>  
   
   
 <div id="row2-col2">  
   <table>  
    <tr id="header-row">  
      <td>CM<br>RAIN</td> <td colspan="12"></td> <td class="label">TEMP<br>&deg;C</td>  
    </tr>  
    <tr> <td class="first-col">36</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">36</td> </tr>  
    <tr> <td class="first-col">34</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">32</td> </tr>  
    <tr> <td class="first-col">32</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">28</td> </tr>  
    <tr> <td class="first-col">30</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">24</td> </tr>  
    <tr> <td class="first-col">28</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">20</td> </tr>  
    <tr> <td class="first-col">26</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">16</td> </tr>  
    <tr> <td class="first-col">24</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">12</td> </tr>  
    <tr> <td class="first-col">22</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">8</td> </tr>  
    <tr> <td class="first-col">20</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">4</td> </tr>  
    <tr> <td class="first-col">18</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">0</td> </tr>  
    <tr> <td class="first-col">16</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-4</td> </tr>  
    <tr> <td class="first-col">14</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-8</td> </tr>  
    <tr> <td class="first-col">12</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-12</td> </tr>  
    <tr> <td class="first-col">10</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-16</td> </tr>  
    <tr> <td class="first-col">8</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-20</td> </tr>  
    <tr> <td class="first-col">6</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-24</td> </tr>  
    <tr> <td class="first-col">4</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-28</td> </tr>  
    <tr> <td class="first-col">2</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-32</td> </tr>  
    <tr> <td class="first-col">0</td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td class="last-col">-36</td> </tr>  
   </table>  
 </div>  
   
   
 </body>  
 </html>  

Final Result