Skip to content

Instantly share code, notes, and snippets.

View carlossanchezp's full-sized avatar

Carlos Sánchez Pérez carlossanchezp

View GitHub Profile
METHOD MISSING
class InformationDesk
def emergency
# Call emergency...
"emergency() called"
end
def flights
# Provide flight information...
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
results = [ ]
for i in 1..3
results << lambda { i }
end
puts results.map { |l| l.call }
@carlossanchezp
carlossanchezp / gist:8800457
Last active March 5, 2017 22:00
Instalation UBUNTU
# 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
@carlossanchezp
carlossanchezp / gist:6529615
Last active December 22, 2015 20:49
MongoDB shell
> 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 } );
/**
* 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; };
@carlossanchezp
carlossanchezp / gist:6159815
Created August 5, 2013 21:35
Ruby unexpected behavior when using .clone or .dup on a hash (or array)
# 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'
@carlossanchezp
carlossanchezp / gist:6103569
Created July 29, 2013 10:53
mi ~/.gitconfig
[merge]
tool = meld
[clolor]
ui = true
[color]
branch = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
@carlossanchezp
carlossanchezp / gist:5935571
Created July 5, 2013 16:11
Un ejemplo de uso de UNION para probar
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})"
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) }