Skip to content

Instantly share code, notes, and snippets.

@vike27
vike27 / You have an array of integers, and for each index you want to find the product of every integer except the integer at that index.
Created May 6, 2015 21:59
You have an array of integers, and for each index you want to find the product of every integer except the integer at that index.
You have an array of integers, and for each index you want to find the product of every integer except the integer at that index.
Write a function get_products_of_all_ints_except_at_index() that takes an array of integers and returns an array of the products.
For example, given:
[1, 7, 3, 4]
your function would return:
[84, 12, 28, 21]
by calculating:
@vike27
vike27 / Maximum Profit Stock Market Problem Algorithm
Last active August 29, 2015 14:20
Maximum Profit Stock Market Problem Algorithm
Writing coding interview questions hasn't made me rich. Maybe trading Apple stocks will.
I have an array stock_prices_yesterday where:
The indices are the time in minutes past trade opening time, which was 9:30am local time.
The values are the price in dollars of Apple stock at that time.
For example, the stock cost $500 at 10:30am, so stock_prices_yesterday[60] = 500.
Write an efficient algorithm for computing the best profit I could have made from 1 purchase and 1 sale of 1 Apple stock yesterday.
No "shorting"—you must buy before you sell. You may not buy and sell in the same time step (at least 1 minute must pass).
@vike27
vike27 / hotel bag | lockers problem set
Last active August 29, 2015 14:20
Hotel Bag Check-In Problem Set
Write a program for managing locker reservations at a hotel concierge desk.
Customers leave bags with the concierge, who then uses your program to determine
in which locker to place the bag. The program tells the concierge the number of
the locker in which to place the bag, and prints a ticket to give to the customer.
Upon return, the customer provides the ticket, and the concierge uses that to
look up the corresponding locker, retrieve the bag, and return it to the customer.
There are 1000 small lockers, 1000 medium sized lockers,
and 1000 large lockers (it’s a big Vegas hotel). You can assume that all
checked bags fit into one of these three sizes. The program should
@vike27
vike27 / FizzBuzz Minitest Exercise
Created April 28, 2015 08:49
FizzBuzz Minitest Exercise
# I wanted learn about Minitest and I saw a cool youtube video about creating a FizzBuzz class that required Minitest. It seemed like a # great introduction so I decided to try it for myself and do my own implementation here
#1st mkdir fizzbuzz to create folder/directory
#This is the main class which we are testing, put this code in a 'fizzbuzz.rb' ruby file
class FizzBuzz
def print(num)
if num.respond_to?(:each)
@vike27
vike27 / Prince Quote
Created July 6, 2014 06:05
Do Bold Things
“All courses of action are risky, so prudence is not in avoiding
danger (it's impossible), but calculating risk and acting
decisively. Make mistakes of ambition and not mistakes of
sloth. Develop the strength to do bold things, not the strength
to suffer.” —NICCOLO MACHIAVELLI, The Prince
@vike27
vike27 / gist:a66e16fc76956d100e67
Created July 4, 2014 23:43
bundle exec rake assets:precompile RAILS_ENV=production for issue submitted: rake aborted! Sass::SyntaxError: Undefined variable: "$c_blue". (Only in production) - Issue in Spree implementation
$ bundle exec rake assets:precompile RAILS_ENV=production
DL is deprecated, please use Fiddle
DL is deprecated, please use Fiddle
[WARNING] You are not setting Devise.secret_key within your application!
You must set this in config/initializers/devise.rb. Here's an example:
Devise.secret_key = "c8e81db7d9ea4e19d185a54a8ade57f38ff00208e174e1c33c5ef6a3d11db0997e499969d5e497f
be30ebdc6828677831272"
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want t
o skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this me
@vike27
vike27 / gist:e20894f45762dd18b7d2
Created July 4, 2014 23:39
git push heroku master trace for issue submitted: rake aborted! Sass::SyntaxError: Undefined variable: "$c_blue". (Only in production) - Issue in Spree implementation
$ git push heroku master
Fetching repository, done.
Counting objects: 171, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (126/126), done.
Writing objects: 100% (148/148), 298.06 KiB | 403.00 KiB/s, done.
Total 148 (delta 56), reused 0 (delta 0)
-----> Ruby app detected
-----> Compiling Ruby/Rails
@vike27
vike27 / gist:017214ea8458495467aa
Created July 4, 2014 23:35
Gemfile for issue submitted: rake aborted! Sass::SyntaxError: Undefined variable: "$c_blue". (Only in production) - Issue in Spree implementation
source 'https://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.5'
# Use sqlite3 as the database for Active Record
group :development do
gem 'sqlite3'
@vike27
vike27 / gist:fa6e65d28098037b6181
Created July 4, 2014 23:34
Gemfile.lock for issue submitted: rake aborted! Sass::SyntaxError: Undefined variable: "$c_blue". (Only in production) - Issue in Spree implementation
GIT
remote: git://github.com/spree/spree_fancy.git
revision: bdeaeb9ced29a4e3204d8bc9988b57808b5a71d8
branch: 2-2-stable
specs:
spree_fancy (1.3.0)
compass-rails
deface (~> 1.0.0rc3)
jquery-ui-rails
spree_core (~> 2.2)