Skip to content

Instantly share code, notes, and snippets.

@xecutioner
xecutioner / a.rb
Created March 10, 2016 02:32
STI PROGRAMMING NOTES
While permanently null fields and large unwieldy tables are conceptually ugly, they generally don't actually cause any real inefficiency. The extra space used by null fields is not an important consideration for most systems, and the query speed will not be slower if you set up your indexes well.
And the benefits of STI are often worthwhile (database efficiency by minimizing joins, and shared code simplicity and DRYness). So if you are going to use a traditional SQL system, just learn to ignore the conceptual ugliness and use STI. Your use case is what STI was designed for.
That said, if you are not too deep in your development cycle for this project to be attached to your database system (and it sounds like you're not), and you are willing to invest some time to research/learning, you really might want to consider an alternative to SQL (there are many good ones out there). Currently the most popular alternative (and my personal favorite) is MongoDB.
MongoDB is document-based rather than schema-based. This
@xecutioner
xecutioner / _share_buttons.html.erb
Created March 9, 2016 09:10
share buttons views
<div class="share_buttons <%='pull-right' if defined?(pull_left) && pull_left!=true%>">
<span class='st_facebook_large' st_url=<%=request.original_url%> displayText='Facebook'></span>
<span class='st_googleplus_large' st_url=<%=request.original_url%> displayText='Google +'></span>
<span class='st_twitter_large' st_url=<%=request.original_url%> displayText='Tweet'></span>
<span class='st_linkedin_large'st_url=<%=request.original_url%> displayText='LinkedIn'></span>
<span class='st_email_large' st_url=<%=request.original_url%> displayText='Email'></span>
<span class='st_reddit_large' st_url=<%=request.original_url%> displayText='Reddit'></span>
<!-- <span class='st_plusone_large' displayText='Google +1'></span> -->
<%if !defined?(pull_left) %>
<span class="share_text">If you like this article, Then perhaps share?</span>
@xecutioner
xecutioner / file sizes
Created March 6, 2016 08:32
commands for checking the file sizes in linux
# Overall file system usages.
df -h
# Specific file or folder
du -sh *
@xecutioner
xecutioner / grok_vi.mdown
Created February 17, 2016 21:05 — forked from nifl/grok_vi.mdown
Your problem with Vim is that you don't grok vi.

Answer by Jim Dennis on Stack Overflow question http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118

Your problem with Vim is that you don't grok vi.

You mention cutting with yy and complain that you almost never want to cut whole lines. In fact programmers, editing source code, very often want to work on whole lines, ranges of lines and blocks of code. However, yy is only one of many way to yank text into the anonymous copy buffer (or "register" as it's called in vi).

The "Zen" of vi is that you're speaking a language. The initial y is a verb. The statement yy is a simple statement which is, essentially, an abbreviation for 0 y$:

0 go to the beginning of this line. y yank from here (up to where?)

@xecutioner
xecutioner / deploy.rb
Created January 19, 2016 05:13
private_pub capistrano tasks
namespace :private_pub do
desc "Start private_pub server"
task :start do
run "cd #{current_path};RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production -D -P tmp/pids/private_pub.pid"
end
desc "Stop private_pub server"
task :stop do
run "cd #{current_path};if [ -f tmp/pids/private_pub.pid ] && [ -e /proc/$(cat tmp/pids/private_pub.pid) ]; then kill -9 `cat tmp/pids/private_pub.pid`; fi"
end
@xecutioner
xecutioner / git tricks
Last active August 16, 2016 09:28
git tricks
Remove merged branch
git branch --merged | grep -v "\*" | grep -v master | grep -v dev | xargs -n 1 git branch -d
Git log of code snippet
git log -S'the line from your file' -- path/to/your/file.txt
@xecutioner
xecutioner / rspec_model_testing_template.rb
Last active May 29, 2017 07:19 — forked from PWSdelta/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:

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

[6/18/15, 2:44:59 PM] Kapil Nakhwa: s3 = AWS::S3.new
bucket = s3.buckets.create('dns-compat-bucket-name')
[6/18/15, 2:45:33 PM] Kapil Nakhwa: s3 = AWS::S3.new(
:access_key_id => 'YOUR_ACCESS_KEY_ID',
:secret_access_key => 'YOUR_SECRET_ACCESS_KEY')
bucket = s3.buckets['my-bucket'] # no request made
@xecutioner
xecutioner / tricks
Created May 25, 2015 11:01
Rails Tricks
#Migrate back but a specific verison only
rake db:migrate:down VERSION=20150406100828