Skip to content

Instantly share code, notes, and snippets.

@maliqq
maliqq / broker.go
Last active November 22, 2018 08:53
Golang message broker
package protocol
import (
"fmt"
"log"
)
// pubsub
type Broker struct {
Send map[string]*chan *Message
@maliqq
maliqq / sberbank.rb
Last active December 23, 2016 23:41
текстовая выписка сбербанка -> csv
# 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
@maliqq
maliqq / StateMonad.scala
Created December 2, 2016 02:42 — forked from channingwalton/StateMonad.scala
State Monad and Validation with Scalaz
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)
### Usage example
Publisher = Struct.new(:name)
Book = Struct.new(:publisher)
Review = Struct.new(:book)
def Review.publisher
book.publisher
end
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)
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)> {
import (
"math"
)
type Currency struct {
Name string // "US Dollar"
IsoCode string // "USD"
Precision int // 2
}
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
[]
@maliqq
maliqq / gist:5244932
Created March 26, 2013 12:11
github languages (full)
JavaScript 1
Ruby 2
Java 3
Python 4
Shell 5
PHP 6
C 7
C++ 8
Perl 9
Objective-C 10
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