Page 1 of 1

Stoner loop

Posted: Wed Nov 09, 2011 11:04 am
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');
?>

Re: Stoner loop

Posted: Wed Nov 09, 2011 5:46 pm
by kaos78414
This looks very useful! Great if you find yourself using a lot of while loops.

Re: Stoner loop

Posted: Wed Nov 09, 2011 8:42 pm
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.

Re: Stoner loop

Posted: Wed Nov 09, 2011 9:49 pm
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

Re: Stoner loop

Posted: Wed Nov 09, 2011 11:03 pm
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.

Re: Stoner loop

Posted: Wed Nov 09, 2011 11:16 pm
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.

Re: Stoner loop

Posted: Thu Nov 10, 2011 12:24 am
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?

Re: Stoner loop

Posted: Thu Nov 10, 2011 11:25 am
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.

Re: Stoner loop

Posted: Thu Nov 10, 2011 9:56 pm
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.

Re: Stoner loop

Posted: Thu Nov 10, 2011 10:26 pm
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.