Skip to content

Instantly share code, notes, and snippets.

View ekyfauzi's full-sized avatar

Eky Fauzi ekyfauzi

View GitHub Profile
@ekyfauzi
ekyfauzi / autoheight.js
Last active August 29, 2015 14:19
Autoheight
// Autoheight for element with class .autoheight to be 100% height
$('.autoheight').css({ height: $(window).innerHeight() });
// Auto resize height if window resize
$(window).resize(function(){
$('.autoheight').css({ height: $(window).innerHeight() });
});
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/coconut/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Eky Fauzi"]
gem.email = ["ekyfauzi@hotmail.com"]
gem.description = %q{This is my first gem}
gem.summary = %q{I love to code with gem!}
gem.homepage = ""
# app/models/post.rb
class Post < ActiveRecord::Base
has_many :comments, as: :commentable
def comment_by_user(id)
comments.where(user_id: id)
end
end
# app/models/image.rb
class Image < ActiveRecord::Base
has_many :comments, as: :commentable
def comment_by_user(id)
comments.where(user_id: id)
end
end
# app/models/comment.rb
class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: true
end
# app/models/concerns/commentable.rb
module Commentable
def self.include(base)
base.class_eval do
has_many :comment, as: :commentable
end
end
def comment_by_user(id)
comments.where(user_id: id)
# app/models/post.rb
class Post < ActiveRecord::Base
include Commentable
end
# app/models/image.rb
class Image < ActiveRecord::Base
include Commentable
end
@ekyfauzi
ekyfauzi / rspec_model_testing_template.rb
Last active September 5, 2015 16:45 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@ekyfauzi
ekyfauzi / NERDTree.mkd
Created November 26, 2015 12:12 — forked from m3nd3s/NERDTree.mkd
My Vim Cheat Sheet

NERDTree

o.......Open files, directories and bookmarks....................|NERDTree-o|
go......Open selected file, but leave cursor in the NERDTree.....|NERDTree-go|
t.......Open selected node/bookmark in a new tab.................|NERDTree-t|
T.......Same as 't' but keep the focus on the current tab........|NERDTree-T|
i.......Open selected file in a split window.....................|NERDTree-i|
gi......Same as i, but leave the cursor on the NERDTree..........|NERDTree-gi|
s.......Open selected file in a new vsplit.......................|NERDTree-s|
gs......Same as s, but leave the cursor on the NERDTree..........|NERDTree-gs|

O.......Recursively open the selected directory..................|NERDTree-O|