Skip to content

Instantly share code, notes, and snippets.

View frops's full-sized avatar
Focusing

Ildar Asanov frops

Focusing
View GitHub Profile
@montanaflynn
montanaflynn / CONCURRENCY.md
Last active June 28, 2024 12:00
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.

@subfuzion
subfuzion / curl.md
Last active July 3, 2024 11:43
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.

@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: alexander@codeordie.ru
* May be freely distributed under the MIT license
*/
namespace common\behaviors;
use Yii;
@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: alexander@codeordie.ru
* May be freely distributed under the MIT license
*/
let singleton = Symbol();
let singletonEnforcer = Symbol();
@you-think-you-are-special
you-think-you-are-special / Url.php
Last active August 29, 2015 14:13
Yii2 Url Behavior
<?php
/**
* Email: <alexander@codeordie.ru>
* Date: 19.01.15
* Time: 12:10
*
* use \behaviors\Url
* ...
*
* public function behaviors()
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;
}
}