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
| METHOD MISSING | |
| class InformationDesk | |
| def emergency | |
| # Call emergency... | |
| "emergency() called" | |
| end | |
| def flights | |
| # Provide flight information... |
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
| Opción 1) | |
| class DateRange | |
| def initialize(from, to, step) | |
| @from, @to, @step = from, to, step | |
| end | |
| def each | |
| current = @from | |
| while current < @to do |
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
| results = [ ] | |
| for i in 1..3 | |
| results << lambda { i } | |
| end | |
| puts results.map { |l| l.call } | |
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
| # Update System | |
| # ------------------------------------------------------------------------------ | |
| echo 'Updating System...' | |
| sudo apt-get -y update | |
| # Hardware | |
| # ------------------------------------------------------------------------------ | |
| echo 'Installing bumblebee' | |
| sudo add-apt-repository -y ppa:bumblebee/stable && sudo apt-get update | |
| sudo apt-get -y install bumblebee bumblebee-nvidia |
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
| > db.things.insert( { _id : 1, tags : ['tag1', 'tag2'] } ); | |
| > db.things.insert( { _id : 2, tags : ['tag2'] } ); | |
| > db.things.insert( { _id : 3, tags : ['tag1', 'tag2', 'tag3'] } ); | |
| > db.things.insert( { _id : 4, tags : [] } ); | |
| > // función de mapeo | |
| > m = function(){ | |
| ... this.tags.forEach( | |
| ... function(z){ | |
| ... emit( z , { count : 1 } ); |
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
| /** | |
| * How to create a Javascript object and initialize its properties using dot notation (.) | |
| */ | |
| var code = new Object(); | |
| code.url = 'http://www.example.com'; | |
| code.twitter = '@example'; | |
| code.getTwitter = function() { return code.twitter; }; | |
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
| # Ruby unexpected behavior when using .clone or .dup on a hash (or array) | |
| # create a hash and freeze it so it shouldn't be modified | |
| MY_HASH = { :one => { :first => 'eins', :second => 'zwei' } }.freeze | |
| puts MY_HASH.inspect # {:one=>{:first=>"eins", :second=>"zwei"}} | |
| new_hash = MY_HASH.dup # copy the hash, unfrozen | |
| new_hash[:one][:second] = 'dos' |
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
| [merge] | |
| tool = meld | |
| [clolor] | |
| ui = true | |
| [color] | |
| branch = auto | |
| status = auto | |
| [color "branch"] | |
| current = yellow reverse | |
| local = yellow |
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 ActiveRecord::UnionScope | |
| def self.included(base) | |
| base.send :extend, ClassMethods | |
| end | |
| module ClassMethods | |
| def union_scope(*scopes) | |
| id_column = "#{table_name}.id" | |
| sub_query = scopes.map { |s| s.select(id_column).to_sql }.join(" UNION ") | |
| where "#{id_column} IN (#{sub_query})" |
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
| result_set.tap{|o| (o.blank?) ? o << "experts" : o << ".experts" if params[:type] == "Expert"}. | |
| tap{|o| (o.blank?) ? o << "customers" : o << ".customers" if params[:type] == "Customer"}. | |
| tap{|o| (o.blank?) ? o << "adminstrators" : o << ".adminstrators" if params[:type] == "Adminstrator"}. | |
| tap{|o| (o.blank?) ? o << "activated" : o << ".activated" if params[:activated] == 'true'}. | |
| tap{|o| (o.blank?) ? o << "deactivated" : o << ".deactivated" if params[:activated] == 'false'} | |
| end | |
| User.instance_eval { eval(result_set) } |