spechal.com | [spesh-uhl]

Archive for November 2009

127 views
Nov/09

17

Python Abstract Box Art using PyGame

#
#   Abstract Random Box Art
#   Copyright 2009 Travis Crowder
#   travis.crowder@spechal.com
#   Published under the MIT License
#
import pygame, sys, random
from pygame.color import THECOLORS

pygame.init()

screen = pygame.display.set_mode([640,480])
screen.fill([0,0,0])

for i in range(1, 100):
    width = random.randint(0, 250)
    height = random.randint(0, 250)
    top = random.randint(5, 435)
    left = random.randint(5, 375)
    color_name = random.choice(THECOLORS.keys())
    color = THECOLORS[color_name]
    line_width = random.randint(1,3)
    pygame.draw.rect(screen, color, [left, top, width, height], line_width)
pygame.display.flip()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

, ,

375 views

Google and it’s record breaking industrial complex within the search engine world, has broken many barriers by creating interesting new products which fans go mad about. They first exploded with the search engine in 1998, and since then have not only become a giant worldwide in just indexing, but a well oiled machine in the software world as well.

Google has broken walls and created a foundation with it’s innovations, allowing itself to not only become number one in the search category, but one of the best email services available, with Gmail. They since developed “Gears”, which is an “active” production wheel of services that keep Google products adapting to your operating system.

Some knew this was a prequel to the future, and their beliefs were proven true when Google unveiled the mighty Google Chrome browser, which has become a powerhouse in competing with the number one ranked Mozilla Firefox, and the original Internet Explorer from Microsoft.

Google did not stop there. Google for the last year, have been implementing “Android” Google based “mobile operating systems” into cell phones, and have claimed a huge amount of market share in the ever growing handheld/mobile industry. Google had claimed it’s throne as the “king of kings” in the online and multimedia categories.

Google though, had been planning something greater, the highly anticipated Google operating system for personal computers, which has still yet to reach the markets. It promised a linux-based engine, which would of course slaughter Microsoft Windows in performance. That day of reckoning is near, where as next week the Google OS will finally be revealed. Google busts out yet again, with a new force, but none are sure of how compatible it will be.

None the less, this new OS, will be another breakthrough for the powerhouse ran by Eric Schmidt, which many expect to be a huge success. Although there are doubters, many claim that drivers necessary for a smooth running platform OS will not be available immediately. Only time will tell.

The code-named “Chrome OS” is slated for the first public release next week, even though some analysts claim it will be pushed back. The future succession of the OS is yet to be seen, as Linux based operating systems and open source platforms have been available for a very long time, free of charge, and have yet to hold a firm grip upon the market.

Microsoft dominates, clearly in the world of operating systems, but, another brand of competition, let alone a financial giant such as Google, could prove to be a challenge for Microsoft. We shall all see soon.

By:
xxxOBSCENExxx
November 13th, 2009
extratorrent.com

418 views
Nov/09

16

Python Temperature Converter (F to C)

#
# Convert Fahrenheit to Centigrade
# Copyright 2009 Travis Crowder
# travis.crowder@spechal.com
# Published under the MIT License
#
degrees = input("Enter the temperature in Fahrenheit to convert: ");
print degrees, "Fahrenheit is", (degrees - 32.0) * 5/9, "Centigrade"

160 views
Nov/09

16

Python Guessing Game

#
#  Guessing Game
#  Copyright 2009 Travis Crowder
#  travis.crowder@spechal.com
#  Published under the MIT License
#
import random

secret = random.randint(1,100)
guess = 0
guesses = 0

print "Guess the secret number between 1 and 100!"

while guess != secret:
    guesses = guesses + 1
    guess = input("Enter your guess: ")
    if guess > secret:
        print "Your guess is too high.  Try again!"
    elif guess < secret:
        print "Your guess is too low.  Try again!"
    else:
        print "You guessed the secret in", guesses, "guesses!  It was", secret

377 views
Nov/09

16

C++ Read from a file using fstream

/**
  Read from a file (version 1)
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/
#include <iostream>
#include <fstream>
#include <string>

int main(int argc, char* argv[]){

  // create the file handle, opening the file
  std::fstream myFile("text.txt", std::ios::in);

  // create a string to hold the line
  std::string line;

  if(myFile.is_open()){
    while(!myFile.eof()){
      getline(myFile, line);
      std::cout << line << std::endl;
    }
  } else {
    std::cout << "Could not open text.txt for reading." << std::endl;
    return -1;
  }

  return 0;
}

232 views
Nov/09

16

C++ Write to a file using fstream

/**
  Write to a file (version 1)
  Copyright 2009 Travis Crowder
  travis.crowder@spechal.com
  Published under the MIT License
*/
#include <iostream>
#include <fstream>

