Archive for February, 2011

WordPress determine version number

Wednesday, February 23rd, 2011


WordPress custom sidebar category filtered archive code

Wednesday, February 23rd, 2011

<div id=”sidebar”>
$myposts = get_posts(“category=1”);
foreach($myposts as $post) : ?>
<li><a href=”<?php the_permalink(); ?>“><?php the_time(‘M’) ?>. – <?php the_title(); ?></a></li>
<?php endforeach; ?>

mostly in thanks to:

WordPress Post to Category ID association in the Database

Wednesday, February 23rd, 2011

WordPress 3

Start with a Post and get Category ID:

Get the id number(A) for the post you’re interested in in wp_posts table,  id column

Go to wp_term_relationships table, and find that same id number(A) in the object_id column, read over to the term_taxonomy_id column and get that number, that’s the category id

Start with a Category ID and get Category Name:

Go to the wp_terms table, and find the category you’d like in the name column, read over to the term_id and note the number

Find all Cateogry IDs:

Go to the wp_term_taxonomy table and sort by taxonomy value ‘category category number is in term_taxonomy_id column

Ruby on Rails : rateatrack app notes to self

Tuesday, February 22nd, 2011

add in item to an array/object example:

@artists << track.artist

order object contents example:

def index
@tracks = Track.all(:order => ‘artist‘)

simple rating average math:

rating = params[‘rating’].to_i
@track.average = ((@track.average * @track.numberofvotes) + newlysubmittedrating)/(@track.numberofvotes + 1)
@track.numberofvotes = @track.numberofvotes + 1

simple db update conditional redirect with reporting:

if @track.update_attributes(params[:track])
format.html { redirect_to(“/”, :notice => ‘Track updated.’) }

similar db object one liners:

  • @object.destroy
  • @track = Track.find(params[:id])
  • @object =
  • @record = Track.find_by_sql “SELECT * …”

simple char substitution:

somevariablename = variablecontainingcharstoswap.gsub(“_”, ” “)

method simply needs to render a view other than that matching its name:

render :viewname

.each loop fills text variable, then renders it:

@record.each do |track|
$str << “#EXTINFO:#{track.length},#{track.title}<br />#{track.url}<br />”
render :text => $str

notice: to substitute variables into such a statement, #{variablename}

simple and example model with validation and some messaging:

class Track < ActiveRecord::Base
validates :url,  :presence => true
validates :title, :presence => true, :length => { :minimum => 1 }
validates :artist, :presence => true
validates :length, :presence => true
validates_format_of :url, :title, :artist, :length, :with =>/^[a-zA-Z \\ \/. : 0-9]+$/x, :message=>”alphanumeric characters, colons, periods, forward/backward slashes only please”


Rateatrack::Application.routes.draw do

match “tracks/generate/” => “tracks#generate” // custom :action route
resources :tracks

get “home/index”

root :to => “tracks#index” // sidestep app index, route to desired controller

heroku only uses Postgres, used MySQL locally, fun experiment to RELY on persistence:


adapter: mysql2
encoding: utf8
reconnect: false
database: rateatrack_development
pool: 5
username: user_name
password: password_removed
socket: /tmp/mysql.sock

encoding: unicode
adapter: postgresql
database: rateatrack_production

simple schema.rb

ActiveRecord::Schema.define(:version => 0) do

create_table “tracks”, :force => true do |t|
t.string  “url”,     :limit => 64
t.string  “title”,   :limit => 64
t.string  “artist”,  :limit => 64
t.integer “length”
t.decimal “average”, :default => 0.0, :precision => 8, :scale => 2
t.integer “votes”,   :default => 0


RoR version of include, partial, snippet, and so on…

<%= render ‘form’ %>

this will pull from the same folder as the calling resource, file name _form.erb

form example with error checking:

<% @track %>
<%= form_for(@track) do |track_form| %>
<% if @track.errors.any? %>
<%= pluralize(@track.errors.count, “error”) %> prohibited this post from being saved:
<% @track.errors.full_messages.each do |msg| %>
<%= msg %>
<% end %>
<% end %>
<table><tr><th><%= track_form.label :url %></th></tr>
<tr><td><%= track_form.text_field :url %></td></tr></table>
<%= track_form.submit %>
<% end %>


gem ‘rails’, ‘3.0.4’
gem ‘mysql2’

Ruby on Rails simple authentication

Tuesday, February 22nd, 2011


class ApplicationController < ActionController::Base


def authenticate
authenticate_or_request_with_http_basic do |user_name, password|
user_name == ‘admin’ && password == ‘password’

