Skip to content

Instantly share code, notes, and snippets.

@luckydev
luckydev / basic_style_guidelines
Last active December 31, 2015 11:59
Basic Style guidelines
How to declare a method:
- (returntype)nameofTheMethodParam:(paramtype)paramname andAnotherParam:(paramtype)paramname;
+ (returntype)nameofTheMethodParam:(paramtype)paramname andAnotherParam:(paramtype)paramname;
Not like these:
-(returntype)nameofTheMethodParam:(paramtype)paramname andAnotherParam:(paramtype)paramname;
-(returntype) nameofTheMethodParam:(paramtype)paramname andAnotherParam:(paramtype)paramname;
@luckydev
luckydev / RGB.h
Created November 4, 2013 02:44
Macro for setting UIColor from RGB Hex.
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@luckydev
luckydev / irb.rb
Created December 24, 2012 09:02
What I <3 in Ruby. reOpen classes anytime. Do any shit with them, they will digest :)
irb(main):007:0> class Person
irb(main):008:1> attr_accessor :name,:email
irb(main):009:1> end
=> nil
irb(main):010:0> p = Person.new
=> #<Person:0x007fa40a038378>
irb(main):011:0> p.name
=> nil
irb(main):012:0> p.email
=> nil
@luckydev
luckydev / activities_controller.rb
Created February 2, 2012 20:00
Rendering views in rails
#all these will render guests/new.html.erb template
#calling from an action in ActivitiesConctoller, for example.
render "guests/new"
render "guests/new.html.erb"
render :template => "guests/new"
render :template => "guests/new.html.erb"
@luckydev
luckydev / devs.rb
Created December 1, 2011 04:58
Types of Developers
# SeniorDev, AwesomeDev, NoviceDev
class SeniorDev
def do_some_old_stuff
puts "This is a piece of cake"
end
def method_missing(name, *args)
puts "Err.. What? #{name}??.. THAT IS IMPOSSIBLE! Leave me alone."
end
@luckydev
luckydev / a_lambda.rb
Created August 14, 2011 05:41
Proc and Lambda: Difference 2 - Arguments Check
my_super_code = lambda { |a,b| return a+b; }
puts my_super_code.call(1,2,5)
#=> ArgumentError: wrong number of arguments (3 for 2)
@luckydev
luckydev / a_lambda.rb
Created August 14, 2011 05:38
Proc and Lambda: Difference 1 - Return policy
def my_awesome_method
ret = lambda { return "This is returned from Lambda" }
ret.call
"This line will run"
end
puts my_awesome_method
# => "This is returned from Lambda"
# => "This line will run"
@luckydev
luckydev / output
Created July 18, 2011 06:07
ActiveRecord Finder
ruby-1.9.2-p180 :001 > Account.find(34)
ActiveRecord::RecordNotFound: Couldn't find Account with ID=34
from /Users/lakshman/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/relation/finder_methods.rb:296:in `find_one'
from /Users/lakshman/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-
ruby-1.9.2-p180 :002 > Account.where(:id => 34).first
=> nil
ruby-1.9.2-p180 :003 > Account.where(:id => 34)
=> []
$ bundle install
Fetching source index for http://rubygems.org/
Installing rake (0.9.2)
Installing abstract (1.0.0)
Installing activesupport (3.0.5)
Installing builder (2.1.2)
Installing i18n (0.6.0)
Installing activemodel (3.0.5)
Installing erubis (2.6.6)
Installing rack (1.2.3)
@luckydev
luckydev / MyClass.rb
Created April 15, 2011 16:33
for an object -- singleton class
class MyClass
def my_instance_method
puts "this is an instance method"
end
#self here is MyClass
class << self
def count_objects
"counting objects..DONE"