Skip to content

Instantly share code, notes, and snippets.

View frops's full-sized avatar
Focusing

Ildar Asanov frops

Focusing
View GitHub Profile
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;
}
}
@you-think-you-are-special
you-think-you-are-special / Url.php
Last active August 29, 2015 14:13
Yii2 Url Behavior
<?php
/**
* Email: <[email protected]>
* Date: 19.01.15
* Time: 12:10
*
* use \behaviors\Url
* ...
*
* public function behaviors()
@you-think-you-are-special
you-think-you-are-special / Singleton.js
Created February 18, 2015 10:52
ES6 Singleton example. Use: import Singleton from 'Singleton'; let instance = Singleton.instance;
'use strict';
/**
* Created by Alexander Litvinov
* Email: [email protected]
* May be freely distributed under the MIT license
*/
let singleton = Symbol();
let singletonEnforcer = Symbol();
@you-think-you-are-special
you-think-you-are-special / UserSetter.php
Created March 26, 2015 10:01
Yii2 UserSetter Behavior
<?php
/**
* Created by Alexander Litvinov
* Email: [email protected]
* May be freely distributed under the MIT license
*/
namespace common\behaviors;
use Yii;
@subfuzion
subfuzion / curl.md
Last active November 11, 2024 03:27
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@montanaflynn
montanaflynn / CONCURRENCY.md
Last active November 7, 2024 18:22
Examples of sequential, concurrent and parallel requests in node.js

Concurrency in JavaScript

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.