This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import functools | |
| import operator | |
| def fat(n): | |
| return functools.reduce(operator.mul, range(1, n + 1), 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Crawler.kt | |
| import kotlinx.coroutines.* | |
| import org.json.JSONObject | |
| import org.jsoup.Jsoup | |
| import org.jsoup.nodes.Document | |
| import org.jsoup.nodes.Element | |
| import org.jsoup.select.Elements | |
| class Crawler { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| limit = 10000 # Max attempt number: 14 (log2 10000) | |
| numbers = list(range(limit)) | |
| def find(number): | |
| begin = 0 | |
| end = len(numbers) - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.apache.flink.api.common.functions.ReduceFunction | |
| import org.apache.flink.streaming.api.TimeCharacteristic | |
| import org.apache.flink.streaming.api.windowing.triggers.{TriggerResult, _} | |
| import org.apache.flink.streaming.api.windowing.windows.TimeWindow | |
| case class FlinkCountWindowWithTimeout[W <: TimeWindow](maxCount: Long, timeCharacteristic: TimeCharacteristic) extends Trigger[Object, W] { | |
| private val serialVersionUID = 1L | |
| import org.apache.flink.api.common.state.ReducingStateDescriptor | |
| import org.apache.flink.api.common.typeutils.base.LongSerializer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.circe.{Decoder, Encoder} | |
| import io.circe.parser.decode | |
| import io.circe.syntax._ | |
| import org.apache.flink.api.common.serialization.{DeserializationSchema, SerializationSchema} | |
| import org.apache.flink.api.java.typeutils.TypeExtractor | |
| import scala.reflect.ClassTag | |
| /* Generic Flink schema to encode/decode json with Circe */ | |
| case class FlinkCirceSchema[A <: AnyRef : ClassTag]()(implicit decoder: Decoder[A], encoder: Encoder[A]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.concurrent.Future | |
| object AdvancedRecap extends App { | |
| // partial functions | |
| val partialFunction: PartialFunction[Int, Int] = { | |
| case 1 => 42 | |
| case 2 => 65 | |
| case 5 => 999 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ObjectDiff { | |
| private static final Logger LOG = LoggerFactory.getLogger(ObjectDiff.class); | |
| public Map<String, Map<String, Object>> getDiff(Object oldObject, Object newObject) { | |
| Map<String, Map<String, Object>> diff = new HashMap<>(); | |
| if (oldObject == null && newObject != null) { | |
| Map<String, Object> objectDiff = new HashMap<>(); | |
| String objectName = newObject.getClass().getSimpleName(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| RECURSION_LIMIT = 5500000 | |
| # Não faça isso em prod :) | |
| sys.setrecursionlimit(RECURSION_LIMIT) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def hello(): | |
| ola() | |
| print("Hello!") | |
| def ola(): | |
| hola() | |
| print("Olá!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def shapeArea(n): | |
| result = 0 | |
| while n > 1: | |
| result += 4 * (n - 1) | |
| n -= 1 | |
| return result + 1 |
NewerOlder