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
[2,3,5,6,7,9].permutation(3).map {|e| e.join.to_i % 5 == 0 }.count { |i| i == true } |
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
def cut_string(text, length, ending) | |
text[0...length].strip + ending | |
end | |
# forma de uso | |
texto = "meu texto é muito comprido, por isso eu preciso de um metodo que minimize ele" | |
cut_string(texto, 10, "...") # "meu texto ..." |
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
# -*- coding: utf-8 -*- | |
class Stack < Array | |
end | |
class Calculator | |
def initialize | |
@stack = Stack.new | |
end | |
def eval(expr) |
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
/*************************************************************************** | |
* Pequena implementação da calculadora "dc" do GNU/Linux * | |
* Copyright (C) 2009 by Claudemiro Alves Feitosa Neto * | |
* dimiro1@gmail.com * | |
* * | |
* This program is free software: you can redistribute it and/or modify * | |
* it under the terms of the GNU General Public License as published by * | |
* the Free Software Foundation, either version 3 of the License, or * | |
* (at your option) any later version. * | |
* * |
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
/*************************************************************************** | |
* Pequena implementação da calculadora "dc" do GNU/Linux * | |
* Não é uma implementação para calculos de alta precisão * | |
* Copyright (C) 2009 by Claudemiro Alves Feitosa Neto * | |
* dimiro1@gmail.com * | |
* Modified: <2009-05-21 20:58:52 BRT> * | |
* * | |
* This program is free software: you can redistribute it and/or modify * | |
* it under the terms of the GNU General Public License as published by * | |
* the Free Software Foundation, either version 3 of the License, or * |
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
#!/usr/bin/env ruby |
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
class Person | |
def initialize(name) | |
@name = name | |
end | |
def name | |
@name | |
end | |
def hello |
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
module Paperclip | |
class Watermark < Processor | |
class InstanceNotGiven < ArgumentError; end | |
def initialize(file, options = {},attachment = nil) | |
super | |
puts attachment.to_yaml | |
@file = file | |
@current_format = File.extname(@file.path) |
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
class Photo < ActiveRecord::Base | |
belongs_to :album | |
named_scope :covers, :conditions => {:cover => true} | |
has_attached_file :image, | |
:storage => :s3, | |
:s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml", | |
:path => ":attachment/:id/:style/:basename.:extension", | |
:styles => { | |
:original => {:geometry => "500x375>", :processors => [:thumbnail, :watermark], :quality => :better }, |
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
class ErbEngine < Haml::Engine | |
def push_script(text, preserve_script, in_tag = false, preserve_tag = false, | |
escape_html = false, nuke_inner_whitespace = false) | |
push_text "<%= #{text.strip} %>" | |
end | |
def push_silent(text, can_suppress = false) | |
push_text "<% #{text.strip} %>" | |
end | |
end |