Skip to content

Instantly share code, notes, and snippets.

@soeirosantos
soeirosantos / sort.go
Last active July 13, 2019 21:02
Kahn’s algorithm for Topological Sorting
package sort
import (
"errors"
)
func TopologicalSort(g *Graph) ([]int, error) {
inDegree := make([]int, g.numOfVertices)
for _, l := range g.graph {
@soeirosantos
soeirosantos / search.go
Created July 13, 2019 02:20
Binary Search in Go
package search
func BinarySearch(arr []int, target int) int {
start := 0
end := len(arr) - 1
for start <= end {
midPos := (start + end) / 2
if target < arr[midPos] {
end = midPos - 1
} else if target > arr[midPos] {
@soeirosantos
soeirosantos / runge_kutta.py
Created February 21, 2019 05:31
Runge-Kutta 2nd and 4th order comparison
'''
Numerical methods for ordinary differential equations are
methods used to find numerical approximations to the solutions
of ordinary differential equations (ODEs). Their use is also
known as "numerical integration", although this term is sometimes
taken to mean the computation of integrals.
The Runge–Kutta methods are a family of implicit and explicit
iterative methods used in temporal discretization for the approximate
solutions of ordinary differential equations.
class Node:
def __init__(self, value=None):
self.value = value
self.next = None
def __repr__(self):
return "Node(value=%s,next=%s)" % (self.value, self.next)
from tweepy import OAuthHandler, API
from nltk.corpus import stopwords
from textblob import TextBlob
import re
import json
class TwitterClient(object):
def __init__(self):
#!/usr/bin/env python
class TreeNode:
def __init__(self):
self.value = None
self.left = None
self.right = None
self.size = 0
from random import randint
def quick_sort(arr, start, end):
if start >= end:
return arr
pivot_idx = partition(arr, start, end)
quick_sort(arr, start, pivot_idx - 1)
quick_sort(arr, pivot_idx + 1, end)
@soeirosantos
soeirosantos / README.md
Last active December 2, 2018 20:14
Playing around with KSQL and KSQL JDBC Driver

Playing around with KSQL and KSQL JDBC Driver

Start by initializing the environment

$ docker-compose up broker ksql-cli

Connect to the KSQL CLI:

$ docker-compose exec ksql-cli ksql http://ksql-server:8088
@soeirosantos
soeirosantos / kubelog.sh
Last active July 28, 2018 16:02
Quick access to the Pod's log based on the name of the app.
#!/bin/sh
# Quick access to the Pod's log based on the name of the app.
# Please, note that this script assumes you have a selector
# called "app" on your pod. If you want to use a different
# selector simply update the script
if [[ -z "$1" || -z "$2" ]]; then
echo "Please, provide an app name and namespace."
echo "Example: ./kubelog.sh name-of-app dev"
exit 1
/**
It's a dummy example about how to synchronize the KafkaConsumer accross threads in scala.
"The Kafka consumer is NOT thread-safe. All network I/O happens in the thread of the
application making the call. It is the responsibility of the user to ensure that multi-threaded
access is properly synchronized. Un-synchronized access will result in ConcurrentModificationException."
- https://kafka.apache.org/0100/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#multithreaded
*/