Skip to content

Instantly share code, notes, and snippets.

View DenisVerkhoturov's full-sized avatar
🖖
self-educating

Denis Verkhoturov DenisVerkhoturov

🖖
self-educating
View GitHub Profile
@DenisVerkhoturov
DenisVerkhoturov / alteration-protein-level-pattern.re
Last active May 19, 2020 11:34
PCRE (Perl Compatible Regular Expression) for protein level alteration notation. Based on http://www.hgmd.cf.ac.uk/docs/mut_nom.html#protein
(?x)
^
(?<prefix>p.)?
(?<alteration>
(?:
(?<substitution>
(?<substitution_old>A|R|N|D|B|C|E|Q|Z|G|H|I|L|K|M|F|P|S|T|W|Y|V|X)
(?<substitution_position>\d+)
(?<substitution_new>A|R|N|D|B|C|E|Q|Z|G|H|I|L|K|M|F|P|S|T|W|Y|V|X)
)
@DenisVerkhoturov
DenisVerkhoturov / matchers-against-asserts.md
Created February 25, 2020 20:02
Testing: Matchers agains asserts

Testing: Matchers

Let's weight up a couple of testing approaches. We will test these two simple functions:

  • sum(List<Integer>) : int
  • max(List<Integer>) : int

The simplest way to cover this functionality with tests will be to use assertEquals and assertTrue members of the org.junit.jupiter.api.Assertions class, so we write tests like these:

public class FunctionsTest {
    @Test void testIfListIsEmptyForSum() {
        assertEquals(0, sum(emptyList()));
@DenisVerkhoturov
DenisVerkhoturov / MicroTypes.scala
Last active January 23, 2020 16:56
Scala micro types using value classes and smart constructors
import cats.Show
import cats.data.{ NonEmptyChain, NonEmptyList, Validated }
import cats.data.Validated.{ Invalid, Valid }
import scala.util.control.NoStackTrace
trait Wrapped[T] extends Any {
def unwrap: T
module Main
namespace DNA
data Nucleotide : Char -> Type where
A : Nucleotide 'A'
C : Nucleotide 'C'
G : Nucleotide 'G'
T : Nucleotide 'T'
namespace RNA
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.AclFileAttributeView;
import java.nio.file.attribute.AclEntry;
import java.nio.file.attribute.AclEntryType;
import java.nio.file.attribute.AclEntryPermission;
import java.nio.file.attribute.UserPrincipal;
import _ from 'lodash';
_.mixin({
splitOn: (array, needSplit) => {
function splitting(chunks, current) {
const [init, last] = [_.initial(chunks) || [], _.last(chunks) || []];
const previous = _.last(last);
return needSplit(current, previous) ? [ ...chunks, [current] ] : [ ...init, [ ...last, current ] ];
}
@DenisVerkhoturov
DenisVerkhoturov / OopTest.java
Last active June 3, 2019 11:41
Function-based objects
package metamer.cmdparser;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.function.Function;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

При начале работы обязательно выполняем:

git pull

А в конце работы обязательно выполняем:

git push

Это вообще хорошая практика, оставлять репозиторий в консистентном состоянии после окончания работы и обновлять состояние непосредственно перед тем как приступить к работе.

1. Debounce

Реализовать функцию, которая принимает функцию и время в миллесекундах и следит за тем, чтобы переданная функция была вывана только в том случае, если с предыдущего вызова прошло определенное время, иначе функция не должна делать ни чего сразу, а только назначать выполнение функции по истечении определенного времени.

  function greeting(name) {
    console.log(`Greetings, ${name}!=D`);
  }