Stoner loop

Place to place any code snippets, completed games, or even uncompleted games for IR users to use.
Post Reply
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Stoner loop

Post by Chris »

Lets you loop through one or two callback functions a given amount of times from the global scope.

Code: Select all

<?php

class stonerLoop {

    var $calls;
    var $callNum;
    var $callBackOne;
    var $callBackTwo;

    function __construct( $numCalls, $callBackOne, $callBackTwo=NULL )
    {
        $this->calls = $numCalls;
        $this->callBackOne = $callBackOne;
        $this->callBackTwo = $callBackTwo == NULL ? $callBackOne : $callBackTwo;
        $this->one();
    }
    
    function call($function)
    {
        $function();
    }
    
    function one()
    {
        $this->callNum++;
        
        $this->call($this->callBackOne);
        
        if( $this->callNum > $this->calls )
        {
            return;
        }
        $this->two();
    }
    
    function two()
    {
        $this->callNum++;

        $this->call($this->callBackTwo);
        
        if( $this->callNum > $this->calls )
        {
            return;
        }
        $this->one();
    }
    
}

function lol()
{
    echo 'LOL';
}
function haha()
{
    echo 'haha';
}

new stonerLoop(10, 'lol', 'haha');
?>
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
kaos78414
Posts: 507
Joined: Thu Jul 22, 2010 5:36 am

Re: Stoner loop

Post by kaos78414 »

This looks very useful! Great if you find yourself using a lot of while loops.
w00t
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Stoner loop

Post by Chris »

The main reason I wrote this is cause when you're high, for loops are the most annoying thing to write, now I can just call a function a certain amount of times. I'll have to benchmark this, I don't think it will turn out too good.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
kaos78414
Posts: 507
Joined: Thu Jul 22, 2010 5:36 am

Re: Stoner loop

Post by kaos78414 »

Do you do a lot of programming while high? I tried to program drunk once - I came back and looked at it the next day, it was godawful haha
w00t
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Stoner loop

Post by Chris »

Dude.. I can't program unless I'm high! The worst thing is if you smoked late in the evening and the next morning you feel stupid. That means it's generally going to have to be a wake and bake before I can start to program again, but if I'm out of weed in the morning the coffeeshop doesn't open till 10.. So that's around 11 before I get there.. Then with my laptop, I just sit there, joint in my mouth, dreaming up ideas and putting them to use.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
kaos78414
Posts: 507
Joined: Thu Jul 22, 2010 5:36 am

Re: Stoner loop

Post by kaos78414 »

Where do you live that you can smoke in a coffee shop? If smoking was legal where I was I would definitely be doing that instead of drinking.
w00t
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Stoner loop

Post by Jackolantern »

kaos78414 wrote:Where do you live that you can smoke in a coffee shop? If smoking was legal where I was I would definitely be doing that instead of drinking.
Where else in the world could he be where you can smoke (and buy, btw) weed in a coffee shop? :lol:

Hey Chris, I always heard that the hash shops were more of a tourist thing. Are there a lot of native weed smokers over there?
The indelible lord of tl;dr
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Stoner loop

Post by Chris »

Maybe in Amsterdam.. but not in my town.. They're actually going trying to control it by only letting people with special passes into coffee shops. Meaning no more weed for tourists.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Stoner loop

Post by Jackolantern »

Chris wrote:Maybe in Amsterdam.. but not in my town.. They're actually going trying to control it by only letting people with special passes into coffee shops. Meaning no more weed for tourists.
Nah, they aren't going to do that. Or if they did, they would be stupid. Legal weed brings millions, if not billions, of dollars into the city every year.
The indelible lord of tl;dr
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Stoner loop

Post by Chris »

Jackolantern wrote:
Chris wrote:Maybe in Amsterdam.. but not in my town.. They're actually going trying to control it by only letting people with special passes into coffee shops. Meaning no more weed for tourists.
Nah, they aren't going to do that. Or if they did, they would be stupid. Legal weed brings millions, if not billions, of dollars into the city every year.
Yeah, and all of those millions were bought in by coffeeshops tax free from illegal growers :D. It's illegal for the coffeeshops to buy weed and for a grower to sell weed.. Coffeeshops are allowed to sell it however. I think the best solution to the problem were if the police were to sell the weed to the coffeeshops. That way the police can tax the weed, tax the growers for selling it, and the police can control how much the coffeeshops sell because they're only source should be and would be from the police.
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Code Sharing”