Skip to content

Instantly share code, notes, and snippets.

View Sedose's full-sized avatar
:shipit:

Sedose Sedose

:shipit:
  • Ukraine
View GitHub Profile
--1st solution
select warehouse, count(warehouse) as number_of_boxes
from boxes
group by warehouse
union (
select code, '0'
from warehouses
where code not in (
select warehouse
from boxes
@Sedose
Sedose / .kt
Created April 3, 2022 17:01
Koltin map string to sequence of chars with previous ones. #kotlin loop with previous
fun String.withPrevious(): Sequence<Element> {
val string = this
return sequence {
for (i in string.indices) {
val current = string[i]
val previous = if (i > 0) string[i - 1] else null
yield(Element(current, previous))
}
}
}
@Sedose
Sedose / Commercetools.kt
Last active July 15, 2022 19:35
Commercetools code snippets
Remove cart by anonymousId
val carts = apiRoot.carts().get().addWhere(
"anonymousId = :anonymousCustomerId",
"anonymousCustomerId",
anonymousCustomerId
).execute().get().body.results
for (cart in carts) {
apiRoot.carts()
kubectl apply -f - <<EOF
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: trading-bot-gke-persistent-volume-claim
namespace: default
labels:
app: trading-bot-gke
component: master
spec:
@Sedose
Sedose / list_all_chats.pyt
Last active September 28, 2022 08:19
Telethon
import asyncio
from telethon.sync import TelegramClient, events
async def list_groups():
api_id = 111111111
api_hash = '11111111eeeeee'
phone = '+8111111111'
client = TelegramClient(phone, api_id, api_hash)
await client.connect()
@Sedose
Sedose / .kt
Created April 21, 2023 15:44
Leetcode. 49. Group Anagrams. Сгрупувати анаграми
fun main() {
val strs = arrayOf("eat", "tea", "tan", "ate", "nat", "bat", "aaaaab")
println(groupAnagramsRedundantly(strs))
}
fun groupAnagramsRedundantly(strings: Array<String>): List<List<String>> {
val groupedAnagramsMap = hashMapOf<Any, MutableList<String>>()
for (string in strings) {
val anagramKey = findAnagramKeyMutableListRepresentation(string)
val list = groupedAnagramsMap.getOrPut(anagramKey) { mutableListOf() }
@Sedose
Sedose / .kt
Created April 23, 2023 13:48
Leetcode. Top K Frequent Elements
fun topKFrequent(numbers: IntArray, k: Int): IntArray {
val map = numbers.toList().groupingBy { it }.eachCount()
val priorityQueue = PriorityQueue<Pair<Int, Int>>(compareBy { it.second })
map.forEach { (number, count) ->
priorityQueue.offer(Pair(number, count))
if (priorityQueue.size > k) {
priorityQueue.poll()
}
}
return IntArray(k) { priorityQueue.poll().first }
@Sedose
Sedose / print-project-structure.py
Created June 24, 2023 06:08
Print project structure of gradle koltin spring app
import os
def print_directory_tree(startpath):
for root, dirs, files in os.walk(startpath):
dirs[:] = [d for d in dirs if d not in ['gradle', 'build', '.idea', '.gradle']]
level = root.replace(startpath, '').count(os.sep)
indent = ' ' * 4 * (level)
print('{}{}/'.format(indent, os.path.basename(root)))
sub_indent = ' ' * 4 * (level + 1)
for f in files:
@Sedose
Sedose / requirements.txt
Created July 8, 2023 02:02
AI ML Python libs
tensorflow==2.7.0
scikit-learn==1.0.1
pandas==1.1.5
matplotlib==3.2.2
seaborn==0.11.2
@Sedose
Sedose / Single queue using 2 stacks.kt
Last active September 3, 2024 06:35
Single queue using 2 stacks impl for Leetcode problem
package org.example
fun main() {
createQueue(createStack(), createStack()).apply {
push(1)
push(2)
push(3)
pop()
peek()
pop()