Skip to content

Instantly share code, notes, and snippets.

# 1. Briefly explain what the following code does.
# 2. Is there anything wrong with it?
# 3. How would you resolve the problems (if any exist)?
# Assume League, Team, Player models
# League <has_many> teams
# Team <has_many> players
# Player has boolean column all_star
def all_stars(league_name)
league = League.find_by_name league_name
@sanjeev2838
sanjeev2838 / .pryrc
Last active December 20, 2019 12:44
My pryrc file
begin
require 'awesome_print'
Pry.config.print = proc { |output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output) }
rescue LoadError => err
puts "no awesome_print :("
end
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
@sanjeev2838
sanjeev2838 / pre-commit
Created December 18, 2019 12:35 — forked from koppen/pre-commit
Run rubocop on pre-commit
# .git/hook/pre-commit
#!/bin/sh
#
# Check for ruby style errors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
NC='\033[0m'
require 'rubygems'
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(open('/Users/kumar064/Desktop/KnowingPeople.htm'))
output_file = File.open('/Users/kumar064/Documents/Children_of_tomorrow.txt', 'w')
# puts page
page.css('p').each do |el|
@sanjeev2838
sanjeev2838 / gist:128dea6fcbb7a9db38106bf390a9bfff
Created May 21, 2019 17:04 — forked from speric/gist:6096965
vimtutor Lesson Summaries
Lesson 1 SUMMARY
1. The cursor is moved using either the arrow keys or the hjkl keys.
h (left) j (down) k (up) l (right)
2. To start Vim from the shell prompt type: vim FILENAME <ENTER>
3. To exit Vim type: <ESC> :q! <ENTER> to trash all changes.
OR type: <ESC> :wq <ENTER> to save the changes.
@sanjeev2838
sanjeev2838 / ruby
Created February 16, 2019 18:58
Kindle Notes parser
require 'rubygems'
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(open('/Users/kumar064/Documents/suno_laddakh_notebook.html'))
output_file = File.open('/Users/kumar064/Documents/parsed_suno_laddakh_notebook.txt', 'w')
page.css('div.noteText').each do |el|
output_file.write el.children.first.text
@sanjeev2838
sanjeev2838 / console.rb
Created August 1, 2017 04:05 — forked from nuxlli/console.rb
To access url helpers (url_for, etc) from Rails console (Rails 3)
# Example from: http://snipplr.com/view/37063/
include Rails.application.routes.url_helpers
# set host in default_url_options:
default_url_options[:host] = "localhost"
# can then use:
url_for()
# This works with steak 0.3.x and rspec 1.x
# For steak --pre and rspec 2 see this fork: http://gist.github.com/448487
# Put this code in acceptance_helper.rb or better in a new file spec/acceptance/support/javascript.rb
Spec::Runner.configure do |config|
config.before(:each) do
Capybara.current_driver = :selenium if options[:js]
end
@sanjeev2838
sanjeev2838 / Gemfile
Created July 25, 2017 09:14 — forked from eliotsykes/Gemfile
JavaScript testing in Rails 4.x with RSpec, Capybara, PhantomJS, Poltergeist
# Add poltergeist gem to Gemfile, in :test group,
# then run `bundle` to install
group :test do
...
gem 'poltergeist'
...
end
@sanjeev2838
sanjeev2838 / ajax-modal.js
Created July 19, 2017 17:28 — forked from AleeRojas/ajax-modal.js
Ajax y Modal Semantic-UI
$('body').on('click', '.ajax-modal', function() {
$('.ui.modal')
.modal({
onShow: function(callback) {
callback = $.isFunction(callback) ? callback : function(){};
var $content = $(this).find('.content');
$.get("contentData.php", function(data) {
$content.html(data);
});
}