Javascript is a programming language with a peculiar twist. Its event driven model means that nothing blocks and everything runs concurrently. This is not to be confused with the same type of concurrency as running in parallel on multiple cores. Javascript is single threaded so each program runs on a single core yet every line of code executes without waiting for anything to return. This sounds weird but it's true. If you want to have any type of sequential ordering you can use events, callbacks, or as of late promises.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by Alexander Litvinov | |
* Email: [email protected] | |
* May be freely distributed under the MIT license | |
*/ | |
namespace common\behaviors; | |
use Yii; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Created by Alexander Litvinov | |
* Email: [email protected] | |
* May be freely distributed under the MIT license | |
*/ | |
let singleton = Symbol(); | |
let singletonEnforcer = Symbol(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Email: <[email protected]> | |
* Date: 19.01.15 | |
* Time: 12:10 | |
* | |
* use \behaviors\Url | |
* ... | |
* | |
* public function behaviors() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Item drop_random_item() { | |
int r = rand(0, total_chance_sum); | |
int current_sum = 0; | |
for(int i = 0; i < items.count(); i++) { | |
if (current_sum <= r && r < current_sum + items[i].chance) return items[i]; | |
current_sum += items[i].chance; | |
} | |
} |