Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
import itertools as it
class IterableListNode(ListNode):
@classmethod
def from_ListNode(cls, list_node):
@sztamas
sztamas / eredmeny.txt
Last active October 18, 2020 11:57
Matek feladat
0
2 4
6 8 10
12 14 16 18
20 22 24 26 28
30 32 34 36 38 40
42 44 46 48 50 52 54
56 58 60 62 64 66 68 70
72 74 76 78 80 82 84 86 88
90 92 94 96 98 100 102 104 106 108
@sztamas
sztamas / fizz_buzz.clj
Last active September 10, 2020 16:04
FizzBuzz without ifs
;; First solution
(defn fizz-buzz-or-number
[x]
(
["FizzBuzz" x x "Fizz" x "Buzz" "Fizz" x x "Fizz" "Buzz" x "Fizz" x x]
(mod x 15)))
(defn fizz-buzz
@sztamas
sztamas / george.clj
Created August 5, 2020 04:50
The Frugal Gentleman
(defn select-georges-wine [wines]
(condp = (count wines)
0 nil
1 (first wines)
(second (sort-by :price wines))))
(def choose-wine (comp :name select-georges-wine))
@sztamas
sztamas / python_deep_eq.py
Created August 29, 2019 09:01
Python == is deep
In [4]: l = [{'x': [254, 247, 230, 225, 222, 221, 231, 247, 281, 314, 381, 461, 487, 508, 517
...: , 504, 460, 431, 380, 346, 318, 301, 305, 309, 328, 359, 400, 413, 438, 441, 447, 472
...: , 490, 511, 519, 529, 529], 'y': [26, 25, 26, 28, 32, 37, 51, 58, 59, 56, 44, 34, 34,
...: 34, 35, 46, 60, 66, 75, 83, 91, 99, 101, 102, 105, 105, 105, 106, 110, 113, 116, 116
...: , 116, 116, 116, 112, 107]}, {'x': [479], 'y': [123]}, {'x': [20, 24, 27, 34, 45, 48,
...: 51, 59, 67, 71, 76, 80, 97, 108], 'y': [46, 48, 51, 58, 69, 72, 75, 82, 86, 87, 88,
...: 89, 93, 96]}, {'x': [619, 619, 620, 620, 620, 620], 'y': [29, 37, 41, 50, 55, 64]}]
...:
In [5]: l2 = [{'x': [254, 247, 230, 225, 222, 221, 231, 247, 281, 314, 381, 461, 487, 508, 51
#!/usr/bin/env python
import boto3
ec2 = boto3.resource('ec2')
FMT = '{sg.group_id},{sg.group_name},"{sg.description}"'
@sztamas
sztamas / bash
Last active September 5, 2018 10:48
PYPI and HTTP proxies for development machines
docker run \
-h 'squid' --net bridge -m 0b -p 3128:8000 \
-d \
-v /srv/squid:/data \
-v /etc/localtime:/etc/localtime:ro \
-e USE_ACL=0 \
--name squid \
--restart=always \
muccg/squid-deb-proxy:latest
"""
All credits to https://github.com/andreif/codegen/blob/master/codegen.py
Just quicly edited everything in place to transform python conditional expressions to their JS equivalent.
Scroll to the bottom of the file for examples.
"""
from ast import *
BINOP_SYMBOLS = {}
(defn product
([] [])
([xs] (if (empty? xs) [] (seq xs)))
([xs & rest]
(for [x xs p (apply product rest)] (flatten (list x p)))))
(defn endless-product [xs]
(let [repeat-xs (map #(repeat % xs) (drop 1 (range)))]
(apply concat (map #(apply product %) repeat-xs))))
(defmacro product [xs dim]
"Creates a dim dimension cartesian product of the xs sequence.
For example (product \"ab\" 3) returns ((a a a) (b a a) (a b a) ...)"
(let [syms (take dim (repeatedly gensym))
seq-expr (vec (interleave syms (repeat xs)))
body-expr (cons 'list syms)]
(list 'for seq-expr body-expr)))