Add Scroogle to your search area in Firefox 2.0 Install the 'Scroogle Scraper' search plugin.

Imagine you have a set of cards. On one side of each card is a letter and on the reverse side of each is a number. You lay down four such cards:
A F 2 7

Your task is to determine which cards you must flip over in order to show that the following statement holds true: “If there is a vowel on one side of the card, there is an even number on the other side.”

This nagiosified Bash script sends a JSON payload to a webservice and parses the output for an expected string:

[root@server apitest]# ./webservice_check.sh
Usage: ./webservice_check.sh [API_NAME]
[root@server apitest]# ./webservice_check.sh service1
OK - service1 API working
[root@server apitest]# cat webservice_check.sh
#!/bin/bash
 
if [ $# -ne 1 ]; then
        echo "Usage: $0 [API_NAME]"
        exit
fi
E_SUCCESS="0"
E_CRITICAL="2"
case "$1" in
'service1')
API_NAME="service1"
URL="https://******.example.com/api"
JSONPAYLOAD='{"auth": {"type" : "basic","password": "******","username": "******"},"requestId" : 15,"method": {"name": "service1"}}'
COMMAND_STRING="curl -s -H \"Content-type: application/json; charset=UTF-8\" --data '$JSONPAYLOAD' $URL 2>/dev/null"
OUTPUT=`eval $COMMAND_STRING`
EXPECTED_RESULT="result"
;;
*)
echo "INVALID API Argument"
exit 1
esac
 
if grep -q "$EXPECTED_RESULT" <<< $OUTPUT; then
        echo "OK - $API_NAME API working"
        exit ${E_SUCCESS}
        else
        echo "CRITICAL - $API_NAME API not working"
        exit ${E_CRITICAL}
fi

Maybe you have the selenium firefox plugin and you’ve recorded some web tests and exported them in phpunit format and you’re running them against, say firefox. then you realize that launching a browser is not a fast thing to do. with firefox, you have to create a separate profile, disable plugins/update checks, and you’re severely limited to the number of simultaneous tests you can run.

then you hear of phantomjs, which encapsulates webkit (used in safari and chrome) and you decide it would be a LOT faster to use phantomjs instead of firefox. fortunately there is ghostdriver which is the glue for this. Here, below, I assume you’ve got selenium, phantomjs, ghostdriver, phpunit and PHPUnit_Selenium.

1. start selenium in hub mode: java -jar selenium-server-standalone-2.25.0.jar -role hub

2. register phantomjs with selenium: phantomjs –webdriver=8080 –webdriver-selenium-grid-hub=http://127.0.0.1:4444

3. use this code (which uses PHPUnit_Extensions_Selenium2TestCase not PHPUnit_Extensions_SeleniumTestCase):

require_once 'PHPUnit/Autoload.php';
 
class CDemoLoginTest extends PHPUnit_Extensions_Selenium2TestCase {
 
	protected function setUp() {
		$this->setBrowser( 'phantomjs' );
		$this->setBrowserUrl( 'http://www.example.com/' );
	}
 
  	public function testLogin() {  		
	    $cookies=$this->cookie();
	    $cookies->clear();
	    $this->url('http://www.example.com' );	    
	    $this->assertEquals( 'page title', $this->title() );
	    //echo($this->source());
	    $company_user = $this->byId('username');
	    $company_user->value('aUser' );
	    $password = $this->byId('password');
	    $password->value('aPassword' );	
	    $login=$this->byId('Login');
	    $login->click();    
	    $this->assertEquals( 'web portal', $this->title() );	    
	    $userLink=$this->byLinkText('logout' ); 
            $userLink->click();
	    $this->assertEquals( 'page title', $this->title() );
	}
}

4. run phpunit on it:

[root@server phantomtest]# phpunit --verbose CDemoLoginTest.class.php
PHPUnit 3.7.21 by Sebastian Bergmann.
 
.
 
Time: 4 seconds, Memory: 3.00Mb
 
OK (1 test, 3 assertions)
[root@server phantomtest]#

Note: PHPUnit_Extensions_Selenium2TestCase is newer and you can read about it here:

