Skip to content

Instantly share code, notes, and snippets.

View rishighan's full-sized avatar
:octocat:
Focusing

Rishi Ghan rishighan

:octocat:
Focusing
View GitHub Profile
<div id="fbook">
<a href="https://www.facebook.com/sharer/sharer.php?u=https://www.intermixonline.com/category/in-the-mix/look+books/holiday+look+book+2013.do" target="_blank">
<img src= "/text/content/HolidayLookBook2013/images/Fb.png">
</a>
</div>
<div id="twitter">
<a href="https://twitter.com/share?url=http://www.intermixonline.com/category/in-the-mix/look+books/holiday+look+book+2013.do" target="_blank">
<img src="/text/content/HolidayLookBook2013/images/Tw.png" border="0"/>
</a>
@rishighan
rishighan / arraymult.rb
Created May 25, 2012 18:46
Array Multiplication
def arrayMultiply arr1, arr2
n =arr1.length
#arr1.inject(0) {|c,i| c + arr1[i]*arr2[i]}
c = Array.new(n)
0.upto(arr1.length-1) do |i|
0.upto(arr2.length-1) do |j|
0.upto(arr1.length-1) do |k|
arr1[i][k] * arr2[k][j]
end
end
@rishighan
rishighan / post.rb
Created April 16, 2012 03:48
filtering by category
# filtering by category
def self.filter_category(category)
where("categories.category_name != ?",category)
end
@rishighan
rishighan / pages_controller.rb
Created April 13, 2012 23:59
Best way to collect posts from a "Home Carousel" category?
@carousel_posts = Post.includes(:categories).where('categories.category_name = "Home Carousel"')
class PhotosController < ApplicationController
def index
redirect_to Instagram.authorize_url(:redirect_uri => CALLBACK_URL)
end
def callback
response = Instagram.get_access_token(params[:code], :redirect_uri => CALLBACK_URL)
session[:access_token] = response.access_token
redirect_to "/feed"
<%= form_for([:admin,@variant]) do |f| %>
<% if @variant.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@variant.errors.count, "error") %> prohibited this attribute from being saved:</h2>
<ul>
<% @variant.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@rishighan
rishighan / 20120301183631_products_product_categories.rb
Created March 1, 2012 18:25
Product, Variant and Categories.
class ProductsProductCategories < ActiveRecord::Migration
def up
create_table :products_product_categories, :id => false do |t|
t.integer :product_category_id
t.integer :product_id
end
end
def down
end
@rishighan
rishighan / cart.rb
Created February 27, 2012 22:17
Order and Cart and Order_transaction
class Cart < ActiveRecord::Base
has_many :line_items, :dependent => :destroy
has_many :orders
def total_items
line_items.sum(:quantity)
end
def add_product(product_id)
current_item = line_items.find_by_product_id(product_id)
@rishighan
rishighan / cart.rb
Created February 27, 2012 16:21
Shopping cart issue.
class Cart < ActiveRecord::Base
has_many :line_items, :dependent => :destroy
def total_items
line_items.sum(:quantity)
end
def add_product(product_id)
current_item = line_items.find_by_product_id(product_id)
class ApplicationController < ActionController::Base
protect_from_forgery
private # this makes the cart method available to controllers and prevents it from being used as an action on the Controller
def current_cart
Cart.find(params[:cart_id])
rescue ActiveRecord::RecordNotFound
cart = Cart.create
session[:cart_id] = cart.id