Skip to content

Instantly share code, notes, and snippets.

View mxrguspxrt's full-sized avatar

Margus Pärt mxrguspxrt

View GitHub Profile
@mxrguspxrt
mxrguspxrt / chunky_png.rb
Created November 24, 2011 20:38
autocrop, colorize, solid color
# Usage:
#
# image1 = ChunkyPNG::Image.from_file('vase.png')
# image1.colorfy!(:color => "ff0000")
# image1.save 'changed_red.png'
#
# image2 = ChunkyPNG::Image.from_file('vase.png')
# image2.colorfy!(:color => "ff0000", :solid => true)
# image2.save 'only_red.png'
#
# atm its so for my class
class ApplicationController < ActionController::Base
extend ActiveSupport::Concern
protect_from_forgery
#enable_authorization
respond_to :html, :xml, :json
@mxrguspxrt
mxrguspxrt / gist:1539073
Created December 30, 2011 09:55
replace method object handled like a object
# example
class A
def a
puts "a"
end
def b
puts "b"
end
end
@mxrguspxrt
mxrguspxrt / help.rb
Created January 1, 2012 14:54
Undrestanding yield and scopes
# what should I do, that a() would run in context of class A, not give "block in <main>': undefined method `a' for main:Object (NoMethodError)"
class A
def a
puts "a"
end
end
class B
@mxrguspxrt
mxrguspxrt / classes_branches_diff.rb
Created March 21, 2012 12:10
Compare methods in different classes
def digest array
Digest::MD5.hexdigest array.to_s
end
def write file, array
File.open(file, 'w') { |f| f.write array.sort.to_json }
end
def read file
@mxrguspxrt
mxrguspxrt / timeline.rb
Created April 25, 2012 17:37
Timeline for executing blocks in different ranges
# Timeline is a Line that has beginning and the end, it contains many Frames with beginning and end.
module Timeline
# Range has the beginning, end and length.
class Range
attr_accessor :from, :length
attr_reader :to
def initialize from, length
class LuhnNumber
attr_accessor :full_number
def initialize(full_number)
self.full_number = full_number
end
def full_number=(full_number)
@full_number = full_number.gsub(/[^0-9]/, '').to_s
class Class
def instance_advices(include_super=true)
throw :never_thrown
end
end
class Test1
end
class Test3 < Test1
@mxrguspxrt
mxrguspxrt / tableless.rb
Created September 6, 2012 18:37
Rails Tableless
class Tableless
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::Validations
include ActiveModel::Conversion
include ActiveModel::MassAssignmentSecurity
def initialize(params={})
if params
sanitized_params = sanitize_for_mass_assignment(params)
@mxrguspxrt
mxrguspxrt / java2-home3.java
Created October 5, 2012 07:04
java2-home3.java
public class Answer {
public static void main (String[] argum) {
Answer answer = new Answer();
}
class Linked {
public int value;
public Linked parent;