https://github.com/giorgiosironi/phpunit-selenium/blob/master/Tests/Selenium2TestCaseTest.php

https://github.com/sebastianbergmann/phpunit-selenium/blob/master/PHPUnit/Extensions/Selenium2TestCase.php

Screen Shot 2013-05-10 at 1.19.53 PMMaybe you’re giving a presentation and you’d like a quick “text your vote to this number” real-time poll. Maybe you don’t want to pay the commercial services out there and you have access to a php/mysql server. Here, below, below is some code to make your free poll become a reality. It’s based on this other open source text to vote system: https://github.com/rahims/Text-to-Vote and http://www.twilio.com/blog/2011/05/how-to-create-a-simple-sms-voting-system-using-php.html but instead of sqlite, my version uses MySQL:
handle_incoming_sms.php

<?php
	header('Content-type: text/xml');
	echo '<Response>';
	$phone_number = $_REQUEST['From'];
	$team_number = (int) $_REQUEST['Body'];
 
	if ( (strlen($phone_number) >= 10) && ($team_number > 0) )
	{
            $db=mysql_connect("localhost","user","pass");
            mysql_selectdb("database",$db);
            if (!$db)
            {
              echo "Failed to connect to MySQL: " . mysqli_connect_error();
            }
            $phone_number = mysql_real_escape_string($_REQUEST['From']);
            $team_number = mysql_real_escape_string($_REQUEST['Body']);
            $sql="insert into table set phone='".$phone_number."', team='".$team_number."'";
            $result=mysql_query($sql,$db);
            if (!$result) 
            {
   	        die('Invalid query: ' . mysql_error());
            }
	}
	else 
        {
		$response = 'Sorry, I didn\'t understand that. Text the team number to vote. For example, texting 1 will vote for Team 1.';
	}
 
	echo '<Sms>'.$response.'</Sms>';
	echo '</Response>';
?>

cat get_votes.php

<?php
     $db=mysql_connect("localhost","user","pass");
     mysql_selectdb("database",$db);
 
if (!$db)
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
 
$sql="SELECT COUNT(CASE WHEN team = '1' THEN 1 ELSE NULL END) AS team1,
COUNT(CASE WHEN team = '2' THEN 1 ELSE NULL END) AS team2,
COUNT(CASE WHEN team = '3' THEN 1 ELSE NULL END) AS team3
FROM table";
$result=mysql_query($sql,$db);
                if (!$result)
                {
                         die('Invalid query: ' . mysql_error());
                }
$row = mysql_fetch_assoc($result);
$team1= $row['team1'];
$team2= $row['team2'];
$team3= $row['team3'];
$votes=array((int)$team1, (int)$team2, (int)$team3);
	echo json_encode($votes);
?>

elevatorDetractors of lateral/logic thinking puzzles for interview questions protest that the questions do not serve the purpose of the interview, which is ostensibly to identify those candidates who are likely to be valuable employees. “Some people aren’t good at puzzles!” or “They’ll just Google the answers beforehand and parrot them back to you!”

Others dislike difficult programming challenges in interviews, saying the problems do not reflect the type of real world problems one is likely to face. Who cares if I can find the longest string of increasing integers in a three dimensional array? What does that have to do with apartment management software?

Still more believe that the questions should focus on design skills rather than algorithmic prowess, “you can always Google the algorithm.”

It is with those objections that I present the Elevator Interview Question. It’s not new and generally goes something like, “Design a basic set of objects/methods to be used to simulate an elevator bank. What are the objects and their attributes/methods?”

Being able to show the Object Oriented design for an elevator bank in pseudo-code should satisfy those who demand good design. The follow up questions though, I feel are a combination of algorithmic and lateral thinking which could help spotlight those who are capable of deeply considering a problem.

  • How do you optimize the elevator system for availability?
  • How would variation of traffic over a typical work week, floor, or time of day affect this?
  • How would you test this optimization system?
  • What would be the effect of replacing the “up” and “down” buttons outside the elevator with floor buttons and removing the floor buttons in the elevators?
  • One elevator design has no doors (Paternoster) and constantly move either up or down. Is this a good idea?
  • How might technology help with the optimization (RFID tags on people), people counters outside of elevators?

