0

Shell :: Simple Apache Pig Identification

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
#apachepig.sh
#simple script for identifying shared hosting pigs on a small server
#only definitive for a forking server, threading would need modification
#should be enhanced for polling, but useful for processes that are hung
#which is what we are looking for right?
 
ARGS=("$@")
 
#GLOBALS
WEBROOT=/home
DAEMONNAME=apache2
 
#ARGS
ACTION=${ARGS[0]}
#add single PID functionality later
PID=${ARGS[1]}
 
case $ACTION in
	mem)
		PROCESSES=$(top -b -n1 | grep $DAEMONNAME | sort -r -k 6)
	;;
	cpu)
		PROCESSES=$(top -b -n1 | grep $DAEMONNAME | sort -r -k 5)
	;;
	time)
		PROCESSES=$(top -b -n1 | grep $DAEMONNAME | sort -r -k 7)
	;;
	*)
		echo "operation not supported"
	;;
esac
 
IFS=$'\n'
for x in $PROCESSES; do
	echo "$x"
	PID=$(echo $x | awk '{print $1}')
	OUTPUT=$(lsof -w -p $PID | grep "$WEBROOT")
	if [ $OUTPUT ]; then
		echo $OUTPUT
	else
		echo 'NO PIGS'
	fi	
	echo " "
done

Read More

0

Shell :: simple MySQL DB provisioning

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#provmysqldb.sh
 
ARGS=("$@")
 
#GLOBALS
MYSQLHOST=your.server.name
MYSQLPASS=yourpass
 
#ARGS
ACTION=${ARGS[0]}
USER=${ARGS[1]}
#maybe we want to split this out later
DB=${ARGS[1]}
 
if [[ $ACTION && $USER && $DB ]]; then
	case $ACTION in
		create)
			#check to see if db exists
			echo "use ${DB}" | mysql -s -h $MYSQLHOST -u root -p$MYSQLPASS 2> /dev/null
 
			if [ $? -ne 0 ]; then
				echo -n 'enter password: '
				read PASS
 
				OP="
				create database ${DB};
				create user '${USER}'@'%' identified by '${PASS}';
				grant all ON ${DB}.* to '${USER}'@'%';
				flush privileges;"
			else
				echo "The database/user: ${DB} already exists"
			fi
			;;
		delete)
			#check to see if db exists
			echo "use ${DB}" | mysql -h $MYSQLHOST -u root -p$MYSQLPASS 2> /dev/null
 
			if [ $? -eq 0 ]; then
				OP="
				drop database ${DB};
				drop user '${USER}'@'%';
				flush privileges;"
			else
				echo "The database/user: ${DB} doesn't exist"
			fi
			;;
		*)
			echo 'Operation not supported'
			;;
	esac
 
	if [[ $OP ]]; then
		echo $OP | mysql -h $MYSQLHOST -u root -p$MYSQLPASS 2> /dev/null
		if [ $? -eq 0 ]; then
			echo 'Operation Succeeded!'
		else
			echo 'Operation Failed!'
		fi
	fi
 
 
else
	echo 'USAGE: provmysqldb.sh <action:create|delete> <dbname>'
fi

Read More

1

Love the Cloud :: More new companies

Linode
A Xen VPS hosting company.
According to these benchmarks they have the best Xen VPS performance so far.

Heroku
A ruby app hosting company with a slick API and a fully managed stack. I love their web design too!

Read More

0

IPS/pkg :: A business friendly software distribution and packaging system

I just noticed this change to pkg in OpenSolaris. These functionality additions allow for the conditional display and acceptance of software licenses on package install for the IPS system.

Why is this significant? Because it opens up the package system for commercial software distributors. If you couple this with the IPS repository functionality and require keys for the repo you have subscription updates, and license management covered!

Your software purchase and install path looks like:

Go to web site -> do they support opensolaris -> yes -> buy -> add repo -> pkg install software

Update your software from now until forever:

pkg install software or

pkg image-update

I really don’t like having to run custom installers from vendors that run scripts that do all kinds of stuff to the system and also install package sets. If the software packaging system is opened up to vendors we can manage our open source and commercial applications from one place.

I would also like to see open source projects build their own package repositories for all the major distributions. This would allow us to stay current with some software packages who’s development out paces the release cycles of the enterprise distros (RHEL, Ubuntu LTS).

Read More

2

Bash :: Extension change script

A simple script to recursively change filename extensions (case insensitive)

#!/bin/bash
#chext.sh
 
ARGS=("$@")
 
