Skip to content

Instantly share code, notes, and snippets.

@ilobko
ilobko / Set Window Width 1280.workflow
Created August 9, 2022 11:15
AppleScript that resizes current window. Can be used as a Quick Action (App Menu -> Services -> Set Window Width 1280)
set windowWidth to 1280
set currentApplication to (path to frontmost application as Unicode text)
tell application currentApplication
set windowBounds to bounds of the front window
set upperLeftX to item 1 of windowBounds
set upperLeftY to item 2 of windowBounds
set lowerRightY to item 4 of windowBounds
set bounds of the first window to {upperLeftX, upperLeftY, upperLeftX + windowWidth, lowerRightY}
@ilobko
ilobko / longest_ladder.rb
Last active June 4, 2022 18:11
Найти в массиве самую длинную «лесенку» (последовательность идущих подряд чисел).
# longest_ladder([1,2,1,2,3,5,6,7,8,9,10,7,5,5,6])
# => [5,6,7,8,9,10]
def longest_ladder(arr)
arr.chunk_while { _2 == _1 + 1 }.max_by(&:length)
end
@ilobko
ilobko / square_every_digit.py
Created June 4, 2022 18:02
Возвести каждую цифру числа в квадрат (912 → 8114).
# Option 1
def square_digits(num):
return int(''.join(str(int(d)**2) for d in str(num)))
# Option 2
def square_digits(num):
ret = ""
for x in str(num):
ret += str(int(x)**2)
@ilobko
ilobko / name_shuffler.py
Last active June 4, 2022 17:59
Поменять местами слова в строке из двух слов (“Tom Jerry” → “Jerry Tom”).
# Option 1
def name_shuffler(s):
return ' '.join(s.split(' ')[::-1])
# Option 2
def name_shuffler(s):
return ' '.join(reversed(s.split()))