This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package protocol | |
import ( | |
"fmt" | |
"log" | |
) | |
// pubsub | |
type Broker struct { | |
Send map[string]*chan *Message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
def parse_date(s) | |
map = {'ЯНВ' => 1, 'ФЕВ' => 2, 'МАР' => 3, 'АПР' => 4, 'МАЙ' => 5, 'ИЮН' => 6, 'ИЮЛ' => 7, 'АВГ' => 8, 'СЕН' => 9, 'ОКТ' => 10, 'НОЯ' => 11, 'ДЕК' => 12} | |
s =~ /^(\d+)(.+?)(\d+)$/ | |
Date.new($3.to_i + 2000, map[$2], $1.to_i) | |
end | |
require 'csv' | |
str = CSV.generate do |csv| | |
while line = gets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
import Scalaz._ | |
/** | |
* Use the state monad to 'process a trade' and store the new trade. | |
* As well as processing the trade, handle validation errors. | |
*/ | |
object StateMonad extends App { | |
case class Trade(info: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Usage example | |
Publisher = Struct.new(:name) | |
Book = Struct.new(:publisher) | |
Review = Struct.new(:book) | |
def Review.publisher | |
book.publisher | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final val TypeField = "$type" | |
final val ObjectField = "$object" | |
def encode[T <: Message](msg: T): Array[Byte] = { | |
val schema: protostuff.Schema[T] = msg.schema.asInstanceOf[protostuff.Schema[T]] | |
val out = new java.io.ByteArrayOutputStream | |
val context = new org.codehaus.jackson.io.IOContext(protostuff.JsonIOUtil.DEFAULT_JSON_FACTORY._getBufferRecycler(), out, false); | |
val generator = protostuff.JsonIOUtil.newJsonGenerator(out, context.allocWriteEncodingBuffer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group java_bean_model_schema : java_bean_model_base; | |
message_block(message, module, options, nested) ::= << | |
<if(!nested)> | |
<message:message_header(message=it, module=module, options=options)> | |
<endif> | |
public <if(nested)>static <endif>class <remote_model_schema_name(message=message, name=message.name)> | |
<options.(message.name + ".extends_schema_declaration"); format=" "> | |
<message:message_impl_declaration(message=it, options=options)> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"math" | |
) | |
type Currency struct { | |
Name string // "US Dollar" | |
IsoCode string // "USD" | |
Precision int // 2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1,2,3,5,6,7,10,11,12,14,15] | |
def split_gaps(a) | |
gaps = [] | |
buffer = a.inject([]) { |buffer, item| | |
prev = buffer[buffer.size - 1] | |
if prev && item - prev > 1 | |
gaps << buffer | |
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JavaScript 1 | |
Ruby 2 | |
Java 3 | |
Python 4 | |
Shell 5 | |
PHP 6 | |
C 7 | |
C++ 8 | |
Perl 9 | |
Objective-C 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'active_support/all' | |
def traverse(nodes, tabs = 0) | |
nodes.each do |node| | |
unless node.is_a? Nokogiri::XML::Element | |
if node.is_a?(Nokogiri::XML::Text) | |
puts ' ' * tabs + node.content.sub(/^\s+/, '').inspect if node.content !~ /^\s+$/ | |
end | |
next |
NewerOlder