What other follow up questions make the Elevator Design Dilemma an optimal interview question?

http://en.wikipedia.org/wiki/Elevator#Destination_control_system

http://www.reddit.com/r/compsci/comments/1at0zj/elevator_algorithm_questions/

http://dan-nolan.com/how-i-would-optimize-the-elevators-in-our-office-building/

http://www.angelfire.com/trek/software/elevator.html

http://www.acetheinterview.com/questions/guide_excerpts.pdf

http://danielparejaortiz.es/ascensores/documentos/dynamic%20optimization%20-%20I.pdf

http://codereview.stackexchange.com/questions/5723/c-code-for-oop-elevator-design-evaluation

http://www.cs.cmu.edu/~luluo/Courses/18540PhDreport.pdf

What do you do when you need a file from a remote linux server and that server has libcrypto and libssl messed up? Also, ftp client isn’t installed. Also, they don’t want you to install anything. also the file you need is very large?

ssh user@remotehost.example.com "cat somebigfile.tgz" > localcopyoffile.tgz

That’s it. As it turns out,

cp a b

is (for most purposes) equivalent to

cat a>b

Now you know. knowing is 1/2 the battle.

Once you have more than a few servers, you’ll find that you have lots of log files from things like apache, your dbms, java, etc. You’ll also find that when something goes wrong it’s very useful to be able to correlate those different logs. That means a centralized logging solution. (Open Source Splunk)

