i => j1 = 2*i 0 => 0 1 => 2 2 => 4
j2 = 2*i+1 0 => 1 1 => 3 2 => 5
i = j//2 0 => 0 2 => 1 4 => 2
1 => 0 3 => 1 5 => 2
i => j1 = 2*i + 1 0 => 1 1 => 3 2 => 5
j2 = 2*i + 2 0 => 2 1 => 4 2 => 6
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
""" Inspired by http://flask.pocoo.org/snippets/40/ """ | |
app = Flask(__name__) | |
@app.url_defaults | |
def hashed_url_for_static_file(endpoint, values): | |
if 'static' == endpoint or endpoint.endswith('.static'): | |
filename = values.get('filename') | |
if filename: | |
if '.' in endpoint: # has higher priority |
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
const fs = require('fs'); | |
const path = require('path'); | |
async function *walkdir(dir) { | |
const stack = [dir]; | |
while (stack.length) { | |
const filename = stack.pop(); | |
const stat = await fs.promises.stat(filename); | |
if (stat.isDirectory()) { | |
const files = (await fs.promises.readdir(filename)) |
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
sample = [5, 3, 1, 2, 4] | |
n = len(sample) | |
mean = sum(sample)/n | |
median = (sample[n//2 - (n + 1)%2] + sample[n//2])/2 | |
stddev = (sum((e - mean)**2 for e in sample)/n)**0.5 | |
cnt = {} | |
for e in sample: | |
cnt[e] = cnt.get(e, 0) | |
cnt[e] += 1 | |
mode = sorted(cnt.keys(), key=lambda e: (cnt[e], -e))[-1] |
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'; | |
/** | |
* Пример использования socket.io namespaces в сервисе AngularJS. | |
* | |
* Цель: получить несколько отдельных каналов связи в рамках одного соединения. | |
* | |
* Проблема: так как сервисы в AngularJS являются синглтонами, не возможно | |
* получить несколько экземпляров сервиса Socket с разными значениями | |
* namespace. При этом хочется иметь отдельные сервисы, представляющие |
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
#include <chrono> | |
#include <iostream> | |
#include <stdlib.h> | |
#include <time.h> | |
#define SIZE_MEDIUM 4096 | |
#define SIZE_LARGE 16*4096 | |
#define ITER_COUNT 100000 | |
using namespace std; | |
using namespace std::chrono; |
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
def next_row(prev_row): | |
row = [prev_row[0]] * (len(prev_row) + 1) | |
for idx in range(len(prev_row) - 1): | |
row[idx + 1] = (prev_row[idx] + prev_row[idx + 1]) | |
return row | |
def binomial(n, k, cache=None): | |
""" Calculates binomial coefficients using Pascal's triangle. | |
0 1 |
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
Input | Py2 | Py3 | |
----------+-----+----- | |
5/2 | 2 | 2.5 | |
----------+-----+----- | |
5//2 | 2 | 2 | |
----------+-----+----- | |
5.0/2 | 2.5 | 2.5 | |
----------+-----+----- | |
5.0//2 | 2.0 | 2.0 | |
----------+-----+----- |
Run:
grep "07/May/2016" app_access.log | goaccess -a --log-format '%h %^[%d:%t %^] "%r" %s %b "%R" "%u"' --date-format '%d/%b/%Y' --time-format '%H:%M:%S' > goaccess_may07.html
More here