PHP Snippet03.08.08

Here is a PHP Snippet I wrote. It’s a cool trick to for calling multiple methods in a much simpler way. Inspired by Ruby’s ActiveRecord.

<?php

interface Member {
	function login($username, $password);
	function update($status);
}

class Base implements Member {
	public function login($username, $password) {
		echo "You will be logged in as: {$username} with Password: {$password}\n";
	}

	public function update($status) {
		echo "Your New Status Message is: {$status}\n";
	}

	public function __call($method, array $argv) {
		if(preg_match('/^do_*/i', $method)) {
			foreach(explode("_and_", substr($method, 3)) as $k => $v) {
				$param = array();
				foreach($argv[$k] as $value) { $param[] = "'{$value}'"; }
				$param = join(", ", $param);
				$code = '$this->'. $v ."({$param});";
				eval($code);
			}
		}
	}
}

class User extends Base {

	public function say_hello($message) {
		echo "Message: {$message} \n";
	}
}

$usr =& new User();

$usr->do_login_and_update(array("username", "password"), array("Hello World"));
# Prints the following:
# You will be logged in as: username with Password: password
# Your New Status Message is: Hello World
#

$usr->do_login_and_say_hello(array("username", "password"), array("Hi how are you?"));
# Prints the following:
# You will be logged in as: username with Password: password
# Message: Hi how are you?
#

$usr->do_login_and_update_and_say_hello(array("username", "password"), array("Hello World"), array("Hi how are you?"));
# Prints the following:
# You will be logged in as: username with Password: password
# Your New Status Message is: Hello World
# Message: Hi how are you?
#

?>

Posted in PHP, Programmingwith No Comments →

Ruby Technique: Meta Programming03.02.08

Meta Programming is code that writes code. See the code sample below.
I have made a screencast of this process. View it here

#!/usr/bin/env ruby

class Product
  def initialize(items)
    items.each {|item| Product.product(item) }
  end

  def self.product(item)
    code = %Q{
      def add_#{item}(item)
        @#{item} = [] unless @#{item}
        @#{item} << item
      end

      def display_#{item}s
        @#{item}.each {|item| puts item }
      end
    }
    class_eval(code)
  end
end

class Item < Product
  def initialize(*items)
    super(items)
  end
end

cart = Item.new(:book, :computer, :music)
cart.add_book(:Ruby) # => Add a book to our cart items

cart.display_books # => We want to display All books we have added
puts "\n"

cart.add_computer(:Apple)
cart.add_computer(:Dell)
cart.add_computer(:Sony)
cart.display_computers # => Display All Computers
puts "\n"

cart.add_music(’Modest Mouse‘)
cart.add_music(’Northstar‘)
cart.display_musics # => Display All Music Items

Posted in Programming, Rubywith No Comments →

Mac vs. PC vs. Linux02.28.08


Posted in Revver, videowith No Comments →

Lastbridge - Add Friends Stations/Playlist02.14.08

lastbridge.net new feature
New Feature out now. Add your last.fm friends radio stations and playlist.

Posted in Last.fm, Projects, Ruby On Rails, lastbridge.netwith 1 Comment →

Terminator: The Sarah Connor Chronicles02.01.08

In the series premiere, Sarah Connor struggles to keep her son John Connor safe from an enemy Terminator from the future.

A must watch show on hulu.com. It’s cool!

Posted in Other, videowith No Comments →

Lastbridge Stations01.24.08

Added Playlist

New Feature for LastBridge.net - I have added a small list of station you can now select.

Of course more new features are planned ahead.

Posted in Programming, Projects, Ruby On Railswith 1 Comment →

Release: LastBridge01.20.08

Screencast Lastbridge

It is official LastBridge.net is out for public consumption! Again for those who are lost and don’t know what this “LastBridge” is it’s for listening to your last.fm radio stream on the Roku SoundBridge.I have made a screencast on How To use LastBridge. If anyone still needs help or just want to leave your opinions on this project, leave a comment or two. Thanks.Enjoy!

www.LastBridge.net

Posted in Programming, Projects, Ruby On Rails, videowith 25 Comments →

Development: LastBridge01.18.08

LastBridgeWhat? What is this? Well, yeah… it is another project of mine. I call it LastBridge, like the name? its original… anyways.. So LastBridge is a web app for users of the Roku SoundBridge like myself. Basically you can listen to your last.fm music on the SoundBridge without having to install anything or hosting any files. I previously wrote the same thing in a much cheaper less good looking way, in PHP. This time I have rewritten it using Ruby On Rails. As soon as I release it make sure to check it out.

Posted in Projects, Ruby On Railswith 10 Comments →

Ruby Code Snippet01.13.08

In Ruby a switch statement looks like this

say = "Hello"

case say
when "Hello" then
	puts "Say Hello"
when "Bye" then
	puts "Say Bye"
end

In PHP a switch statement looks like this


Posted in Programming, Rubywith No Comments →

Ruby MySpace Status Updater01.05.08

I have written a MySpace Status Updater class in Ruby. So if you want it take it, download it, use it.Download Here Or Download the RubyGem 

How do you use it?

credentials = {:username => ”, :password => ”, :status => %q(Okay Now I am really Done!…)}

@status = MySpace.update_status(credentials) 

Posted in Rubywith 2 Comments →

“Rails is Ghetto”01.02.08

Wow, you don’t see rants like this every day. Zed Shaw, who created Mongrel, a library and web server that just about everyone uses to serve rails applications, is basically a God in the Rails community. In a post today called “Rails Is A Ghetto” he tears into a number of leading Rails developers, the community in general, and a number of startups (and Google).via Techcrunch

Posted in Other, Ruby On Railswith No Comments →

Happy New Year!01.01.08

Hello everyone it is I… Thanks to everyone who as emailed me, said good stuff about my work, and gave me tips and everyone who as made a comment. Thanks everyone!-fernyb 

Posted in Mewith 1 Comment →

David Blaine Street Magic Part 312.29.07

Blaine sets his sights on the same two effeminate idiots from the last two videos. And unfortunately for them, the third time’s the charm.read more | digg story

Posted in videowith 1 Comment →

“The Future of Web Services” Video12.25.07

If you’re just getting into Rails or you’re not entirely clear on the whole REST thing, as I was, take a look at Gregg’s video presentation over at railsenvy.com It’s good.

Posted in Ruby On Rails, videowith No Comments →

Flock - The Social Web Browser12.21.07

feature_main_mac.jpg” cannot be displayed, because it contains errors.
Flock - The Social Web Browser

I’m using flock now, and its pretty cool.. at least I think so. Check it out and give it a shot..

Posted in Otherwith 1 Comment →


  • I am Fernando Barajas. Mostly known as FernyB.

  • Recent Comments

    • DennisBB: @neo I don’t see where he wrote on his site that he’ll provide support for that program
    • DennisBB: That’s kool d00d Haven’t tried it yet, but once I’ll have time
    • Pedro: Please send me an invite ;)
    • Josh: That would be sweet. This is the only thing I can find anywhere that actually updates MySpace status outside of...
    • fernyb: @josh I haven’t worked on this code for a while but I suppose I can take a quick look at it, of course...


My blog is worth $1,693.62.
How much is your blog worth?


Bad Behavior has blocked 272 access attempts in the last 7 days.

eastern-avalanche
eastern-avalanche
eastern-avalanche
eastern-avalanche