example usage: project/app/controllers/example_controller.rb

class TracksController < ApplicationController

before_filter :authenticate, :except => [:index, :show]


Create Rails Application Directory Godaddy Hosting

Friday, February 18th, 2011

If you use 4GH:


Ruby on Rails 3 Mac OSX 10.6.6 – Some Basics

Thursday, February 17th, 2011

If you just switched to Rails 3, prepare for some changes…

Need an IDE?

Recommended tutorials:

Gems mysql2 problems?:

New Project:

Navigate to the folder where you’d like to create a new project, terminal:

$ rails new projectname

Start Server:

Navigate to the new project, terminal:

$ rails s

Create a database for the new project, terminal (if you have phpMyAdmin simply type name and push Create):

$ mysqladmin -u root -p create projectname

Scaffold example:

$ rails generate scaffold Post name:string title:string content:text

Migrate now (env specific):

$ rake db:migrate RAILS_ENV=production

link_to example:

<%= link_to “My Blog”, posts_path %>


$ rails console

Active Record Doc:

Unescaped HTML (escaped now default in 3):

<%= raw %>

Layout and Rendering:

Routing from the Outside In:

Ruby on Rails Guide:

Ruby on Rails Tutorial:

WordPress control number of posts per archive page

Wednesday, February 16th, 2011

edit archive.php

replace this:

< ?php get_header(); ? >

with something along these lines:

< ?php get_header(); ? >
< ?php
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
‘showposts’ => 10,
‘caller_get_posts’=> 1
? >

Perl valid email regular expression

Tuesday, February 1st, 2011

# Check for valid email address


CSS !important override

Tuesday, February 1st, 2011

A rule that has the !important property will always be applied no matter where that rule appears in the CSS document.


p { color: #ff0000 !important; }

CSS text-transform

Tuesday, February 1st, 2011


also consider:

CSS pseudo elements & pseudo classes

Tuesday, February 1st, 2011

CSS Pseudo Elements

Adds content after an element

Adds content before an element

Adds a style to the first character of a text

Adds a style to the first line of a text


Posted on 5 Oct 2009, 17:00 – Category: CSS

Pseudo Classes

Adds a style to an element that is activated

Adds a style to an element that is the first child of another element

Adds a style to an element that has keyboard input focus

Adds a style to an element when you mouse over it

Adds a style to an element with a specific lang attribute

Adds a style to an unvisited link

Adds a style to a visited link

CSS em

Tuesday, February 1st, 2011

h1 {font-size:2.5em} /* 40px/16=2.5em */
h2 {font-size:1.875em} /* 30px/16=1.875em */
p {font-size:0.875em} /* 14px/16=0.875em */

Perl string substitution substr

Tuesday, February 1st, 2011


my $text = “This is one heck of a story”;

my $swap = “heck”;

my $replacement = “hell”;

substr($text, index($text, $swap), length($swap), $replacement);

print $text;

Perl chop chomp

Tuesday, February 1st, 2011

sub spacer

{ print “<br />”; }

my $text = “This is one heck of a story”;

# remove the last character

print chop($text); spacer(); # returns y

print $text; spacer(); # we can see that it also DID alter the variable

# remove newlines from the end of a string only

$text = $text . “\n\n”;

print $text; spacer();

print chomp($text); spacer(); # again, returns # of items “chomp”ed 🙂

print $text; spacer();

Perl output pretty HTML

Tuesday, February 1st, 2011

# outputting pretty HTML

# basically a matter of including \n
# and using Perl qq function

my (@time,@days,@months,$time,$days,$months);

@time = localtime;

@days = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);

@months = qw(January February March April May June July August September October November December);

print qq(\n<html>\n<head>\n<title>Get the date</title>\n</head>\n<body>\n);

print qq(Today is <strong>$days[$time[6]], $months[$time[4]] $time[3]</strong>.);

print “\n</body>\n”;

print ‘</html>’;

CakePHP Setting up your system to Bake

Tuesday, February 1st, 2011
start baking:

C:\xampp\htdocs\project\app>”../cake/console/cake” bake

Starting a new project with CakePHP

Tuesday, February 1st, 2011

download the current release:

unzip, copy/rename folder as desired

check apache file permissions
app/tmp – 0777

core.php – change Security.salt to new value
database.php.default – remove .default, and configure values according to your database


CakePHP naming conventions

Tuesday, February 1st, 2011

URL will trigger controller

in app/controllers:
in there:
class DataUsersController extends Controller {

this should be the same as the table it will reference:

in app/models:
class data_user extends AppModel {

in app/views/data_users: