Skip to content

Instantly share code, notes, and snippets.

View rodrigopr's full-sized avatar

Rodrigo Ribeiro rodrigopr

View GitHub Profile
history = [] # previous labels
for i, word in enumerate(sentence):
featureset = get_features(word, history, sentence, i)
label = predict(featureset)
history.append(label)
... remain processing
# Description:
# This script receives pages in the formats
# /usr/bin/curl -d host="$HOSTALIAS$" -d output="$SERVICEOUTPUT$" -d description="$SERVICEDESC$" -d type=service -d state="$SERVICESTATE$" $CONTACTADDRESS1$
# /usr/bin/curl -d host="$HOSTNAME$" -d output="$HOSTOUTPUT$" -d type=host -d state="$HOSTSTATE$" $CONTACTADDRESS1$
#
# Author:
# oremj
irc = require('irc')
# Description:
# This script receives pages in the formats
# /usr/bin/curl -d host="$HOSTALIAS$" -d output="$SERVICEOUTPUT$" -d description="$SERVICEDESC$" -d type=service -d notificationtype="$NOTIFICATIONTYPE$ -d state="$SERVICESTATE$" $CONTACTADDRESS1$
# /usr/bin/curl -d host="$HOSTNAME$" -d output="$HOSTOUTPUT$" -d type=host -d notificationtype="$NOTIFICATIONTYPE$" -d state="$HOSTSTATE$" $CONTACTADDRESS1$
#
# Based on a gist by oremj (https://gist.github.com/oremj/3702073)
#
# Configuration:
# HUBOT_NAGIOS_URL - https://<user>:<password>@nagios.example.com/cgi-bin/nagios3
#
trait Facade[A] {
def decode(json: String): A
}
trait DecodeJson[A] {
def apply(json: String): A
}
implicit def toDecode[A](implicit facade: Facade[A]): DecodeJson[A] = {
new DecodeJson[A] {

Instead of using TurnJsonIntoHttp in each place:

class MyEndpoint extends Endpoint[HttpRequest, HttpResponse] {
  def route = {
    case Method.Get -> Root / "items" 
      List() ! TurnJsonIntoHttp[List[MyObj]]

    case Method.Get -> Root / "item" / Long(id) 
      GetDetail(id) ! TurnJsonIntoHttp[MyObj]
 
class FormatEncoder[Encoder <: EncodeResponse[_]] {
def encoder[A]: Encoder[A] = implicitly[Encoder[A]] // implicit encode must be in scope =/
}
class Formats(encoders: (String, FormatEncoder[_])*, defaultFormat: String) {
private val formatsHash = encoders.toMap
private val default = formatsHash(defaultFormat)
def encodeFor[A](httpReq: HttpRequest): EncodeResponse[A] = formatsHash.getOrElse(???, default).encoder[A]
}
import com.twitter.finagle.{Filter, Service}
import com.twitter.finagle.http.{Request HttpRequest, Response HttpResponse}
import com.twitter.util.Future
import io.finch.{HttpRequest HttpxRequest, HttpResponse HttpxResponse}
import org.jboss.netty.handler.codec.http.{HttpResponse NettyHttpResponse}
/**
* Convert from finagle new `Httpx` to the `Http` representation
*
* This is required to make `httpx` services compatible
@rodrigopr
rodrigopr / gist:414e5311fb7ddb70effa
Last active August 29, 2015 14:21
Flask installable module draft
class Resource(object):
def __init__(self, path, type): ...
def install(self, destination_map): ...
class ExModule(FlaskModule):
@property
def blueprints(self):
return [app, admin]
@property
/**
* This file is licensed to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2013-06-25_14:35:37.51497 org.elasticsearch.transport.TransportSerializationException: Failed to deserialize exception response from stream
2013-06-25_14:35:37.51497 at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:171)
2013-06-25_14:35:37.51497 at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:125)
2013-06-25_14:35:37.51497 at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
2013-06-25_14:35:37.51497 at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:558)
2013-06-25_14:35:37.51497 at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:786)
2013-06-25_14:35:37.51497 at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296)
2013-06-