Cross Browser Gradient Shadowed Buttons

This is the CSS I use to make grey and blue buttons for fun.

.shadow {
	-moz-box-shadow: 3px 3px 4px #969696;
	-webkit-box-shadow: 3px 3px 4px #969696;
	box-shadow: 3px 3px 4px #969696;
	/* For IE 8 */
	-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#969696')";
	/* For IE 5.5 - 7 */
	filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#969696');
}
 
.button-grey {
	padding:5px;
	color:#FFF;
	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#5E5E5E', endColorstr='#333333'); /* for IE */
	background: -webkit-gradient(linear, left top, left bottom, from(#5E5E5E), to(#333333)); /* for webkit browsers */
	background: -moz-linear-gradient(top,  #5E5E5E,  #333333); /* for firefox 3.6+ */
	border:1px solid #666;
	cursor:pointer;
}
 
.button-blue {
	padding:5px;
	color:#FFF;
	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#51A9C6', endColorstr='#1375AE'); /* for IE */
	background: -webkit-gradient(linear, left top, left bottom, from(#51A9C6), to(#1375AE)); /* for webkit browsers */
	background: -moz-linear-gradient(top,  #51A9C6,  #1375AE); /* for firefox 3.6+ */
	border:1px solid #1480BE;
	cursor:pointer;
}
Posted in Internet | Tagged | Leave a comment

Simple PostgreSQL and data backup script for Linux bash

backup-script.sh

#!/bin/bash
export PGPASSWORD=SUPERSECRETPASSWORD
thedate=`date --rfc-3339=date`
echo "Making tarball for $thedate"
filename="$thedate.tar.gz"
`pg_dump -U postgres the_database > /var/www/db_dump.sql`
tar czf /backups/$filename /var/www

Above is a simple bash script to backup a directory after making a PostgreSQL data dump. I left a lot of my original code in place so you can see how to work with directories that have spaces. The trick is to escape when you use double quotes and do nothing when you use no quotes.

I also told crontab to run this file every day by making a crontab file:

cron.txt

30 5 * * * /home/user/cron/backup-script.sh

Then telling crontab to use the file

crontab -e cron.txt
Posted in bash, Linux, PostgreSQL | Tagged , | Leave a comment

Blue Cross Blue Shield Kansas City BCBSKC Claim Fax Number

Searching high and low for this number I had to resort to actually calling someone. Is it still 1999?

Fax your BCBCKC claims to:

816-395-3959
Attn: Written Correspondence
Posted in Life | Leave a comment

Sharpy Lite PHP RAD Framework

So here is part of the Sharpy framework I have been developing with. Once I get things more mature, I will release the whole php rapid application development framework.

Download sharpy-lite. Published under the MIT License.

Basically just upload the content to your web server (renaming public_html if needed) and browse to the site. PHP 5.3.x is required.

I will write up more detailed information upon request, but to get going …

To create a new module, copy the index module and rename it to whatever you want, without meta characters. Hyphens are acceptable.

Posted in PHP | Tagged | Leave a comment

Node.js MVC – Starting an MVC setup for Node.js

server.js

var http = require('./lib/http')
var router = require('./lib/router')
var fs = require('fs')
 
http.serve(router.dispatch)

http.js

var http = require('http')
 
exports.serve = function(handleRequest) {
  http.createServer(function (request, response) {
    handleRequest(request, response)
  }).listen(parseInt(process.env.PORT) || 8001)
}

lib/router.js

var http = require('./http');
var sys = require("sys");
var path = require('path');
 
exports.dispatch = function (request, response) {
	if(request.url != '/'){
		var tmpvar = request.url.split('/');
		if(tmpvar[0] == '')
			tmpvar.splice(0, 1);
	    if(tmpvar.length >= 1){
	      request.controller = tmpvar[0];
	      if(tmpvar.length == 1){
	    	request.action = 'index';
	      } else {
	    	if(tmpvar[1]) // sometimes the action is just / which causes issues
	    		request.action = tmpvar[1];
	    	else
	    		request.action = 'index';
	      }
	    }
	} else {
	  // requested / ... the index
	  request.controller = request.action = 'index';
	}
	console.log('Controller = ' + request.controller + ' :: Action = ' + request.action);
	if(typeof(request.controller) != 'undefined' && typeof(request.action) != 'undefined'){
	  var thePath = path.resolve('controllers/' + request.controller + '.js');
	  path.exists(thePath, function(exists){
	    if(exists){
	      var controller = require(thePath);
	      if(controller.run(request, response))
	    	  return true;
	      else
	    	  error404(request, response);
	  	} else { 
	  	  error404(request, response);
	  	}
	  });
	}      	
}
 
function error404 (request, response){
  response.writeHead(404, {'Content-Type': 'text/html'});
  response.end('<p>The page you requested was not found!</p>');
}

controllers/index.js

var fs = require('fs'), 
	path = require('path');
 
exports.run = function(request, response){
	response.writeHead(200, {'Content-Type': 'text/html'});
	var encoding = 'utf8';
	var viewfile = request.action + '.html';
	var theFile = path.resolve('views/' + request.controller + '/' + viewfile);
	path.exists(theFile, function(exists){
		if(exists){
			var output = fs.readFileSync(theFile, encoding);
			response.end(output);
		} else { 
			return false;
		}
	});
	return true;
}

views/index.html

Hello World!
Posted in Internet, JavaScript, Node.js / Socket.io | Tagged , , | 1 Comment

Resizing and recoloring images with Python

import Image # I have the power!
 
theFile = "foo.png" # the file to start with
 
img = Image.open(theFile) # open the image
resized = img.resize((75,75)) # resize the image
r, g, b, alpha = resized.split() # get the RGBA data
 
newImage = Image.new(resized.mode, resized.size, "black") # make a new image
newImage.paste(resized, mask=alpha) # copy the old to the new
newImage.save("out.png") # save it
 
print "Done" # Yay!
Posted in Python | Tagged , | Leave a comment

Set static IP address in Ubuntu

You will need to edit your /etc/network/interfaces file

sudo nano /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
network 192.168.1.0
broadcast 192.168.1.255

Restart networking via

sudo /etc/init.d/networking restart
Posted in Internet, Linux, Operating Systems | Tagged , , | Leave a comment

Installing Node.js and Socket.io on Ubuntu

Issue the following on the command line:

cd ~
sudo apt-get install libv8-2.0.3 libv8-dev libv8-dbg libssl-dev curl
wget http://nodejs.org/dist/node-v0.4.3.tar.gz
tar zxvf node-v0.4.3.tar.gz
cd node-v0.4.3
./configure && make && make install
sudo curl http://npmjs.org/install.sh | sudo sh
sudo npm install socket.io

First we change to our home directory via cd ~ … even though the tilda in the code above looks like a hyphen. Then we install Google V8, SSL development files and cURL. Next we grab Node.js, configure and install it. Nearly last, we download and install npm. Finally, we tell npm to install socket.io for us.

fin.

Posted in Commands, Google, Internet, JavaScript, Linux, Node.js / Socket.io, Operating Systems | Tagged , , , | Leave a comment

Super Simple Node.js Chatroom

Updated: Fixed an issue in the HTML code where node.js would create a malformed URL.
Note: Don’t use a port in the FQDN, specify the port in the io.Socket options.
Node.js Code

var http = require('http'), // HTTP server
  io = require('socket.io'), // Socket.io
  fs = require('fs'); // File System
 
// make a standard server
server = http.createServer(function(req, res){
    res.writeHead(200, {'Content-Type': 'text/html'});
    // read index.html and send it to the client
    var output = fs.readFileSync('./index.html', 'utf8');
    res.end(output);
});
// run on port 8080
server.listen(8080);
 
// listen to the server
var socket = io.listen(server);
// on a connection, do stuff
socket.on('connection', function(client){
        // broadcast the connection
	client.broadcast({message: client.sessionId + ' is now available'});
        // when the server gets a message, during a connection, broadcast the message
	client.on('message', function(msg){ client.broadcast({ message: client.sessionId + ': ' + msg.message }); });
        // when the server gets a disconnect, during a connection, broadcast the disconnection
	client.on('disconnect', function(){ client.broadcast({ message: client.sessionId + ' is no longer available' }); });
});

HTML Code

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Chatroom</title>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
  <script src="http://127.0.0.1:8080/socket.io/socket.io.js"></script> 
  <script> 
    // make a connection to the server
    var socket = new io.Socket('127.0.0.1', {port:8080, connectTimeout:3000});
    // make a message buffer in case things get congested
    var buffer = [];
    socket.connect();
 
    socket.on('connection', function(client){
          // on connection, send the buffer and tell broadcast, to the server, the connection
  	  client.send({buffer: buffer});
  	  client.broadcast({ announcement: client.sessionId + ' connected' });
    });
 
    socket.on('connect_failed', function(){
          alert('The connection to the server failed.');
    });
 
    socket.on('message', function(message){
          // when the client gets a message from the server, 
          // add it to the buffer and display the message
  	  buffer.push(message);
  	  if(buffer.length > 15)
  		  buffer.shift();	  
  	  appendMessage(message.message);
    });
 
    socket.on('disconnect', function(client){ 
      // on disconnect, broadcast it to the server
      client.broadcast({ announcement: client.sessionId + ' disconnected' });
    });
 
    // send a message to the server
    function sendMessage(message){
  	  if(!message){
                // get the message from the input field
  	  	var msg = $("input#message").val(); 
  	  	$("input#message").val('');
  	  } else {
  		var msg = message; 
  	  }
  	  if(msg.length > 0){ // stop annoying empty messages
  	  	if(socket.send({message:msg})) // send the message
      	  	    appendMessage('You: ' + msg); // show the message
  	  }
    }
 
    // show the message on the screen
    function appendMessage(message){
  	  $('div#chat-box').append('<div class="msg">' + message + '</div>'); 
    }
  </script> 
</head>
<body>
<div id="chat-box"></div>
<div id="chat-field">
  <form method="post" action="" onsubmit="return false;" />
    <input type="text" name="message" id="message" value="" /><input id="client" name="client" value="" type="hidden" /><input type="submit" class="button" name="send" id="send" value="Send" onclick="sendMessage();" />
  </form>
</div>
</body>
</html>

Save the Node.js code as chatroom.js or something and the HTML as index.html. Start node on chatroom.js (execute node chatroom.js on the CLI). Fire up your browser and view 127.0.0.1:8080. Open up another tab and go to the same address to start talking to yourself. You can also put the script on a public IP and have your friends connect to it.

Enjoy!

Posted in Internet, JavaScript, Node.js / Socket.io | Tagged , , | 3 Comments

How To Measure Any Distance With The Pythagorean Theorem

We’ve underestimated the Pythagorean theorem all along. It’s not about triangles; it can apply to any shape. It’s not about a, b and c; it applies to any formula with a squared term.

It’s not about distance in the sense of walking diagonally across a room. It’s about any distance, like the “distance” between our movie preferences or colors.

If it can be measured, it can be compared with the Pythagorean Theorem. Let’s see why.

Posted in Mathmatics, Patterns | Tagged | Leave a comment