Skip to content

Instantly share code, notes, and snippets.

View dimiro1's full-sized avatar

Claudemiro A F Neto dimiro1

  • Berlin, Germany
View GitHub Profile
// NormalizeString remove noise chars
// https://blog.golang.org/normalization
// See http://www.fileformat.info/info/unicode/category/index.htm
// No formato NFC cada caractere é representado por um único simbolo
// ex: "é"" no formato NFC == "\u00e9""
// No formato NFD o mesmo caractere é representado por "e\u0301"
// Após converter para NFD fica fácil remover os caracteres extras, apenas passando de byte a byte
// Ao final é necessária a conversão para o formato normalizado NFKD que trata caracteres semelhantes
// como sendo o mesmo símbolo: ex: 'Ω' ("\u03a9") e 'Ω' (Ohm sign "\u2126") podem ser considerados a mesma coisa
func NormalizeString(s string) (string, error) {
@dimiro1
dimiro1 / fbp.go
Created September 15, 2016 03:21
package main
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"time"
"github.com/rs/xlog"
package main
import (
"fmt"
"context"
)
func reverse(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
{"paragraphs":[{"text":"import org.apache.commons.io.IOUtils\nimport java.net.URL\nimport java.nio.charset.Charset\n\n// Zeppelin creates and injects sc (SparkContext) and sqlContext (HiveContext or SqlContext)\n// So you don't need create them manually\n\n// load bank data\nval bankText = sc.parallelize(\n IOUtils.toString(\n new URL(\"https://s3.amazonaws.com/apache-zeppelin/tutorial/bank/bank-full.csv\"),\n Charset.forName(\"utf8\")).split(\"\\n\"))\n\ncase class Bank(age: Integer, job: String, marital: String, education: String, balance: Integer)\n\nval bank = bankText.map(s => s.split(\";\")).filter(s => s(0) != \"\\\"age\\\"\").map(\n s => Bank(s(0).toInt, \n s(1).replaceAll(\"\\\"\", \"\"),\n s(2).replaceAll(\"\\\"\", \"\"),\n s(3).replaceAll(\"\\\"\", \"\"),\n s(5).replaceAll(\"\\\"\", \"\").toInt\n )\n).toDF()\nbank.registerTempTable(\"bank\")","dateUpdated":"2016-06-28T11:13:53+0000","config":{"colWidth":12,"graph":{"mode":"table
@dimiro1
dimiro1 / stackdump-shopify-go-lua.lua
Created May 29, 2016 17:01
Stack Dump Shopify-Go-lua
func stackDump(l *lua.State) {
n := l.Top()
fmt.Println("-------------------- Stack Dump -------------------")
fmt.Printf("Total in stack: %d\n", n)
for i := 1; i <= n; i++ {
fmt.Printf("%d: ", i)
switch l.TypeOf(i) {
func escapeQuery(s string) string {
s1 := regexp.QuoteMeta(s)
re := regexp.MustCompile("\\s+")
s1 = strings.TrimSpace(re.ReplaceAllString(s1, " "))
return s1
}
@dimiro1
dimiro1 / Preferences-sublime.js
Created February 12, 2016 10:51
Preferences Sublime
{
"color_scheme": "Packages/Theme - Spacegray/base16-eighties.dark.tmTheme",
"folder_exclude_patterns":
[
".svn",
".git",
".hg",
"CVS",
".idea",
"tmp",
@dimiro1
dimiro1 / application.go
Last active April 10, 2017 03:52
Implementation of the Thrift Servlet with golang net/http handler function
// Copyright (c) 2016, Claudemiro Alves Feitosa Neto
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@dimiro1
dimiro1 / calculator.thrift
Last active December 30, 2015 20:37
Implementation of the Thrift Servlet with Clojure Ring/compojure - A Working example https://github.com/dimiro1/thrift-clojure-example
service Calculator {
i64 sum(1: i64 a, 2: i64 b)
}
var thing = {n: 0};
function inc(param) {
param.n++;
}
inc(thing);
console.log(thing.n);