Skip to content

Instantly share code, notes, and snippets.

@styliii
styliii / shipping.rb
Created December 20, 2012 04:12
mock code interview example
require 'yaml'
file_data = YAML.load_file('shipping.yaml')
class ShippingData
def initialize(attr={})
@sd_data = attr
end
@styliii
styliii / leaderboard.js
Created December 28, 2012 02:11
JS file to my leaderboard app
// Set up a collection to contain player information. On the server,
// it is backed by a MongoDB collection named "players".
Players = new Meteor.Collection("players");
var randomScore = function() {
return Math.floor(Math.random()*10)*5;
}
if (Meteor.isClient) {
Template.leaderboard.players = function () {
@styliii
styliii / SortAge.rb
Created December 29, 2012 00:06
Interview Question
# Given an array of objects with people's name and age
# sort this array based on a person's age
# for a given age, do not change the order of the original array
people = [
{:name => "Jake", :age => 33},
{:name => "Larry", :age => 31},
{:name => "Chhay", :age => 33},
{:name => "Li", :age => 29},
{:name => "Li2", :age => 32},
@styliii
styliii / jquery.stop
Last active December 12, 2015 06:48
for chhay
$('a.cne-google').on('mouseenter', function() {
$('div#cne-google-tooltip').fadeIn();
})
$('#cne-google').mouseleave( function() {
$('#cne-google-tooltip').delay(1000).fadeOut("slow");
})
$('#cne-google-tooltip').mouseenter(function(){
$('a.cne-google').stop();
@styliii
styliii / default.rb
Created July 17, 2013 22:25
redis recipe for cookbook
package "python-software-properties" do
action :install
end
execute "redis ppa install" do
command "/usr/bin/add-apt-repository ppa:chris-lea/redis-server"
command "/usr/bin/apt-get -y update"
action :run
end
@styliii
styliii / stack_trace
Created August 16, 2013 23:35
stack trace for error adding chef-hipchat cookbook
[2013-08-16T23:33:35+00:00] DEBUG: Gem::InstallError: ruby_block[Compile Custom OpsWorks Run List] (opsworks_custom_cookbooks::execute line 3) had an error: Gem::InstallError: chef_gem[hipchat] (hipchat::default line 1) had an error: Gem::InstallError: httparty requires multi_xml (>= 0.5.2)
/usr/lib/ruby/vendor_ruby/rubygems/installer.rb:232:in `ensure_dependency'
/usr/lib/ruby/vendor_ruby/rubygems/installer.rb:408:in `ensure_dependencies_met'
/usr/lib/ruby/vendor_ruby/rubygems/installer.rb:407:in `each'
/usr/lib/ruby/vendor_ruby/rubygems/installer.rb:407:in `ensure_dependencies_met'
/usr/lib/ruby/vendor_ruby/rubygems/installer.rb:158:in `install'
/usr/lib/ruby/vendor_ruby/rubygems/dependency_installer.rb:297:in `install'
/usr/lib/ruby/1.8/fileutils.rb:243:in `each_with_index'
/usr/lib/ruby/vendor_ruby/rubygems/dependency_installer.rb:270:in `each'
/usr/lib/ruby/vendor_ruby/rubygems/dependency_installer.rb:270:in `each_with_index'
{
"command": "ruby -rubygems -r./custom_plan -eZeus.go",
"plan": {
"boot": {
"default_bundle": {
"development_environment": {
"prerake": {"rake": []},
"console": ["c"],
"generate": ["g"]
require 'zeus/rails'
class CustomPlan < Zeus::Rails
# def my_custom_command
# # see https://github.com/burke/zeus/blob/master/docs/ruby/modifying.md
# end
def spec(argv=ARGV)
# disable autorun in case the user left it in spec_helper.rb
RSpec::Core::Runner.disable_autorun!
@styliii
styliii / zeus.json
Created December 12, 2013 23:14
current zeus setup
{
"command": "ruby -rubygems -r./custom_plan -eZeus.go",
"plan": {
"boot": {
"default_bundle": {
"development_environment": {
"prerake": {"rake": []},
"console": ["c"],
"generate": ["g"]
=> #<User id: 110, email: "[email protected]", crypted_password: "$2a$10$oWWIP/cyDCkdjSAuabsWd.4LmITNER2.snHZNs1n9c8R...", salt: "y85TW1tozJXwXqxWsU7L", created_at: "2014-01-29 22:59:07", updated_at: "2014-01-29 22:59:08", remember_me_token: nil, remember_me_token_expires_at: nil, reset_password_token: nil, reset_password_token_expires_at: nil, reset_password_email_sent_at: nil, last_login_at: "2014-01-29 23:32:53", last_logout_at: nil, last_activity_at: "2014-01-31 16:50:57", first_name: "jaimel", last_name: "gauda", phone_number: "3144948435", zendesk_user_id: "605708293", last_login_from_ip_address: "24.6.52.99", used_free_months: 0, agree_to_tos: true, lead_id: nil, conversion_token: "">
irb(main):005:0> user.invoices
[Shard: slave_0] Invoice Load (1.3ms) SELECT `invoices`.* FROM `invoices` WHERE `invoices`.`user_id` = 110
=> #<ActiveRecord::Associations::CollectionProxy [#<Invoice id: 105, order_id: 112, user_id: 110, foreign_key: "in_3Ov9pbVLvRGBRg", aasm_state: "shipped", created_at: "