Building Asterisk Modules

Compile a module:

gcc -shared res_taysipreload.c -o -fPIC


Move to proper dir:

sudo cp /usr/lib/asterisk/modules/

Load: module load res_taysipreload


How to set up your own PBX (Phone System)

Setting up an office phone system is not as hard as most people would have you believe.  Thanks to VoIP, technology has gotten to a point where end users can install phones them selves and easily customize the phone system to do what they want.  In about a half an our almost any individual can build their own PBX system, here is a great guide on how to build your own PBX that I wrote recently on RingRoost:

So what is a PBX anyway?

A PBX (Private Branch Exchange) is simply a phone system for an office,  a PBX usually has number of phones each assigned an extension.  Each extension can interact with the other extensions in some way (conferencing, call forwarding, queues etc..), and can usually make outbound calls to anywhere in the world.  Traditionally companies would run physical phone lines into their business and install a physical computer on site in order for a PBX to work. Now most PBX system are hosted or virtual. Meaning that the server they run off is not physically located at the business. This means that building your own PBX no longer requires installing your own hardware and software.



Setting up SSH keys

1. Generate pub/private key one client in ~/.ssh/ : ssh-keygen -t rsa
2. Append public key on client to servers authorized key file: ~/.ssh/authorized_keys
3. On client add private key to keychain: ssh-add -K ~/.ssh/privateKey.txt

note: on ubuntu to add key to  ~/.ssh/config:

<code>IdentityFile ~/.ssh/keyfile.txt</code>
<code> </code>

Displaying code in html

Displaying various types of code on an HTML web page  is always an annoying problem, especially when you are using a editor of some sort to create the post/page on the backend. My solutions (which I think is the best) is to store the code in regular html bad characters and all (“<”, “>”).  And then any code that your write inside a post/page put inside the “<pre></pre>” tags. Then when outputting your content use this little handy function that run’s PHP’s htmlspecialchars only on what’s inside your “<pre>” tags:

