Ivor O’Connor

March 9, 2013

The Universal IDE: VI with SPF13

Filed under: bash, git, howto, html5, IDE, JavaScript, Linux, mint 14 xfce, php, sqlite, ubuntu, vi, vim, vundle — ioconnor @ 4:08 am

This is a youtube video I made on how to install SPF13 on Linux Mint 14 XFCE. I like learning from youtube videos whenever possible. If in the future I want to install SPF13 and something is not how I remember it I can return to this video. SPF13 makes VI into a universal IDE. It works on most if not all OSs including windows and the mac.  Sure if you are working with something like AIX, HP-UX, or some platform that does not have vim installed SPF13 will not be for you. I’d recommend you put in your base .vimrc commands directly into the .vimrc.local file and use them along with SPF13. Picking and choosing what you find works.

UPDATE 2013-03-08: Insert the following line into your .bashrc file before starting to get full colors: export TERM=”xterm-256color”

February 7, 2013

vundle

Filed under: bash, css, git, html5, JavaScript, Linux, pdo, php, vim, vundle — ioconnor @ 12:36 pm

Vundle is the new package manager for vim plugins. I’m thinking it will be largely responsible for making a resurgence in the use of vim because it allows clean installs of IDE tools for various environments. Allowing easy file navigation, editing, compiling, debugging, and all the other things you might want to do. However vundle is new and largely unknown. Take a look for it in any vim book and you won’t find it. This post will be continuously updated until it has the information I find useful and need on a routine basis. My first effort will be in setting up an environment for PHP, javascript, html, css, bash, c/c++, git, pdo, and mysql/sqlite3 development. So I’m thinking there will probably be a flurry of updates to this post over the next few months.

First off auto installing vundle. I stole the following from this site but had to remove the EOL comments to make it work. Make a copy of your existing “.vimrc” and then add the following to the end of your .vimrc file:

" Setting up Vundle - the vim plugin bundler
let iCanHazVundle=1
let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
if !filereadable(vundle_readme)
echo "Installing Vundle.."
echo ""
silent !mkdir -p ~/.vim/bundle
silent !git clone https://github.com/gmarik/vundle ~/.vim/bundle/vundle
let iCanHazVundle=0
endif
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
"Add your bundles here
Bundle 'Syntastic'
Bundle 'altercation/vim-colors-solarized'
Bundle 'https://github.com/tpope/vim-fugitive'
"...All your other bundles...
if iCanHazVundle == 0
echo "Installing Bundles, please ignore key map error messages"
echo ""
:BundleInstall
endif
" Setting up Vundle - the vim plugin bundler end

Then type in to vim “:BundleInstall!” and watch it install before restarting vim.

2013-02-08 UPDATE: Interesting links:

February 22, 2009

Awk and Sed one liners explained

Filed under: awk/sed, bash, cli, php, Uncategorized — Tags: , , , — ioconnor @ 7:44 pm

There is an excellent article at OS News here http://www.osnews.com/story/21004/Awk_and_Sed_One-Liners_Explained

Much of the stuff presented there is very useful. However… Yes there is a big “however”. Howevery do you really want to use these platform specific arcane relics that do not have the error handling capabilities needed to handle unexpected scenarios? Short answer… NO.

Use PHP instead. It can do everything awk/sed can much more easily. More importantly you can plan for the unexpected since you get errors back instead of just blindly assuming the awk and sed commands worked as they did in your microcosm of a test world.

Sure PHP is not always installed on the platform. Say you are planning to put your code in a debian package and you are afraid to use PHP since it does not come preinstalled. Well simply put the latest release of PHP as a requirement for your package. Done. Before your package is loaded PHP gets loaded so you have all the wonderful PHP tools and perhaps libraries available.

Then there is the matter of running your code run on windows platforms. Same thing. Require PHP to be installed first. You can find it here for free on the M$ world. Sure there are some cooler languages like python and ruby but they simply are not as solid as PHP nor do they have the excellent pear libraries.

October 20, 2008

sqlite3

Filed under: cli, pdo, php, sqlite, ubuntu — Tags: , , — ioconnor @ 12:29 am

Google gears uses sqlite for it’s client side database. I’ve never used sqlite so I went to the sqlite website. I naturally downloaded all their documentation to file allowing me to browse it offline. All companies should provide this ability. However the documentation only covered C/C++ and TCL.

I really wanted to use PHP but decided to use C/C++ because an example from their site was ready to go. I copied their example but could not compile it. First it was simply locating the proper sqlite3.h file. This was just the start of many errors so I gave up. If it does not work straight out of the box on the latest Ubuntu then there is something very wrong. I googled for C/C++ examples elsewhere but without luck.

So I tried googling for PHP CLI examples under Ubuntu. Not much luck but there was something close at http://www.litewebsite.com/?c=49#sqlite3 so I snagged it. Here it is, modified to run from the command line, so I don’t have to search for a half decent starting example again:


#!/usr/bin/php -q

<?php
//# Much of this I got from:
//# http://www.litewebsite.com/?c=49#sqlite3
//# http://www.devshed.com/c/a/PHP/Working-with-Prepared-Queries-with-PDO-Objects-in-PHP-5/
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);

function CountFromPage($page) {
try{
$dbh = new PDO('sqlite:pdoTutorial.sqlite3');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//$dbh->beginTransaction();
$statement = $dbh->query('SELECT name FROM sqlite_master WHERE type = \'table\'');
$result = $statement->fetchAll();
if( sizeof($result) == 0 ){ // No database tables found? (Will need to refine this check for pageView table only.)
$dbh->exec('CREATE TABLE pageView(id INTEGER PRIMARY KEY AUTOINCREMENT, page CHAR(256), access INTEGER(10))');
}

// insert page visit in database with a prepared statement
$stmt = $dbh->prepare('INSERT INTO pageView (page, access) VALUES (?, ?)');
$stmt->bindParam(1, $page, PDO::PARAM_STR);
$stmt->bindParam(2, time(), PDO::PARAM_INT);
$stmt->execute();

// get page views from database
$pageVisit = $dbh->quote($page);
$sqlGetView = 'SELECT count(page) AS view FROM pageView WHERE page = '.$pageVisit.'';
$result = $dbh->query($sqlGetView);
$pageView = $result->fetch(); // store result in array
//$dbh->commit();
return($pageView['view']);
}catch( PDOException $exception ){
//$dbh->rollBack();
die($exception->getMessage());
}

}

if (2 != $_SERVER["argc"]) {
echo "\tWrong number of arguments:" . $_SERVER["argc"] . "\n";
echo "\tProper syntax is: \n" ;
echo "\t\t" . $_SERVER["argv"][0] . " page\n";
} else {
$page = $_SERVER["argv"][1];
echo 'Page "' . $page . '" has been viewed '. CountFromPage($page).' times.'."\n";
}
?>

I stuck it into a file called 1.php in my samba bin directory as my starting point. This way the database can be shared…

Here is the output when run:

~/samba/bin$ 1.php 11
Page “11” has been viewed 1 times.
~/samba/bin$ 1.php 11
Page “11” has been viewed 2 times.
~/samba/bin$ 1.php 12
Page “12” has been viewed 1 times.
~/samba/bin$ 1.php 12
Page “12” has been viewed 2 times.
~/samba/bin$ 1.php 11
Page “11” has been viewed 3 times.

Blog at WordPress.com.