Skip to content

Instantly share code, notes, and snippets.

View sanan-fataliyev's full-sized avatar

Sanan R. Fataliyev sanan-fataliyev

View GitHub Profile
@sanan-fataliyev
sanan-fataliyev / iso8601_year_week.sql
Created June 18, 2025 20:40
ISO 8601 year and week in sqlite
SELECT strftime('%Y-W%V', current_timestamp, '-3 days', 'weekday 4') as period;
#!/bin/python3
import math
import os
import random
import re
import sys
"""
Don't Get Volunteered!
======================
As a henchman on Commander Lambda's space station, you're expected to be resourceful, smart, and a quick thinker. It's not easy building a doomsday device and ordering the bunnies around at the same time, after all! In order to make sure that everyone is sufficiently quick-witted, Commander Lambda has installed new flooring outside the henchman dormitories. It looks like a chessboard, and every morning and evening you have to solve a new movement puzzle in order to cross the floor. That would be fine if you got to be the rook or the queen, but instead, you have to be the knight. Worse, if you take too much time solving the puzzle, you get "volunteered" as a test subject for the LAMBCHOP doomsday device!
To help yourself get to and from your bunk every day, write a function called solution(src, dest) which takes in two parameters: the source square, on which you start, and the destination square, which is where you need to land to solve the puzzle. The funct
def solution(s):
acc = s[0]
while len(acc) < len(s):
while len(s) % len(acc) != 0:
acc = s[:len(acc)+1]
steps = len(s) // len(acc)
for i in range(1, steps):
if s[i * len(acc):(i + 1) * len(acc)] != acc:
acc = s[:(i * len(acc))+1]
break
@sanan-fataliyev
sanan-fataliyev / reducebin.go
Created December 18, 2020 22:19
golang solution for reduce binary string problem
/*
Given a binary string str, the task is to print the numbers of steps required to convert it to one by the following operations:
If ‘S’ is odd add 1 to it.
If ‘S’ is even divide it by 2.
*/
package main
func main() {
@sanan-fataliyev
sanan-fataliyev / argsetter.go
Created October 6, 2020 09:04
testify helper method to set input argument
func argSetter(index int, newVal interface{}) func(args mock.Arguments) {
return func(args mock.Arguments) {
// get dest arg
dest := args.Get(index)
// inspect
ptr := reflect.ValueOf(dest)
// dereference
val := ptr.Elem()
// an in-place solution of Squares of a Sorted Array problem
// https://leetcode.com/problems/squares-of-a-sorted-array/
func sortedSquares(A []int) []int {
// [-3,-2,0, 1, 2]
size := len(A)
for i := 0; i < size; i++ {
A[i] *= A[i]
vowels = set('aıoueəiöüAIOUEƏİÖÜ')
def songify(line):
i = next(i for i in range(len(line)) if line[i] in vowels)
syllable = line[:i+1]
prefix = '-'.join([syllable] * 3)
return prefix + ' ' + line
lyrics = """
Nəşəni çəkdim
// JoinURLs joins base URL and paths safely
// No worries for extra or missing slashes
func JoinURLs(baseURL string, paths ...string) string {
if len(paths) == 0 {
return baseURL
}
joint := strings.TrimRight(baseURL, "/")
for _, path := range paths {
joint += "/" + strings.TrimLeft(path, "/")