Javascript browser dictionary script

Create a new bookmark on your bookmark bar enter the following code into the URL field:

javascript: var word = prompt('What is the magic word?'); if(word){ window.open('http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=define%3A+'+word,'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');}

Now when you will click the button, you will be asked “What is word you want to define?”. Simply type the word you want to define. You can change the Google search url to any url [like dictionary.com]

[pointless tags]
Javascript tricks, javascript, javascript URL code tricks, javascript rocks, javascript API, javascript hack

Facebook, anti homework bookmark

We all know how distracting facebook can be while we are doing homework. Here is a list of things you can do to prevent our favorite social network (or any other website) from distracting us during important work:

  • Log out of Facebook
  • Create a new bookmark on the book mark bar called “Facebook” and in the URL section type the following:

    javascript: alert('Do your homework! >:['); var ans = prompt('OK?'); if(ans == 'please let me in'){document.location.href="http://facebook.com/"};
  • When you will click this bookmark it will alert you saying “Do your homework!” and then it will ask you for the password to let you through to facebook. The default password is “please let me in” but you can change this to your liking.

Hopefully this bookmark will remind you to stay focused on your homework.

    How to write good code.

    How to write good code

    Best PHP editor for mac

    Espresso mac php editor

    Espresso mac

    Espresso by MacRabbit.

    What is a great PHP editor for mac? Well there are many out there, but last week I came among one that has made my workflow with PHP (both localhost and online FTP websites) very easy.

    Some notable features include really easy and flawless editing of many file formats (HTML, PHP, javascript…). And the other feature I love is the FTP file transfer system.

    [Download the trial]

    [Buy it for $79.95] It is 100% worth the buy!

    [visit official Espresso website]

    Of course Pirate Bay and Kickass torrents may disagree with the price ;)

    PHP random hash trick [never collides]

    I discovered a really neat way to get a random hash that is less than 0.000005% likely to ever collide with another hash. Here is the script:

    <?php

    $hash = md5(rand(10,10000));

    ?>

    Simply echo the $hash and refresh the page. You will see a new hash string every time. Feel free to comment and leave suggestions.

    Facebook like PHP script

    We’ve seen the facebook like button everywhere right? But the crappy thing is that you have to copy-and-paste the facebook iframe code that has to be then edited. Lets fix this right now.
    I created a PHP function called facebook_like() which can be called anywhere where you want to show the facebook like button. For more info on the facebook like button go here :http://developers.facebook.com/docs/reference/plugins/like

    COPY AND PASTE:
    <?php
    function facebook_like(){
    function getAddress() //this function will show the URL you are on DONT EDIT
    {
    /*** check for https ***/
    $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
    /*** return the full address ***/
    return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    }
    $url =  getAddress(); //your full URL for page
    return '<iframe src="http://www.facebook.com/plugins/like.php?href='.$url.'&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>';
    }
    ?>
    <h1>Hey do you like this page PHPacademy?</h1>
    <?=facebook_like();?>

     

    Generate random hash (PHP) function

    The following function will generate a random hash, and these strings are very unlikely to ever collide.
    function generateHash(){
    $result = "";
    $charPool = '0123456789abcdefghijklmnopqrstuvwxyz';
    for($p = 0; $p<15; $p++)
    $result .= $charPool[mt_rand(0,strlen($charPool)-1)];
    return sha1(md5(sha1($result)));
    }
    Use it to secure things up :)

    Tiny.cc PHP api script.

    Alright so I made this basic PHP script that lets you make a basic API post request to [url]tiny.cc[/url]. To get started just go create a free user account on tiny.cc (it doesn’t let you use your API key unless you make one).

    1. After you have created a tiny.cc account click here: http://tiny.cc/api-docs Then click “Generate API” Under the Api key.
    2. Here is the PHP function I created that lets you tiny stuff.

    <?php
    $longUrl = 'http://sarcasticblogger.wordpress.com/'; //the url you want to tiny
    $username = 'cool_playa';               // your tiny.cc username
    $apiKey = 'asdfasdfasdfasdfasdfasdfasdfasdfasdf'; // the api key that tiny.cc gave you
    ////// DON"T TOUCH BELOW
    $api_call_url = "http://tiny.cc/?c=rest_api&m=shorten&version=2.0.1&format=json&longUrl=".$longUrl."&login=".$username."&apiKey=".$apiKey;
    $decoded = json_decode(file_get_contents($api_call_url), true);
    ///////////////////
    //You can use the following: var_dump($decoded);
    ///to show you the array data for the API call.
    ///////////////////
    echo $decoded['results'][$longUrl]['short_url'];  //will show you your tiny url
    ?>

    PHP twitter replacers.

    Twitter has the neat ability to change @this into a link to the user this. Well I found some neat ways to make @replies and #topics into links.

    1. @replies –
      $atreply = preg_replace(‘/(@[A-Za-z1-9]+)/’,'<a href=”/users/$1″><u>$1</u></a>’, $from);
      Alright this works by taking $from and checking if for something with an @ infront followed by numbers or letters. It will replace @this with a link to /users/this. You can play around with what the link should be to. Just remember $1 is the var used to replace the word that was followed by the @.
    2. #topic-
      $topic = preg_replace('/#([A-Za-z1-9]+)/','<a href="/topic/$1"><u>#$1</u></a>',$from);

      This does pretty much the same thing as the @reply function. It goes through and finds anything from the var $from and checks it for a # followed by numbers or letters. It replaces the #this with a link to /topic/this. As always you can play around with this

    PHP basic search engine [iframe]

    Lets create a script that will let you search any of the popular search engines that use the GET method. Examples: Google, Yahoo, Bing etc. This script will display an iframe for your search service anywhere on your page. You can also make it so Google searches through your website only. Let’s get started:

    Bais HTML form:

    <form method="GET" action="search.php">
    <input type="text" name="q" value="Search"> <input type="submit" value="Search">
    </form>

    How it works:

    This will create an input that will let the user enter the search term. The submit button will post the information in the input area to search.php.

    search.php:
    <?php
    $q = $_GET['q']; //get it from the form
    echo '<iframe src="http://www.google.com/search?q='.$q.'"></iframe>'; //embeds iframe for search results from GOOGLE.
    ?>

    How it works:

    Using the GET method this script will GET the $q that was posted earlier using the HTML form. Using echo we show an iframe. This iframe will show the search results from Google on your website. This is achived by replacing the ?q variable of the search engine and adding $q which is the search term. Some other sources for search engines:

    Yahoo - http://search.yahoo.com/search/?q=’.$q.’

    Bing – http://www.bing.com/search?q=’.$q.’&go=

    Ask.com – http://www.ask.com/web?q=’.$q.’&search=&qsrc=0&o=0&l=dir

    Follow

    Get every new post delivered to your Inbox.