The Archives

SEARCH

I’m Attending

CodeMash

Tag Archives: Programming

Installing PostgreSQL on OSX

Posted in: General by Steve on June 19, 2012

While trying to move my development environment from SQLite3 to PostgreSQL, I ran into an issue. Following the instructions from Railscasts #342:

brew install postgresql

Got this error message:

Error: You must `brew link ossp-uuid’ before postgresql can be installed

To fix this, I had to execute the following command:

sudo chown -R whoami /usr/local/share/man/man3

Then I was able to brew install postgresql.

After doing that, I wanted to start my first database by running the command:

initdb /usr/local/var/postgres

This gave me the error:

FATAL: could not create shared memory segment: Cannot allocate memory

To fix this, I had to add a file called /etc/sysctl.conf and add the following lines:

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

Additionally, I had to add

export PATH=/usr/local/bin:$PATH

to my ~/.bash_profile file

After restarting my machine, I was then able to create the database and move on with moving over to PostgresSQL 

REF:

https://github.com/mxcl/homebrew/issues/11427

https://gist.github.com/2794006

http://jeffammons.net/2011/09/fixing-postgres-on-mac-10-7-tiger-for-django/

Issue Installing Gems with Ubuntu 10.04, RVM and zlib

Posted in: Programming by Steve on October 30, 2010

So after writing up the tutorial on getting a Linux VM setup, I came across and issue where I couldn’t install gems. I would get the following error message after trying to install any gem:

ERROR: Loading command: install (LoadError)
  no such file to load – zlib
ERROR: While executing gem … (Name Error)
  uninitialized constant Gem::Commands::InstallCommand

image

I found the answer in the RVM documentation: http://rvm.beginrescueend.com/packages/zlib/

Execute these commands:

rvm package install zlib
rvm remove 1.9.2
rvm install 1.9.2 -C --with-zlib-dir=$HOME/.rvm/usr

This will install zlib in your ~/.rvm/usr directory.

I could then move forward setting up my development environment.

Using the Right Tool for the Job

Posted in: Programming by Steve on October 23, 2010

hammer-screwWith my blinders on, I dove headfirst into learning Rails and trying to fit my existing website into a shiny, new container.  The problem was that it would have taken too long to get everything that I needed for my website done in a reasonable amount of time.  The customer has been requesting new features and to polish up some of the old ones.  If I was to get all of these features accomplished, I was going to need a lot more time to get it done.

So instead of trying to build my own CMS, I am going to use a CMS that already has a multitude of code, layout and experience:

WordPress

GASP! Blasphemy! A true programmer would never use something like that for a new site, written in PHP, and being all PHP-y and scripty.  It doesn’t even have unit testing and you can’t do TDD with it!

Yes, in the past, I would have said such things, but as I’ve learned: if someone’s already done it for you, why spend time trying to do it again. It really meets all of my requirements and I can give the customer a lot of choices when it comes to functionality.  If I need to customize anything, it’s an even better opportunity for me to dig into a language that I don’t know much about.  Wasn’t that the original reason for learning Ruby on Rails?

So why not WordPress?

Technical Debt Presentation

Posted in: Programming by Steve on October 22, 2010

Codemash 2011 registration opens today, so to celebrate, here is a video and presentation deck from Gary Short’s talk on Technical Debt.  It was one of my favorites.

Autotest in Ruby

Posted in: Programming by Steve on September 29, 2010

Getting constant feedback on the health of your system is always a great thing.  In rails, you can install a gem called autotest that can run your tests as you change your application and let you know if you have broken anything.

All you have to do is start a terminal window, and type “autotest”.  That’s it!  You get instant feedback on your tests!

http://ph7spot.com/musings/getting-started-with-autotest

How to Verify Your Stored Procedures

Posted in: Programming by Steve on May 5, 2010

One of the things I’ve been trying to do is to eliminate the unnecessary stored procedures from our project.  Currently, we have about 150 left, but a lot of them are still used.  Some of them are still left over and no longer are called from our application.  As I was building a new SQL install script, I was trying to run a script of all stored procedures in one database and create them all in a new one.  I found that some of them no longer would work because of changes we’ve made to the database that have broken these stored procedures without even knowing. 

I asked on twitter how this could be done and Argenis Fernandez (@afernandez) suggested that I look into a Powershell script to verify stored procedures still work.

After some investigation on how Powershell and SQL work together, I scraped together this script:

$server = "localhost";		# The SQL Server instance name
$database = "MyDatabase";		# The database name
 
# Load the SMO assembly
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
 
# Create the SMO objects
$srv = New-Object "Microsoft.SqlServer.Management.SMO.Server" $server;
$db = New-Object ("Microsoft.SqlServer.Management.SMO.Database");
 
# Get the database
$db = $srv.Databases[$database];
 
# For each stored procedure in the database
foreach($proc in $db.StoredProcedures)
{   
    # NOTE: my stored procedures are all prefixed with "web_"
    if ($proc.Name.StartsWith("web_"))
	{    
        $proc.TextBody = $proc.TextBody;
        $proc.Alter();        
    }    
}

If any error occurs, it will display which procedure name did not get altered properly.

In my application, all my stored procedures that I use in the websites are prefixed with “web_”.  This made it easy to check if the procedures used still work. 

SQL Query Madness

Posted in: Programming by Steve on April 15, 2010

I would consider myself to be pretty good with database design and queries, but this one has me stumped.

Our application allows administrators to add “User Properties” in order for them to be able to tailor the system to match their own HR systems.  For example, if your company has departments, you can define “Departments” in the Properties table and then add values that correspond to “Departments” such as “Jewelry”, “Electronics” etc…  You are then able to assign a department to users.

Here is the schema:

image

In this schema, a user can have only one UserPropertyValue per Property, but doesn’t have to have a value for the property.

I am trying to build a query that can use the PropertyValues as the filter for users.  My query looks like this (SQL Server 2005):

SELECT UserLogin, FirstName, LastName
FROM Users U
LEFT OUTER JOIN UserPropertyValues UPV 
	ON U.ID = UPV.UserID
WHERE UPV.PropertyValueID IN (1, 5)

When I run this, if the user has ANY of the property values, they are returned.  What I would like to have is where this query will return users that have values BY PROPERTY.

So if PropertyValueID = 1 is of Department (Jewelry), and PropertyValueID = 5 is of EmploymentType (Full Time), I want to return all users that are in Department Jewelry that are EmployeeType of Full Time, can this be done?

I’m not sure how this can be accomplished without building dynamic SQL, so I thought I would throw this out to see what I could find.


UPDATE:

I posted this question on StackOverflow to see if there are any more ideas

http://stackoverflow.com/questions/2647570/where-clause-on-joined-table-used-for-user-defined-key-value-pairs

New Laptop – I’m a Mac

Posted in: Programming by Steve on February 1, 2010

Macbook After going back and forth between getting a Dell, HP Envy or Asus, I decided to go outside of my comfort zone and bought a Macbook.

The reason I got it was because I wanted to learn a new programming language and to see how the other side lives.  Codemash taught me that if I want to get better as a programmer, I have to widen my experiences to more than just .NET. 

So this is the first step to jump start my learning.  I hope to upgrade it so a better hard drive (SSD), more memory and to get the new Speck soft satin case (and a travel case too).  I will be blogging more about the experience of OS-X vs Windows along with attempting to learn Ruby on Rails.

Building out a new Laptop

Posted in: Programming by Steve on January 11, 2010

LaptopIn March of 2009, I decided it was time to get a netbook.  I wanted to have something that was portable and fast.  I decided to go with the ASUS Eee PC 1000HE Blue Netbook.  It was powerful enough to run Windows 7 Ultimate, SQL Server, Visual Studio 2008 and other development applications, making it very convenient to use on the road at customer locations.  This laptop boasted a 9.5 hour battery, but I upgraded it to have 2 GB of memory and a 320 GB 7200 RPM hard drive.  This lowered the time to about 6 hours, which was more than acceptable.

After using it for 9 months and trying to show videos and do more programming on it, the netbook route isn’t working for me.  I need to have a laptop that is able to handle the load of video since my son, Conner, loves to watch the Muppets.  I am looking to upgrade to a new laptop.

The first step is to clean house.  I am what you would call a “pack rat”.  I have all my old computer equipment and other miscellaneous electronics stored in my closet, stacked to the ceiling (my wife can attest to this).  With all the stuff I have, I couldn’t possibly use it all, so I am selling it on eBay.

The second step is to determine which laptop to purchase.  Here are my requirements for the laptop:

  • Intel Core i7 Core i7 CPU
  • 4GB RAM
  • Discrete graphics card
  • Between 12” and 15.5” High Resolution LED screen
  • Bluetooth
  • capable of handling an Intel X25-M SSD upgraded hard drive
  • 3 year warranty
  • no more than $1,700
  • 0% financing for at least 6 months

ASIDE: Originally, I was looking to purchase a MacBook Pro, but since the refresh hasn’t happened and I’m well invested in the Windows environment (.NET, Windows Home Server, gaming, knowledge), I am not looking into one currently.  Maybe in the future I’ll investigate a Apple, but for now, I’m sticking to Windows laptops.

I’m still investigating the best choice from these:

Right now, the Dell seems to be winning on pricing point at $1,500 with tax and shipping and 9 months of 0% financing with the following load out:

  • Intel® Core™ i7-720QM Quad Core Processor @ 1.6GHz (2.8GHz Turbo Mode, 6MB Cache)
  • 3 Year Basic Service Plan
  • 15.6” Full High Definition (1080p) High Brightness LED Display with TrueLife™ and Camera   
  • 4GB Shared Dual Channel DDR3 at 1333MHz   
  • 320GB SATA Hard Drive (7200RPM)   
  • 512MB ATI Mobility Radeon HD 4570   
  • 8X Slot Load CD/DVD Burner (Dual Layer DVD+/-R Drive)   
  • 85 Whr Lithium Ion Battery (9 cell)   
  • Intel 5300 Ultimate-N Half Mini Card (3×3) with MyWiFi   
  • Dell Wireless 365 Bluetooth Internal (2.1)   
  • Back-lit Keyboard   

With this load out, I can do all my development and show videos to Conner (like this one, his favorite) without any problems. 

The HP Envy comes out closer to $1,700 with a 3 year warranty and only 6 months of 0%. It’s too bad the HP Envy 13 doesn’t come with a Core i7 CPU because that would be the perfect replacement for my netbook.  I’m wondering if I should just get the Envy 13 since the processor is still such a better upgrade to what I have now.  I did see one of these at Fry’s the other day and it definitely is one sweet laptop.

The Asus is out of stock and I haven’t seen one in person to make an informed decision on this one.

I will update on any further information or if a purchase is made.  If you have any other thoughts or ideas for me, please feel free to comment.