Skip to content

Instantly share code, notes, and snippets.

View AlexanderShushunov's full-sized avatar

Alexander Shushunov AlexanderShushunov

View GitHub Profile
@AlexanderShushunov
AlexanderShushunov / operationPerSecond.js
Last active December 13, 2019 10:57
Snippet to measure operation per second
function operationPerSecond () {
let lastNotifyTime = Date.now()
let operationCount = 0
return () => {
operationCount++
if (Date.now() - lastNotifyTime > 1000) {
console.log('opp per sec:', operationCount)
operationCount = 0
lastNotifyTime = Date.now()
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.block {
height: 20px;
border: 1px solid;
}
@AlexanderShushunov
AlexanderShushunov / most-frequent-letter.js
Last active March 8, 2017 09:38
Snippet calcs most frequent letter in the string. It uses lodash.
const _ = require('lodash');
let result = _("qwerwererrr")
.groupBy()
.map((value, key) => ({key, length: value.length}))
.maxBy(_ => _.length)
.key;
console.log(result);
@AlexanderShushunov
AlexanderShushunov / MatrixUtils.java
Created October 26, 2016 09:56
Result of the lesson demo (26.10.2016) Points: meaningful names, preconditions, small function, function preconditions, using domain vocabulary, code formatting.
import java.util.Arrays;
public class MatrixUtils {
public static int[][] multiplyMatrix(
int[][] left,
int[][] right) {
if (!checkMatrix(left) || !checkMatrix(right)) {
throw new IllegalArgumentException();
}
if (getColumnCount(left) != getRowCount(right)) {