Skip to content

Instantly share code, notes, and snippets.

View marquesds's full-sized avatar
🤖
about:robots

Lucas Marques marquesds

🤖
about:robots
View GitHub Profile
@marquesds
marquesds / fatorial_reduce.py
Created February 22, 2022 01:07
Fatorial algorith using reduce function
import functools
import operator
def fat(n):
return functools.reduce(operator.mul, range(1, n + 1), 1)
@marquesds
marquesds / Skrotlin.kt
Created March 2, 2021 12:44
A simple web scraping with Kotlin
// 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 {
@marquesds
marquesds / binary_search.py
Last active May 21, 2020 17:14
Binary search
import random
limit = 10000 # Max attempt number: 14 (log2 10000)
numbers = list(range(limit))
def find(number):
begin = 0
end = len(numbers) - 1
@marquesds
marquesds / FlinkCountWindowWithTimeout.scala
Created March 24, 2020 19:14
Flink count window with timeout
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
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])
import scala.concurrent.Future
object AdvancedRecap extends App {
// partial functions
val partialFunction: PartialFunction[Int, Int] = {
case 1 => 42
case 2 => 65
case 5 => 999
}
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();
import sys
RECURSION_LIMIT = 5500000
# Não faça isso em prod :)
sys.setrecursionlimit(RECURSION_LIMIT)
def hello():
ola()
print("Hello!")
def ola():
hola()
print("Olá!")
def shapeArea(n):
result = 0
while n > 1:
result += 4 * (n - 1)
n -= 1
return result + 1