Skip to content

Instantly share code, notes, and snippets.

View sierikov's full-sized avatar

Artem Sierikov sierikov

View GitHub Profile
@sierikov
sierikov / HomeKitSamsungRemote.yaml
Created April 22, 2024 08:10
This automation allows user to control their Samsug Tizen TV using built in Apple TV Remote.
alias: Call Samsung TV on HomeKit Remote key presses
description: ''
trigger:
- platform: event
event_type: homekit_tv_remote_key_pressed
event_data: {}
condition: []
action:
- service: media_player.play_media
data_template:
@sierikov
sierikov / map-difference.scala
Created October 11, 2023 08:52
Difference between two Maps. Shows new and updated values.
case class MapDifferenceResult(
updatedValues: Map[String, String],
newValues: Map[String, String]
)
def findMapDifferences(
newMap: Map[String, String],
oldMap: Map[String, String]
): MapDifferenceResult = {
val (updatedValues, newValues) =
@sierikov
sierikov / fib-pinos.scala
Created February 26, 2023 13:06
Implementation of Fibonacci. Based on Anrea Pinos formula.
// Formula designed by Anrea Pinos
def fibonacci(n: Int): BigInt = {
n match
case n if (n % 4) == 0 => fibonacci((n + 2) / 2) * (fibonacci(n / 2) + fibonacci((n / 2) - 2)) + 1
case n if (n % 4) == 1 => fibonacci((n - 1) / 2) * (fibonacci((n - 1) / 2) + fibonacci(2 + (n - 1) / 2)) + 1
case n if (n % 4) == 2 => fibonacci((n - 2) / 2) * (fibonacci(n / 2) + fibonacci((n / 2) + 2)) + 1
case n if (n % 4) == 3 => fibonacci((n - 1) / 2) * (fibonacci((n - 1) / 2) + fibonacci(2 + (n - 1) / 2)) - 1
}
@sierikov
sierikov / Fibonacci.java
Created August 11, 2022 18:04
Fibonacci implementation using 3 different algrorithms
/*
* Demonstration of fast Fibonacci algorithms (Java)
* by Project Nayuki, 2017. Public domain.
* https://www.nayuki.io/page/fast-fibonacci-algorithms
*/
import java.math.BigInteger;
public final class FastFibonacci {
@sierikov
sierikov / histogram.hs
Last active August 5, 2021 11:35
Function histogram :: [Int] -> [Int] need to produce an infinite list of elements. The resulted list is formed so that the value at index of its element is a number of index occurrences in the input list. Example: histogram [1,4,2,2,2,1] will produce infinite list, which begins with [2,3,0,1,0,0,0,0,0,0]
-- [1,4,2,2,2,1] -> [2,3,0,1,0,0,...]
histogram :: [Int] -> [Int]
histogram xs = helper xs 1
helper :: [Int] -> Int -> [Int]
helper list index = (count list index) : (helper list (index+1))
count :: [Int] -> Int -> Int
count list element = length(filter (==element) list)
@sierikov
sierikov / football.hs
Last active November 22, 2020 20:09
A haskell program that calculates football score
strings :: [String]
strings = ["1:1", "1:10", "10:2"]
-- 1 - ничья (1:1)
-- 0 - поражение (0:2)
-- 2 - победа (3:0)
result :: Int
result = 0
@sierikov
sierikov / init.txt
Created November 5, 2020 20:25
Cloud init example file.
#cloud-config
hostname: lamp.rsm-live.de
locale: 'de_DE.UTF-8'
runcmd:
- "cd /root"
- "locale-gen"
- "export LANG=de_DE.UTF-8"
- "export LC_ALL=de_DE.UTF-8"
- "curl -O https://apt.puppetlabs.com/puppet6-release-bionic.deb"
- "dpkg -i puppet6-release-bionic.deb"
@sierikov
sierikov / main.scala
Created April 11, 2020 15:47
Crossover algorithm scala
object Main {
def main(args: Array[String]) {
val points: List[Int] = Lesson.points
var sequences = (Lesson.chr1, Lesson.chr2)
def crossingOver(first: List[Char], second: List[Char], start: Int) =
first.zip(second).zipWithIndex.map( x => if (x._2 >= start) x._1.swap else x._1).unzip
points.foreach(i => { sequences = crossingOver(sequences._1, sequences._2, i) })
@sierikov
sierikov / create.sql
Last active March 11, 2020 13:29
task 2.4
USE task2;
DROP TABLE IF EXISTS course;
DROP TABLE IF EXISTS student;
DROP TABLE IF EXISTS teacher;
DROP TABLE IF EXISTS marks;
DROP TABLE IF EXISTS group;
@sierikov
sierikov / fib.hs
Created February 25, 2020 15:31
Difference between functional and recursion fibonacci algorithm
fibonacci :: Integer -> Integer
fibonacci 0 = 0
fibonacci n
| n > 0 = helper (n-1) 0 1
| otherwise = helper (n+1) 0 1
helper :: Integer -> Integer -> Integer -> Integer
helper 0 prev cur = cur
helper term prev cur
| term > 0 = helper (term - 1) (cur) (prev + cur)