This file contains hidden or 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 generate_token(length=8) | |
| alphanumerics = ('a'..'z').to_a.concat(('A'..'Z').to_a.concat(('0'..'9').to_a)) | |
| self.token = alphanumerics.sort_by{rand}.to_s[0..length] | |
| # Ensure uniqueness of the token.. | |
| generate_token unless Widget.find_by_token(self.token).nil? | |
| end |
This file contains hidden or 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
| # populate test database before running tests | |
| Rake::Task["db:test:prepare"].enhance do | |
| Customer.establish_connection "test" | |
| Domain.establish_connection "test" | |
| PopulationHelper.populate | |
| end |
This file contains hidden or 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
| # Controllers | |
| class PostController | |
| before_filter :set_entry | |
| def create | |
| @entry.comments.create!(params.merge(author: @current_user)) | |
| end | |
| protected |
This file contains hidden or 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 Object | |
| def def(method, &b) | |
| self.class.send(:define_method, method, &b) | |
| end | |
| end |
This file contains hidden or 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
| #DIS IS SPARTA! | |
| class Module | |
| def method_missing(*args, &block) | |
| const_get(*args) | |
| rescue | |
| super(*args, &block) | |
| end | |
| end |
This file contains hidden or 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 'rails' | |
| module OtherModule | |
| def self.included(base) | |
| base.extend(ClassMethods) | |
| end | |
| module ClassMethods | |
| def module | |
| ("::"+self.to_s.split("::").tap {|m| m.pop }.join('::')).constantize |
This file contains hidden or 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 Module1 | |
| end | |
| module Module2 | |
| end | |
| module Module3 | |
| end | |
| class MyClass |
This file contains hidden or 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
| function readFile(file) { | |
| var reader = new FileReader(); | |
| var deferred = $.Deferred(); | |
| reader.onload = function(event) { | |
| deferred.resolve(event.target.result); | |
| }; | |
| reader.onerror = function() { | |
| deferred.reject(this); |
This file contains hidden or 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 Document { | |
| func properties() -> [String] { | |
| var array: [String] = [] | |
| var mirror = reflect(self) | |
| for i in 0..<mirror.count { | |
| if mirror[i].0 != "super" { | |
| array.append(mirror[i].0) | |
| } | |
| } | |
| return array |
This file contains hidden or 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 Foundation | |
| struct Regex { | |
| let pattern: String | |
| let options: NSRegularExpressionOptions! | |
| private var matcher: NSRegularExpression { | |
| return NSRegularExpression(pattern: self.pattern, options: self.options, error: nil)! | |
| } | |
OlderNewer