if [[ -d ${ARGS[0]} && ${ARGS[1]} && ${ARGS[2]} ]]; then
        for x in $(find ${ARGS[0]} -name "*.${ARGS[1]}"); do
                y=$(echo $x | sed "s/\.${ARGS[1]}\$/\.${ARGS[2]}/i")
                mv $x $y
                echo "$x -&gt; $y"
        done
else
        echo 'USAGE: chext.sh'
fi

Read More

0

Elementary Algorithms :: Array Difference

UPDATED

In an interview I was posed a problem: given 2 arrays a and b write a program that will print the elements of a that are not in b.

The easiest (incorrect solution) in PHP:

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/php
<?
$a = array(1, 2, 3, 4, 9, 20, 30, 82, 57);
$b = array(1, 2, 3, 82, 57, 100, 32);
 
$c = array();
foreach($a as $aval) {
	if(!in_array($aval, $b)) $c[] = $aval;
}
 
print_r($c);
 
?>

Now as I had stated in the interview this is NOT the best way to accomplish this. Of course that would all depend on how in_array is implemented in PHP. If in_array is simply a short cut to a true false foreach loop then we have a problem. If n and m represent the number of elements of a and b respectively iterations = n * m. Or O(mn). Not efficient. Since this is PHP I am guessing this is the case (a simple sequential search).

So what is a better solution (best?) to allow for better performance as n and m increase? This is the best I could come up with after a quick look at a couple of algorithms.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/php
<?
$a = array(3, 1, 2, 4, 9, 20, 30, 82, 57);
$b = array(1, 2, 3, 82, 57, 100, 32);
 
//binary search function
function binSearch($ar, $n, $value) {
	$l = 0;
	$r = $n;
	while($r >= $l) {
		$mid = ($l + $r)/2;
		if($ar[$mid] == $value) {
			return true;
		} else if ($ar[$mid]< $value) {
			$l = $mid + 1;
		} else {
			$r = $mid - 1;
		}
	}
 
	return false;
}
 
//sort the first array used in the bin search
sort($b);
$n = count($b);
$m = count($a);
$c = array();
for($i=0;$i<$m;$i++) {
	if(!binSearch($b, $n, $a[$i])) {
		$c[] = $a[$i];
	} 
}
 
print_r($c);
 
?>

Removing the negation operator prior to the function call will change the program to array intersection vs array diff. The math for this binary search solution is O(m log2 n).

So consider the following:
m = 8
n = 8

Solution 1:
(mn) = 64

Solution 2:
16*log2(8) = 48

Basically due to the first array being sorted and chunking we are able to do fewer comparisons instead of a comparison for each element. As the size of the chunk decreases the worst case is that the value doesn’t exist.

It also occurs to me that you will want to count each array and sort the shortest and use that as the first argument and the longer array[val] as the second to further reduce the number of iterations. Of course the order of the arguments matters for this problem (in a not in b). I suppose you could flip flop logic/operator in/on the binary search call/function though to account for that as well.

Anyway this is basic CS, everyone probably knows this but I couldn’t come up with it off the top of my head, and the problem was driving me nuts cycling in the back of my mind so I had to write it out.

UPDATE
I still kept thinking about this so here is another based on array merge and comparing next array elements. Since this is a diff and not an intersection we need to merge the first array twice. Any value that shows up twice in the merged array is in a and not in b.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/php
<?
$a = array(3, 1, 2, 4, 9, 20, 30, 82, 57);
$b = array(1, 2, 3, 82, 57, 100, 32);
 
$c = array_merge($a, $b);
$c = array_merge($a, $c);
$d = array();
sort($c);
 
 
$i = 0;
 
while($i <= count($c)) {
 
	if($c[$i+1] == $c[$i] && $c[$i+2] == $c[$i]) { 
		$i+=3;
	} else if ($c[$i+1] == $c[$i]) {
		$d[] = $c[$i];
		$i+=2;
	} else {
		$i++;
	}
}
 
print_r($d);
?>

The math ends up being something like ~O(m + m + n).

Read More

0

Virtual Worlds :: Web 3.0

Back in the day

Today I was remembering back to the mid to late 90s when the VR craze was all the rage on the fledgling Internet. People were going nuts over giant head mounted displays (yeah you couldn’t hold your bloody head up wearing one), and crappy spacial interfaces utilizing hacked up Nintendo power gloves. Don’t even start with the graphics, low polygon count multi colored tron like landscapes were the best that were managed. Affordable 3D hardware was still out of reach of the average individual, and would be until Nvidia took on SGI in the courtroom.

So here we are 13+ years later, still surfing the web utilizing the same keyboard and mouse, still consuming all of our Internet and game content by staring at a monitor (although at least now they are flat). Why? What is the story? The average American internet user has access to ridiculous amounts of compute power and yet the 3D immersive future of the net still eludes us.

