Skip to content

Instantly share code, notes, and snippets.

View sneznaovca's full-sized avatar

Palo Snežný sneznaovca

View GitHub Profile
import React, {useCallback, useLayoutEffect} from 'react';
import Quagga from '@ericblade/quagga2';
import QrCodeReader from '@ericblade/quagga2-reader-qr';
Quagga.registerReader('qrcode', QrCodeReader);
function getMedian(arr) {
arr.sort((a, b) => a - b);
const half = Math.floor(arr.length / 2);
if (arr.length % 2 === 1) {
@sneznaovca
sneznaovca / first-char-counter.go
Created July 10, 2016 10:26
Script print histogram first chars in wordlist
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"sort"
)
@sneznaovca
sneznaovca / sort.php
Created March 13, 2016 20:48
sort.php
/**
* @param array $list
* @param string $sortAttribute
* @return array
*/
public static function by(array $list, $sortAttribute)
{
usort($list, function($o1,$o2) use($sortAttribute) {
if (!property_exists($o1, $sortAttribute) || !property_exists($o2, $sortAttribute)) {
throw new InvalidArgumentException(sprintf('At least one object does not contains attribute \'%s\' used for sorting.', $sortAttribute));
<?php
/**
* usage: php matrix.php 4 2 3
*/
$m=$argv[1];
$n=$argv[2];
$k=$argv[3];