Skip to content

Instantly share code, notes, and snippets.

View vitaliy-evsyukov's full-sized avatar

Виталий Евсюков vitaliy-evsyukov

View GitHub Profile
func Merge2Channels(fn func(int) int, in1 <-chan int, in2 <-chan int, out chan<- int, m int) {
var wg sync.WaitGroup
wg.Add(1)
res := make([]int, m*2)
n := 0
go func() {
defer wg.Done()
for i := 0; i < m; i++ {
v1 := <-in1
v2 := <-in2
$a = [
[1, 2, 3, 4],
[14, 15, 16, 5],
[13, 20, 17, 6],
[12, 19, 18, 7],
[11, 10, 9, 8]
];
$r1 = rand(0, 7);
$r2 = rand(0, 7);
@vitaliy-evsyukov
vitaliy-evsyukov / brutforce.js
Created August 28, 2012 11:53
Tiny JavaScript brutforce
var n, al = ['A', 'B', 'C', 'D'], r = ['', '', ''], linesCount = 100;
for (var i = 0; i < linesCount; i++) {
n = i;
r = ['', '', '',];
for (var j = r.length - 1; j >= 0; j--) {
r[j] = al[n % al.length];
n = Math.floor(n / al.length);
}
console.log(r);
@vitaliy-evsyukov
vitaliy-evsyukov / LongColumnMenu.js
Created August 1, 2012 12:20
ExtJS 4.1 grid feature to get long column menu
/**
* @class Sotm.ux.grid.feature.LongColumnMenu
* Фича, добавляющая в меню выбора колонок в гриде пункт, открывающий подменю с оставшимися колонками, если общшее их
* число превышает установленное
* @extends Ext.grid.feature.Feature
* @ftype longcolmenu
*/
Ext4.define('Sotm.ux.grid.feature.LongColumnMenu', {
extend : 'Ext4.grid.feature.Feature',
alias : 'feature.longcolmenu',
@vitaliy-evsyukov
vitaliy-evsyukov / dnd_grid_to_tree.html
Created March 15, 2012 12:20
ExtJS 4 Drag&Drop from GridPanel to TreePanel and from TreePanel to GridPanel
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Grid to Tree Drag and Drop Example</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="../shared/example.css" />
<script type="text/javascript" src="../../bootstrap.js"></script>
<script type="text/javascript" src="../shared/examples.js"></script>
@vitaliy-evsyukov
vitaliy-evsyukov / IntegerArray.txt
Created March 7, 2012 23:37
Counting inversions in array
54044
14108
79294
29649
25260
60660
2995
53777
49689
9083
@vitaliy-evsyukov
vitaliy-evsyukov / chain.php
Created January 27, 2012 11:57
Chain-of-responsibility pattern
<pre>
<?php
abstract class Controller {
protected $_data = array();
protected $_chain = null;
public function __construct(array $data = array()) {
$this->_data = $data;
<?php
// KNAPSACK BALANCER!
class Balancer
{
public static function balance($items, $key)
{
$result = array();
$maxWeight = floor(self::sum($items, $key) / 2);