Sunday, May 22, 2011

PHP: getting the users IP address

$_SERVER['REMOTE_ADDR']; 

c++ chomping white space

A Bit of code to chomp strings in c++

#include <string>
#include <iostream>

int main()
{
  std::string str;
  getline(std::cin, str);

  std::cout << "'" << str << "'" << std::endl;
    
  std::string::size_type pos = str.find_last_not_of("\n \t");
  if(pos != std::string::npos) 
  {
    str = str.substr(0, pos+1);
  }
    
  std::cout << "'" << str << "'" << std::endl;
}

Quick way list your LAN machines

Here is a quick way to grab the Ethernet MACs and IPs of the machines that are up on your LAN

arp -a

Suming a list of numbers of the shell

Manipulating lists on the shell can be done with awk. The most common one I encounter is summing numbers. Here is a quick bit of shell magic to sum up the size of all log files below a certian dictionary. Awk has much more power than this however.

find . -type f | grep "\.log" | xargs ls -al | sed "s/  */ /g" | cut -d " " -f 5 | awk -F: '{total+=$1} END{print total}'

Friday, May 6, 2011

Shell repeat/do/while for a count

Gahh.. simple thing but annoying its for bash shell

 i=245; while [ $i -ne 33 ]; do  echo $i; i=`expr $i - 1`; done

Wednesday, April 27, 2011

Earthquakes in japan between

Quick video showing earthquakes in Japan between 9 March and 14 March. 1 hour ~ 1 second. Big one is around 1:17.

Suming a list of numbers

cat numbers.txt | awk -F: '{total+=$1} END{print total}'