Skip to content

Instantly share code, notes, and snippets.

@soeirosantos
soeirosantos / Main.java
Created August 21, 2016 03:32
check palindromes with some tolerance indicated by totalCharsToCheck
package br.com.soeirosantos;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
System.out.println(isAlmostPalindrome("abcddcba", 0));
@soeirosantos
soeirosantos / ycombinator_word_counter.py
Last active October 31, 2016 21:25
A very simple and dummy word counter
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import feedparser, operator
import re
from stop_words import get_stop_words
from time import gmtime, strftime
stop_words = get_stop_words('en')
OUTPUT_FOLDER = 'out/'
@soeirosantos
soeirosantos / Main1.java
Last active November 3, 2016 14:38
About BigDecimal
double fixedCost = 0.1;
double variableCost = 0.7;
double totalCost = fixedCost + variableCost;
System.out.println(totalCost);
//output: 0.7999999999999999
Integer[] array = {1, 1, 1, 2, 2, 2, 4, 4, 1, 1, 2, 5, 5,};
Map<Integer, Long> collect =
Arrays.stream(array).collect(
Collectors.groupingBy(Function.identity(), Collectors.counting()));
buildscript {
ext {
versions = [
gradle : '3.2.1',
springBoot : '1.4.3.RELEASE',
springfox : '2.6.1',
lombok : '1.16.10',
lombok_plugin : '1.6',
commons_io : '2.5',
commons_lang : '3.4',
package com.todevornot.hncounter
import com.rometools.rome.io.SyndFeedInput
import com.rometools.rome.io.XmlReader
import java.net.URL
val HN_URL = URL("https://news.ycombinator.com/bigrss")
fun main(args: Array<String>) {
@soeirosantos
soeirosantos / Async.md
Created October 17, 2017 13:05
Async functions in a usage context

Async functions in a usage context

The task we want to accomplish in this example is, given a URL and a file system path, download the document content and save it in the file system.

Let's begin our example by using the modules request and fs to perform the task directly:

const request = require('request')
const fs = require('fs')
@soeirosantos
soeirosantos / README.md
Last active June 15, 2018 02:40
Create a local Kafka cluster for studying and experimentation - It's a Kafka 0.10 cluster but you can install a most recent version changing the lines 12 and 13

If you are playing around with Kafka you, probably, would prefer to use containers. But, for some reason, you may want to use VMs instead. With this Vagrant script you can get a cluster installed and configured locally with a few steps.

Note that this script doesn't use the most recent version of Kafka. But you can change the version by changing the lines 12 and 13 of the script. Check the Confluent Platform and Apache Kafka Compatibilty table for details.

Instructions to execute and test

  1. Install Virtual Box https://www.virtualbox.org/

  2. Install Vagrant >= 1.6.4 http://www.vagrantup.com/

@soeirosantos
soeirosantos / gke_persistent_volumes.md
Last active March 27, 2024 00:25
Playing around with persistent volumes on Google Kubernetes Engine

GKE Persistent Volumes

Let's play around with persistent volumes on GKE.

Setup stuff

$ gcloud init
<output_omitted>
/**
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
*/