Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
vlad-bezden / index.html
Created November 3, 2016 12:06
Radiation Search
<div id="mocha"></div>

Clock Angle

Analog clocks display time with an analog clock face, which consists of a round dial with the numbers 1 through 12, the hours in the day, around the outside. The hours are indicated with an hour hand, which makes two revolutions in a day, while the minutes are indicated by a minute hand, which makes one revolution per hour. In this mission we will use a clock without second hand. The hour hand moves smoothly and the minute hand moves step by step. You are given a time in 24-hour format and you should calculate a lesser angle between the hour and minute hands in degrees. Don't forget that clock has numbers from 1 to 12, so 23 == 11. The time is given as a string with the follow format "HH:MM", where HH is hours and MM is minutes. Hours and minutes are given in two digits format, so "1" will be written as "01". The result should be given in degrees with precision ±0.1.

For example, on the given image we see "02:30" or "14:30" at the left part and "01:42" or "13:42" at the right part. We

@vlad-bezden
vlad-bezden / performance-calculator.markdown
Created December 30, 2016 16:50
Performance Calculator
@vlad-bezden
vlad-bezden / script.js
Created December 30, 2016 18:07
Union, Intersection, and Differences
'use strict'
console.clear()
const array1 = [1, 2, 3]
const array2 = [2, 3, 4]
const union = [...new Set([...array1, ...array2])]
const intersection = [...new Set(array1.filter(a1 => array2.find(a2 => a1 === a2)))]
const differences = [...new Set(array1.filter(a1 => !array2.find(a2 => a1 === a2)))]
@vlad-bezden
vlad-bezden / count_words.py
Created January 27, 2017 16:16
Calculate number of words in sentences using map/reduce and sorting dictionary by value in descending order
'''Calculating number of words and number of times they occurred in sentences
Example of how to use map, reduce, and sorting dictionary by value
Available functions:
- count_words: counts how many times each word occurred in the sentence
- combine_counts: combines two dictionaries. In other word sums up number of
times word occurred in each sentence
'''
@vlad-bezden
vlad-bezden / sensor_simulator.py
Last active January 27, 2017 19:10
Example of sensor data simulator with timestamp and random data. Provides example on zip, iterable, iterators and timer
'''Example of how to simulate sensor data'''
import datetime
import itertools
import random
import time
class Sensor:
'''Sensor simulator
@vlad-bezden
vlad-bezden / _vimrc
Last active April 7, 2017 19:55
vim configuration
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
@vlad-bezden
vlad-bezden / index.html
Created February 18, 2017 14:49
Time Calculator
<h1 id="result"></h1>
@vlad-bezden
vlad-bezden / permutations-using-generator-function.markdown
Last active February 24, 2017 01:58
Permutations Using Generator Function

Permutations Using Generator Function

// Usage Example: const result = permutations('abc')

for (let value of result) { console.log(value) }

A Pen by Vlad Bezden on CodePen.

@vlad-bezden
vlad-bezden / script.js
Last active March 11, 2017 16:44
IsPowerOfTwo
'use strcit'
/*
* Calculate if number is power of two. For instance 1, 2, 4, 8, 16, 32, 64, 128, ...
*
* @param {Number} n - number > 0
* @returns {Bool} - true if number is power of two false otherwise
*/
function isPowerOfTwo(n) {
if (n < 0) {