function html_encode_pre_tags($content){                                                                             
 $line = preg_replace_callback(                                                                                       
         function ($matches) {                                                                                        
             return "<pre>".htmlspecialchars($matches[1])."</ pre>;";                                                   
 return $line;                                                                                                        

This allows your to create posts in various CMS like WordPress and embed example code that can show up pretty on the front end. To top off my solutions I use highlight.js to make the code look extra colorful and pretty to whoever is viewing it on the front end.

Fun new voip technologies

I got into the communications/VOIP business about a year ago and have really been enjoying it. There seems to be a ton of new opportunities emerging, as there is a pretty inevitable shift away from the old way of doing things (PSTN) and the new way of doing things – VOIP. Unfortunately this shift is happening a little slower than ideal as the giant carriers want to ensure their piece of the pie is not going anywhere. The regulations are not exactly helping the situation either,  the governing bodies and regulations are shockingly obscure and outdated, making it difficult to plan/forecast any business model.

None the less, there is no stopping the train of innovation and the latest/coolest technology that has emerged recently is WebRTC. This protocol turns browsers into video and voice capable device, allowing them to work as full fledged media communications clients. This allows users to make voice and video calls right in their browser without any third party technology (like Skype).  With a little finagling I was able to build a “click to call”  browser based button, so people can call me right in their web browser.  Here it is at work, go ahead and give it at try.

Here is an article I  on how to get a click2call button of your own.

The tradition “click to call” method works a bit different, and IMO is not all that helpful to users. That process requires users enter their number and then a call is initiated to the user which is then connected to the business. This process is not much better than entering your number in a lead form and is what the google voice widget below offers:




Reverse Engineer Database With Doctrine & Symfony

My beef with symfony/Doctrine combo is it’s tuff to make changes to your database and the update your Entities. To appease my anger I wrote little PHP script that lets you make changes to your database and then update your entities. Basically this just reverse engineers your database as explained here – now you can avoid having to follow those instruction and just run this php code after making a database change.

NOTE: You will need to change the first three variables to fit your application.

 $path="/home/webhostingweaver_remake/src/Ecom/ModelBundle/Resources/config/doctrine"; //change me
 $bundle= "Ecom"; //change me
 $namespace="Ecom\\ModelBundle\\Entity\\"; //change me
 $command="php app/console doctrine:mapping:convert xml $path --from-database --force";
 $dir = new DirectoryIterator($path);
 foreach ($dir as $fileinfo) {
     if (!$fileinfo->isDot()) {
         $contents= str_replace("entity name=\"","entity name=\"".$namespace,$contents);
 //generate entities
 system("php app/console doctrine:generate:entities $bundle"); 

Run script/PHP as ROOT from web server

Often times you need root permissions to do crazy stuff from a web application. Here is my approach which I think is the best way to do it. As far as I know it’s fine from a security standpoint. I know this seems like a lot but its really not that bad.

#Create a PHP file that contains your script:

vim /scripts/my_script.php

#create a shells script that will run the php script

vim /scripts/my_shell_script

# inside the "my_shell_sript" file add this line that will run the php

php /scripts/my_script.php

#In your web application run that script by calling:

exec('sudo /scripts/my_shell_script');

#Lastly we need to set up linux to not ask for password when running my_script.php.

#Open up /etc/sudoers and add this line:

www-data ALL=NOPASSWD: /scripts/my_script.php

CONGRATS – You  are now running that php script as root.







Absolute vs Relative Truth – The Big Puzzle

I had a conversation with a friend about absolute vs relative truth, not much came of it, but a few nights ago I could not sleep and ended just thinking about it most the night. This is generally the type of stuff I keep to myself,  however I decided to share.

I’ve noticed that my stance or thinking on a philosophical or any topic is derived from first thinking of a situation then applying that situation to what I consider a thought framework or stance on a topic. Often I draw a conclusion, based on situations without registering that I did so.

For example:
How do you think about relative vs absolute truth in the context of this situation?
“What is 2 + 2? “

What about this situation ?
“That is a beautiful girl”

What about this situation ?
“Old hag or young lady?”

The last example is where I initially formed my bases for understanding absolute vs relative truths. It shows a picture in which some see an young lady and some see an old hag. Class rooms have been shown this picture and argue over what she is, after some debate the picture is explained to them and they see the other side of the women in the picture.

Applying this situation to my thinking I thought: well each person has a relative view of the picture, but when they see the other side they are enlightened and understand the picture is an optical illusion. Knowing that the picture is an optical illusion and having seen both sides they now know the absolute truth about the picture.

My initial conclusion was then that:

There seems to be both an absolute truth and a relative truths.

This conclusion rubbed me the wrong way, as this “absolute truth” seemed a little to easy to come by . So I thought about another situation.

What if three men look at the sky two men say the sky is blue and one man who was born color blind says that the sky is  grey. One day one of the  ”blue sky” men goes color blind. He has now seen the sky in both a blue and grey, and has a richer understanding of the sky color than the two other  men.

This thought drew me to a bit different conclusion about absolute and relative truths; as the man who had seen the sky as both grey and blue still does not have the absolute truth about the sky color, he has not seen the sky through the eyes of a bat, or through the eyes of man who can only see some colors.

My new conclusion was that:

There is an absolute truth that is unobtainable by humans, so we think in relative truths that have a nearness or farness from the absolute truth.

I liked this framework of thought, but as I piped various situations through it , the framework seemed to fail or at least be greatly lacking. The one situation that it really seemed to lack to explain the most was the most trivial in nature.

“Was it Owen Wilson or Luke Wilson that starred in the movie Wedding Crashers?”

I say Owen, my moron friend says Luke. There seemed to be such an absolute correctness here, no relative proximity to the correctness,  there is no spinning this one, this was entirely and absolutely true - “Owen Wilson starred in Wedding Crashers.”

Thinking about this expanded my understanding greatly. I found that in most of the previous situations I was thinking about there was generally an entirely different interpretation of a truth, a different paradigm in which people viewed a situation that led them to draw different yet relatively true conclusions. The paradigm that the color blind man lives in leads him to believe the sky is grey, the paradigm in which the man who can see color lives in leads him to believe the sky is blue.

In the Wedding Crashers situation my friend and I are within the exact same paradigm of thought – we did not interpret anything in reguards to the sitution differently. We both had the same interpretation of what a “Star” in the movie was, we both speak English,  we both were speaking about the same movie – ultimately our interpretation was the same.

This understanding began to lead me to understand how utterly far away we are from the “absolute truth”. The only reason we were able to have this argument is because we have some framework or paradigm of thinking. The understanding of this human paradigm and our complete depravity of knowledge was I think my biggest leap in understanding of all.

From that understanding I reworked my model of truths to that of a puzzle, a very big puzzle. A completed puzzle would be absolute truth.

As we live our life, we put down pieces on our puzzle that give us a better view of the absolute truth. The curious thing about a puzzle is that until it is one hundred percent complete we do not know what it is, and can only make statements as to what we see on the puzzle. Each of our puzzles looks very different, yet humans have all done some work on the bottom right corner of the puzzle.

So when a little child sees Santa Clause on the puzzle, that child says look it’s Santa, after putting a few more pieces down that child sees a different picture of Santa as being a fun character we created for a Christmas.

A boy who sees a girl and says she is beautiful, gets to know her a little (putting a few more pieces down on his puzzle) and says she is ugly. Then later gets stuck in a class with her (puts a few more pieces down on his puzzle) and thinks she the most beautiful thing in the world and marries her.

A religious man who says there is a God looks at his puzzle and sees a God. An atheist looks at his puzzle and says there is no God. That same atheist has a child and his puzzle changes drastically now he sees a God. The religious man discovers new information that puts more pieces on his puzzle and now the picture of God he saw turns into “Opium of the people”.

A man argues with a friend about who is the star of the movie, both men see a very similar puzzle. One man put a few pieces down on his puzzle that said Luke Wilson stared in Wedding Crashers because he looked at IMDB the other put pieces on his puzzle when folks said “look it’s Owen Wilson in that movie”. Both men’s puzzles grew after discussing the issue. We both now understood that for a brief period IMDB had put that Luke Wilson had stared in wedding crashers. Our puzzles became aligned, but still grossly incomplete. We did not know that on the day IMDB made this mistake – Jennifer a part time employee who had put the information up had done so on purpose after flirting with a boy in a class she was taking by claiming it was indeed Luke not Owen who stared in weeding crashers – knowing full well it was Owen. We did not know the that the boy thinking this prank was so clever began to see something in the girl he had missed before and ultimately grew to love and marry her.

Ultimately the thinking of truths as a puzzle will be greatly lacking, truth in this world is not a puzzle – it is what it is. Thinking about it this way however provides me with a better framework of thought than I have ever used in the passed.

Initially I thought that as individuals our goal is to expand our puzzle as best we can, continually seeking to get a better picture of the whole puzzle. Now I’m not so sure, I believe we choose most of the puzzle pieces we put down. Some pieces could show us a picture that could ruin our lives, other pieces may gives us the most wonderful lives possible. It seems we can not complete the puzzle, so the best option then would seem to be to try our best to put down those pieces that form a beautiful picture, even if they are not the whole picture.

I am however missing something about humans or myself, because I am adamantly determined to expand my puzzle no matter the impact to the well being of my life.  And I believe that as humans we have in the past and will continue to expand our puzzle no matter the consequence. So that one day we will be able to answer the question “Where did we come from?”  or “is evolution a fact?” as we now answer the question “What is 2 +2?” . 

SEO TIPS – Getting an accurate keyword monthly search count

I recently ran a seo campaign on a particular keyword that Google Adwords told me it was getting 14 million monthly global searches.  So when I got on the second page in the search results for the keyword I was pretty happy until I checked my traffic and was only getting a few visitors trickling in.  Stupid Adwords  was off by 13,999,500 visitors.


Create a google adwords campain  only using the one keyword you want to get information on. Be sure to put brackets around it so it must be an exact match. EX [my search keyword]

Set your cost per click really high, so google will be sure to show your add when someone searches the keyword. Run the campaign for a day or to then look at how many impressions you got per day. Extrapolating that to a month can give you a fairly accurate results on how many searches that keyword is getting.

You also might want to make your add not very relevant to the keyword so people don’t click on it and cost you money.

for example if i was targeting the keyword “high heel shoes” 

An add like this would work:

Mexican Jumping Beans
Your like beans don’t you?
youre a dirty little jumping bean


note: this technique is more accurate for keywords that are not getting massive amounts of monthly searches.




Creating a user session class in PHP

Managing user sessions in PHP applications should be made simple using PHP’s built in “session_start”. However after working with this function you might recognize it’s not the cleanest solution and may not scale well.

I recently built a simple user session class that I believe is a much cleaner/scalable solution. This class uses Memcache as storage engine as appose to flat files. This gives us the ability to manage user session across multiple servers. Using a database to store user sessions would also be a fine solutions. I would love some feedback from other developers on pro’s and con’s on this class.

A few things that I think make this such a good solutions for managing user sessions. First we use a the Singleton pattern so this class will only be instantiated once. Meaning for every php process we hit data storage once for retrieval. The second part of this is the __destruct which (called when the PHP process ends) saves our object to storage only once.

a few things to note:

    • this class is bare bones to show the main components. It would be ideal to put some other methods such as “authorizeUser”,”isUserAuthorized”, etc ….
    • as you can see this class has dependency on another class “Memcache\Connnection”. Here is that class so you could use it if you have a memcached server. If not you could create another datastorage class to use – it simply needs two methods : get($key), set($key,$value,$time_to_store).



include "Connection.php";

use Memcache\Connection;

class User

    protected static $instance; 

    protected $unique_key; 

    public $first_name;
    public $last_name;

    protected function __construct() { 
     * we save this user session when this php process is finishing
    function  __destruct(){

    private function __clone(){ } 

    public static function getInstance() 
        if (!self::$instance) 
            //see if we have a user session for this user,
            //if so we return that if not we construct
                return  $user;
                return new User(); 

        return self::$instance; 

     * fetches user function from memcache this is a serialized object so we 
     * just need to unserialze and should be godo
     * returns the user object or false if it does not exhist
    protected static function getUserSession()
            return false;

        $cache = Connection::getInstance();
        return $cache->get($user_session);  
     * if user does not have a session we need to give them a session cookie
     * and set the memcached object
     *  i will hash a unique time value (consider security implications)
     *  returns true on success false otherwise
    protected function init_session() {

        $cache = Connection::getInstance();
        return $cache->set($this->unique_key,$this,60*60);  


     * saves current object memache, can be called everytime something in here is set
     * should consider way to only call this when we wrapping up script
    protected function save(){
        $cache = Connection::getInstance();
        return $cache->set($this->unique_key,$this,60*60);