So what do we have?

The 3D hardware and rendering engines are here. The physics engines are here. The hardware to run the software is already in consumer hands. The bandwidth and technology to distribute 3D assets is widely available. There are also some viable light weight head mounted displays in the $300 price range on the market.

If you look at what has been accomplished by companies like Bioware, Blizzard Entertainment, and id software you will recognize that the visual aspect of immersive virtual environments is good to go.

So what are we missing?

It’s the interface dummy!

As of yet all the slick new 3D games and environments are designed for the keyboard and mouse, and rightly so! You have to design the game for the target market and all computer users have a keyboard and mouse. Sadly, until a modern 3D + headmounted display and gesture driven interface is a standard feature this will most likely continue to be the case. The tech is there to create it, and the components are affordable it just needs to happen.

An open platform

Probably the number one reason for the fast growth of the web has been the HTTP standard and the open source project the apache httpd web server. In order to make the transition we will need an open world server and a client. Sorry the webGL stuff just doesn’t cut it, and either does HTTP for immersive client interaction. The client and the world server should support plugins so individual operators can add value to their world/service/application. We will also need a full world building suite.

A universal protocol

The net today has become far too complicated in relation to a pretty simple task: data exchange. The world server and client (as well as client to client P2P) should interact with a universal protocol. This protocol should encapsulate the following functionality:

  • Strong identity management/validation/authorization the user/client can opt to give worlds/clients access to certain personal data and or files. These profiles will need to be manageable, and the data sets and data types extensible. Worlds should also be able to define roles and profiles for users that are consuming them.
  • IM & Voice user to user and user to group instant communication.
  • Mail should be an IM extension for communications that have been missed or not accepted at the time of transmission.
  • File Transfer user to user and user to world file transfer instant or point in time
  • Asset Download extension of file transfer service possibly relying on P2P distribution and download of bits
  • App Services apps delivered via world server with 3D interface

Damn! How long will all that take?

Well the tech is there to do it all, however I don’t think we will see much happen until we have the aforementioned 3D interface. As far as the platform goes I see a lot of toys out there, some have some promise but I really think it is going to take an industry leader or a group of industry leaders to put together the platform and the client and make it available for others to use. I would definitely like to see one standard world server architecture that everyone can build their apps/games/worlds on as opposed to every shop re-implementing their own server and client for every project. The problem is that the business cases are not very strong for doing such a thing. Perhaps lowering the barrier to entry via an asset download vs a full client download and install could enlarge the target market for a given project.


Read More

0

Men, Jewelry, The Chronograph

During the course of a recent social event I was queried as to why I was not wearing a wrist watch. Surely, the young woman had reasoned, such attire would be accompanied by an equally impressive chronograph, and yet my wrist lay unadorned.

My tendency toward minimalism coupled with the advent of the modern pocket size cell phone had helped me along to my current view on the chronograph. I don’t particularly care for jewelry (even though most modern males swim in it) unless it has a function, the cell phone had replaced that function. So what reason for wearing this item, other than the fear of being seen with a nude wrist, can be found? The answer is item bound emotional significance.

Many women associate items of jewelry with special events. The items are as varied as the events. For the male this item has frequently been the chronograph. For me personally the chronograph has been a symbol of love presented to me by the object of that love. With loves passing I have retired that particular piece. Though they have all been quite nice, given what they have represented, I really don’t care to wear any of the retirees. Being that I am not seeing anyone at the moment, this has left me bare wristed for the time being.

Read More

0

Sun Support :: Happiness

Ok, now that I am through the sales process:

Sun support is good. Very, Very good.

Read More

0

Sun :: Support Contract Pricing

Seriously WTF.

My story:

I need a patch for Sun Java Messaging Server, the patch is a private patch, it fixes random crashes by the dispatcher. Basically a very necessary patch in that if the dispatcher crashes you stop receiving mail.

I am trying to get a support contract so I can gain access to sunsolve and get the patch.

This will be day 2 of waiting to hear back from Sun on pricing for this product. NO WONDER SUN IS HAVING FINANCIAL WOES, I AM READY TO SPEND AND NONE OF THE SALES REPS KNOW WTF THE SUPPORT CONTRACT COSTS.

This is why I have used only full and open products in the past. If there is an issue I can find it in an open bug DB, searching sunsolve for patches is just plain crap. I can also attempt to fix the issue myself, I am no C god, but I can and have fixed some pretty complex issues in the past and been up and running again in a day if not hours.

Truly this has been a frustrating process, and I just wish the sales person would call me back and take my money.

Read More