Skip to content

Instantly share code, notes, and snippets.

View arjunvenkat's full-sized avatar

Arjun Venkataswamy arjunvenkat

View GitHub Profile
@arjunvenkat
arjunvenkat / gist:1115bc41bf395a162084
Last active January 12, 2024 05:04
Seeding a Rails database with a CSV file

How to seed a Rails database with a CSV file

1. Setup

First, Create a folder inside of lib called seeds

Put your CSV file example.csv into the lib/seeds folder. In the example below, the file is called real_estate_transactions.csv

Make sure you've created a resource with the appropriate columns to match your seed data. The names don't have to match up.

@arjunvenkat
arjunvenkat / scraper_lab_p2.rb
Created December 12, 2012 17:48
scrape multiple pages using Nokogiri and Mechanize
# nokogiri requires open-uri
require 'nokogiri'
require 'open-uri'
# csv will be used to export data
require 'csv'
require 'mechanize'
# pp is useful to display mechanize objects
require 'pp'
@arjunvenkat
arjunvenkat / carrierwave.md
Last active May 24, 2018 16:11 — forked from raghubetina/carrierwave.md
CarrierWave Cheatsheet

CarrierWave Cheatsheet

The CarrierWave gem provides us with an easy way to allow file uploads through forms.

Installation

In your Gemfile, include

gem 'carrierwave'
@arjunvenkat
arjunvenkat / week3.md
Created April 11, 2017 14:19
App Dev Troubleshooting notes

Week 3

Omnicalc

Setup

  • Make sure students are running rails s in their app folder, not the app's parent folder
  • Make sure students test output variables after hitting submit, since the forms wont show any work from the controller
@arjunvenkat
arjunvenkat / pull_requests.md
Last active February 28, 2017 05:23
Creating Pull Requests
  1. Fork the repo that you're working on into your own account.
  2. Clone down the fork
  3. Create a new branch in the fork using git branch [branch_name] replacing [branch_name] with a short phrase describing the feature your'e working on
  4. Check the current status of your branches by using git branch. You should see all the branches you have access to. Your current branch will have an * next to it
  5. Check out the new branch using git checkout [branch_name]
  6. Make your changes in the code
  7. Add and commit your changes
  8. Pull down any changes from the original repo:
  9. Add the original repo as an upstream remote with git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git. Make sure to use the actual owner and repository names.
  10. Pull changes into your branch from the upstream remote with git pull upstream master
@arjunvenkat
arjunvenkat / branches.md
Last active February 28, 2017 05:23
Creating your own branchs

Creating and working with branches in Git

  1. Create a branch with git branch [your_branch_name]
  2. Checkout the branch with git checkout [your_branch_name]
  3. Publish your branch with git push origin [your_branch_name]
  4. Do some work, commit your changes
  5. When your branch is done, checkout master with git checkout master
  6. Pull down any changes from master with git pull
  7. Checkout your branch again and make sure it is up to date with master using git merge master
  8. If there are any conflicts, fix them. If not, you may need to exit the Vim text editor using :wq
@arjunvenkat
arjunvenkat / devise.md
Last active November 20, 2016 19:47 — forked from raghubetina/devise.md

Authentication and Authorization with Devise

We will be using the [Devise gem][2] to help us get started with authentication (are you who you say you are?) and authorization (are you allowed to do/see this?).

Add sign-in/sign-out

  • Add gem 'devise' to your Gemfile and bundle
  • rails g devise:install

Devise will give you some setup instructions. We don't need to worry about most of them, but we do need to set a root URL. Usually, you will point the root URL to the index action of some important resource in your application: In config/routes.rb:

@arjunvenkat
arjunvenkat / rcav.md
Last active July 25, 2016 01:11
the RCAV flow

Our apps are nothing more than a collection of URLs that we decide to allow users to access:

  • mydomain.com/products
  • mydomain.com/photos/193
  • mydomain.com/signin

So remember: everything always starts with a route between a URL we want to support and a Ruby method that will be responsible for generating a response to the user's browser.

In order to support a URL in your app such as http://localhost:3000/signin, there are a lot of dots to connect!

@arjunvenkat
arjunvenkat / grade.sh
Last active May 15, 2016 17:43
Grading bash script for MBA courses
# edit the project name and any feature specs if they're being copied in
project_name=photogram_golden_seven
mkdir ${project_name}_grades
cd $project_name
for branch in $(git for-each-ref --format='%(refname)' refs/remotes/); do
short_name=${branch/refs\/remotes\/origin\//""}
echo $short_name
git add -A