Skip to content

Instantly share code, notes, and snippets.

@felipehummel
felipehummel / AnimaErpServiceInterface.php
Last active August 29, 2015 13:57
erp webservice test
<?php
namespace Anima\Core\Services;
interface AnimaErpDataObject {
public function validate();
public function toArray();
}
class AnimaErpPayment implements AnimaErpDataObject
@felipehummel
felipehummel / curl_new_relic_bug.php
Last active August 29, 2015 13:59
New Relic CURL PHP bug
<?php
/**
* php --version
PHP 5.4.25-1+sury.org~precise+2 (cli) (built: Feb 12 2014 10:45:30)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
**/
$headers = [];
object Test {
def main(args: Array[String]): Unit = {
import org.json4s._
import org.json4s.JsonDSL._
import org.json4s.native.JsonMethods._
import org.json4s.native.Serialization
import org.json4s.native.Serialization.{ read, write, writePretty }
sealed trait Test
case object TestA extends Test
case object TestB extends Test
@felipehummel
felipehummel / TestJava.java
Last active August 29, 2015 14:06
ElasticSearch Scala/Java client SignificantTerms problem
package com.busk.searching;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsBuilder;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.elasticsearch.search.aggregations.AggregationBuilders.*;
{
"results":[{
"articles":[{
"id":131720411,
"created_at":"2014-11-03 18:34:53",
"type":"articles",
"title":"Apucarana: Polícia Militar evita mais quatro golpes do falso sequestro",
"language_code":"pt",
"url":"http://www.tnonline.com.br/noticias/apucarana/45,304044,03,11,apucarana-policia-militar-evita-mais-quatro-golpes-do-falso-sequestro.shtml",
"published_at":"2014-11-03 18:34:18",
// Construtor da classe é (nome: String)
class MinhaClasse(nome: String) {
def olaQuem() = s"Olá $nome!"
}
val minha = new MinhaClasse("Felipe")
val msg = minha.olaQuem()
println(msg) // Olá Felipe!
@felipehummel
felipehummel / result.json
Created February 6, 2015 14:00
example json
{
"results":[{
"articles":[{
"id":147239368,
"created_at":"2015-02-06 13:49:11",
"type":"articles",
"title":"INVESTOR ALERT: Levi & Korsinsky, LLP Commences an Investigation of the Board of Directors of Hospira Inc. In Connection With the Fairness of the Sale of the Company to Pfizer -- HSP",
"language_code":"en",
"url":"http://www.benzinga.com/pressreleases/15/02/n5218605/investor-alert-levi-korsinsky-llp-commences-an-investigation-of-the-boa",
"published_at":"2015-02-06 13:41:48",
@felipehummel
felipehummel / article.json
Last active August 29, 2015 14:14
article example
{
"id":147061902,
"created_at":"2015-02-05 15:30:30",
"type":"articles",
"title":"Why Pfizer wants Hospira",
"language_code":"en",
"url":"http://www.cnbc.com/id/102400727",
"content":"<div class=\"group\" itemprop=\"articleBody\" gravityscore=\"162\" gravitynodes=\"6\">\n <p> Hospira makes biosimilars as well. Its injectable and infused pharmaceuticals business includes about 200 generic drugs, like the antibacterials azithromycin and ceftazidime, and the anticoagulant heparin sodium. </p>\n <p>Hospira has also been in the news in recent years as the only U.S. maker of drugs used in lethal injection. (The company said in 2011 it would stop making the anesthetic, <a class=\"inline_asset\" href=\"http://www.nytimes.com/2011/01/22/us/22lethal.html?_r=1&amp;\" target=\"_blank\">sodium thiopental</a>, because it didn't have U.S. manufacturing capabilities for it, and it had run into opposition in Italy.)</p>\n <p> Read More<a href=\"/id/102396903\" target=\"_self\">Pricing wars heat up over hepatitis
package com.busk.searchserver.api
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.scalatra.ScalatraBase
import org.scalatra.auth.strategy.{BasicAuthStrategy, BasicAuthSupport}
import org.scalatra.auth.{ScentryConfig, ScentrySupport}
/**
* Created by felipehummel on 12/01/15.
@felipehummel
felipehummel / json.scala
Created July 23, 2015 14:53
json default field
object JsonExtensions {
def withDefaultCreatedAt[T](base: Format[T]) = new Format[T]{
def reads(json: JsValue): JsResult[T] = base.compose(JsonExtensions.withDefault("createdAt", DateTime.now())).reads(json)
def writes(o: T): JsValue = base.writes(o)
}
def withDefault[A](key:String, default:A)(implicit writes:Writes[A]) =
__.json.update((__ \ key).json.copyFrom((__ \ key).json.pick orElse Reads.pure(Json.toJson(default))))
}
// .....