That’s where Splunk (http://www.splunk.com/) comes in. With Splunk, you ship your logs to a central server and it indexes those logs and allows you to search them in a sexy interface. Spunk is awesome. It’s also awesomely expensive. They charge you by the bandwidth of logs coming into the central server and it adds up very fast. Expect to spend many thousands of dollars, even for a couple of dozen servers per year. What’s worse, if your application gets suddenly log-chatty, or if someone DDOSs you, your Splunk will shutdown until you pay up to Splunk and they unlock it for you.

Fortunately there is the open source community. They’ve come out with some amazing tools that beat not only the functionality of Splunk, but it’s sweet user interface too.

  1. logstash for routing and mangling logs: logstash.net
  2. elasticsearch for log indexing: www.elasticsearch.org
  3. kibana as a query interface for elasticsearch logs: kibana.org

Other related reading:

  1. http://www.vmdoh.com/blog/centralizing-logs-lumberjack-logstash-and-elasticsearch
  2. http://logstash.net/docs/1.1.0/filters/grok
  3. http://www.youtube.com/watch?feature=player_embedded&v=RuUFnog29M4#!

Thanks Z, from that LMS organization!

Yahoo has been struggling to regain significance in the IT world. Unfortunately for them, the recent announcement by their CEO (Marissa Mayer) to end telecommuting is likely another step towards their ultimate irrelevance. Is Yahoo the new MySpace?

Mayer contends you have to be physically in the office to be productive. She says there are too many distractions at home. I think she is missing the mark here.

The world is full of talent and it’s costly to relocate them. To compete today, you have to pull from this world-wide talent pool and that means allowing remote workers, at least some of the time. As well, I have found that many computer programmers are SIGNIFICANTLY more productive at home than in the office.

Here are the telecommuting benefits that Mayer seems to have overlooked:

  • Increases Productivity “in the zone”
  • Boosts Morale, increases retention, reduces stress
  • Forces use of efficient technology
  • Better tracks productivity and results
  • Sick? Stay home & work!
  • 1-2 hours extra work each day
  • More ecofriendly

What would happen if 40% of the US work force worked from home 1/2 of the time? Fortunately, there’s a study for that:

  • $200 billion productivity gains
  • $190 billion savings from reduced real estate expenses, electricity bills, absenteeism, and employee turnover
  • 100 hours per person not spent commuting
  • 50 million tons of greenhouse gas emissions cut
  • 276 million barrels of oil saved, or roughly 32 percent of oil imports from the middle east
  • 1,500 lives not lost in car accidents
  • $700 billion total estimated savings to American businesses

src:http://www.inc.com/magazine/20100401/telecommuting-by-the-numbers.html

Way to Go, Marissa Mayer.

For those companies who want to succeed, here’s how you implement telecommuting at your organization:

  1. Define specific accountability measures: (e.g. Tickets closed, tasks completed, availability, Scrum story points, etc.)
  2. Put it on trial: Pick a day (Wednesdays are good)
  3. Measure, Evaluate, Decide

When’s the last time you used a Yahoo product?

photo(1)

Adafruit’s $39.00 eTape Liquid Level Sensor is a solid-state sensor with a resistive output that varies with the level of the fluid. The eTape sensor’s envelope is compressed by the hydrostatic pressure of the fluid in which it is immersed. This results in a change in resistance that corresponds to the distance from the top of the sensor to the surface of the fluid. The sensor’s resistive output is inversely proportional to the height of the liquid: the lower the liquid level, the higher the output resistance; the higher the liquid level, the lower the output resistance.

#define SERIESRESISTOR 560
    // What pin to connect the sensor to
    #define NUMSAMPLES 15    
    int samples[NUMSAMPLES];
    #define SENSORPIN A0
    #define FLAP 1
    #define FUDGE 0.3
    void setup(void) {
    Serial.begin(9600);
    analogReference(EXTERNAL);
    }
 
    void loop(void) {    
     uint8_t i;
     float average;
     float waterlevel;
     float lastwaterlevel=0;
    // take N samples in a row, with a slight delay
    for (i=0; i< NUMSAMPLES; i++) {
    samples[i] = analogRead(SENSORPIN);
    delay(10);
    }
    // average all the samples out
    average = 0;
    for (i=0; i< NUMSAMPLES; i++) {
    average += samples[i];
    }
    average /= NUMSAMPLES;
    //Serial.print("Average analog reading ");
    //Serial.println(average);
    // convert the value to resistance
    average = 1023 / average - 1;
    average = SERIESRESISTOR / average;
    //Serial.print("Sensor resistance ");
    //Serial.println(average);
    waterlevel = 0;
    waterlevel= -1 * 0.006958 * average + 11.506958+ FUDGE;
    if (lastwaterlevel<(waterlevel-FLAP)||lastwaterlevel>(waterlevel+FLAP))
    {
        Serial.print("Water level (inches) ");
        Serial.println(waterlevel);
    }
    delay(1000);
    lastwaterlevel=waterlevel;
    }

The wiring is pretty simple: the sensor comes with a 560 ohm resistor. the sensors two middle pins (2&3) are where the action is at. pin 2 goes to gnd. pin 3 goes to one side of the 560 resistor and to analog input 0. the other side of the resistor goes to 3.3v and to aref.

photo(2)
water_sensor_graphScreen Shot 2013-02-22 at 2.08.38 PM

cnnSelenium can take screenshots, but it does it by launching a browser. What if you need a screenshot of a website, but don’t want the overhead of a browser launching?

That’s where phantomjs comes in. First, install it (CentOS directions):

yum install qt47-devel qt47-webkit qt47-webkit-devel sqlite-devel
yum install xorg-x11-server-Xvfb
yum install xorg-x11-server-Xorg
yum install xorg-x11-fonts*
chmod +x /etc/init.d/Xvfb
/etc/init.d/Xvfb start
git clone git://github.com/ariya/phantomjs.git
cd phantomjs/
git checkout 1.6
./build.sh

Next, create a short js file and pass it to phantomjs!

[user@server ~]# cat cnn.js 
var page = require('webpage').create();
page.open('http://www.cnn.com', function () {
        page.render('cnn.png');
    phantom.exit();
});
[user@server ~]# phantomjs google.js

WHAMMO! you now have a webkit rendered cnn.png ready in half a second!

Next Page »

Send to a friend * Print this page * Join the club * Talk with my robot * Advertise here * Search this Site * Donate * Link to me


Web hosting by Utah Hub *  Powered by CreativeTap *  In association with Segomo
Unless otherwise noted, Copyright 2004-2013, Ryan Byrd. All Rights Reserved.
Ryan Byrd dot net -- probably the coolest site in Utah