int main(int argc, char* argv[]){

  // create the file handle, opening the file as well
  std::fstream myFile("text.txt", std::ios::out);

  if(myFile.is_open()){
    myFile << "I am just some text in some file.";
    myFile.close();
    std::cout << "File written to." << std::endl;
  } else {
    // could not create/write to file
    std::cout << "Could not write to file." << std::endl;
    return -1;
  }

  return 0;
}

No tags

505 views
Nov/09

16

PHP Registry Pattern Class for PHP5

The following class is used as a registry to hold elements. Usage is as follows:

$registry = Registry::getInstance();
$registry->set('key', 'value');
echo $registry->get('key'); //prints value
<?php
  /**
   * PHP5 Registry Class
   *
   * @package Registry
   * @author Travis Crowder <travis.crowder@spechal.com>
   * @see MIT License
   * @copyright Travis Crowder
   */

  /**
   *  Registry
   *
   *  The Registry class is used to store values in a global fashion
   *  @final
   *  @see ArrayObject
   */
  final class Registry extends ArrayObject {

    /**
     * Instance object
     *
     * @staticvar object Registry
     */
    static private $_instance = NULL;

    /**
     *  @access private
     *  @var mixed Array to hold the values.
     */
    private $_registry;

    /**
     * Using Singleton pattern with public constructor due to parent class
     *
     * @access public
     * @return void
     */
    public function __construct($array = array(), $flags = parent::ARRAY_AS_PROPS){
      parent::__construct($array, $flags);
    }

    /**
     * Singleton accessor to the object
     *
     * @access public
     * @return Registry $instance Instance of the object
     */
    static public function getInstance(){
      if(self::$_instance === NULL){
        self::$_instance = new Registry;
      }
      return self::$_instance;
    }

    /**
     *  Get method
     *
     *  @access public
     *  @return mixed Element in the registry
     */
    static public function get($key){
      $instance = self::getInstance();
      if(!$instance->checkOffset($key))
        return false; #throw new Exception($key . ' is not set in the registry');
      return $instance->returnOffset($key);
    }

    /**
     *  Set method
     *
     *  Accessor method used to set a value to a registry key.
     *  @access public
     *  @static
     *  @return void
     */
    static public function set($key, $value){
      $instance = self::getInstance();
      $instance->setOffset($key, $value);
    }

    /**
     *  Method to set ArrayObject offset
     *
     *  This method sets the ArrayObjects value
     *  @access protected
     *  @return void
     */
    protected function setOffset($key, $value){
      $this->_registry[$key] = $value;
    }

    /**
     *  Check ArrayObject offset
     *
     *  Method to check if an ArrayObject Registry index has a value.
     *  @param string $key Index of Registry to access
     *  @access protected
     *  @return bool
     */
    protected function checkOffset($key){
      if(isset($this->_registry[$key]))
        return true;

      return false;
    }

    /**
     *  Return method
     *
     *  Method to return the value of a Registry index
     *  @access protected
     *  @return mixed Value of Registry index.
     */
    protected function returnOffset($key){
      return $this->_registry[$key];
    }

    /**
     *  Dump method
     *
     *  Method to dump the contents of the Registry to the screen via print_r
     *  @access public
     *  @return void
     */
    public function dump(){
      print_r($this->_registry);
    }

  }

No tags

416 views
Nov/09

16

C++ Palindrome Checker

/**
  Palindrome Checker
  Copyright 2009 Travis Crowder
  Published under the MIT License
*/

#include <iostream>
#include <algorithm>
#include <string>

bool isPalindrome(const std::string theWord);

int main(int argc, char* argv[]){

  std::string theWord;

  if(!argv[1]){
    std::cout << "Enter the word to check: ";
    std::cin >> theWord;
  } else {
    theWord = argv[1];
  }
  std::cout << std::endl;

  /**
    Make all of the characters lower case
  */
  int i = 0;
  while(theWord[i]){
    if(isupper(theWord[i]))
      theWord[i] = tolower(theWord[i]);
    i++;
  }

  std::cout << theWord << " is ";
  if(!isPalindrome(theWord))
    std::cout << "NOT ";
  std::cout << "a palindrome." << std::endl;
  return 0;
}

bool isPalindrome(const std::string theWord){
  std::string tmp = theWord;
  reverse(tmp.begin(), tmp.end());
  if(tmp == theWord)
    return true;
  return false;
}

247 views
/**
   *  Function to validate a generated GUID / UUID
   *  @param string $guid GUID
   *  @return bool
   */
  function validGUID($guid){
    return preg_match('#^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$#', $guid);
  }

,

855 views
Nov/09

15

PHP function to emulate MySQL UUID

/**
   *  uuid
   *
   *  uuid() simply replicates MySQL's UUID function, which returns a 36
   *  character "random" hash (32 alphanumeric, 4 dashes).
   *  @return string
   */
  function uuid(){
    return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
      mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
      mt_rand(0, 0x0fff) | 0x4000,
      mt_rand(0, 0x3fff) | 0x8000,
      mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
  }

,

<< Latest posts

Older posts >>

Find it!

Theme Design by devolux.org