Skip to content

Instantly share code, notes, and snippets.

View mtungusov's full-sized avatar

Mikhail Tungusov mtungusov

  • Serbia, Belgrade
View GitHub Profile
@mtungusov
mtungusov / gist:6251281
Created August 16, 2013 16:15
xmpp4r fix. REXML::ParseException #<Encoding::CompatibilityError: incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)
# coding: utf-8
def match( pattern, cons=false )
# Fix Start
@buffer = @buffer.force_encoding('utf-8')
# Fix Finish
rv = pattern.match(@buffer)
@buffer = $' if cons and rv
while !rv and @source
begin
@buffer << readline
@mtungusov
mtungusov / gist:6149492
Last active December 20, 2015 14:49
Struct Examples
# 1
class PeerConnected < Struct.new(:source_id, :ip, :port); end
# 2
Struct.new("Point", :x, :y) #=> Struct::Point
origin = Struct::Point.new(0,0) #=> #
# 3
class Point < Struct.new(:x, :y); end
origin = Point.new(0,0)
@mtungusov
mtungusov / memstats.rb
Created June 22, 2013 08:44
memstats for Ruby Process in OS X
def memstats
`ps -o rss #{$$}`.strip.split(' ').last.to_i
end