Skip to content

Instantly share code, notes, and snippets.

import React from 'react';
import { ContentBox } from '@core_js/ui_elements';
import { money } from '@core_js/utils';
import SubscriptionPlan from '../../shared/SubscriptionPlan';
const BillingState = ({ state }) => {
switch (state) {
case 'overdue':
return <div className="yellow">Overdue</div>;
case 'delinquent':

Outline:

Idea: Seek to establish similarities between Machiavelli and Hobbes, talk about some important differences, then conclude with some remarks on how both authors failed to anticipate what would promote peace and liberty as we see in the modern world.

THESIS STATEMENT: On the surface, Hobbes and Machiavelli appear to advocate for polar opposite forms of government. Although their ideologies are different in paper, there are surprising similarities in how they believe liberty and peace are maintained in practice. However, in the end, but both of these thinkers failed to forsee what has proven to secure liberty and peace in the modern world.

Main Point #1: Hobbes and Machiavelli have conflicting definitions of liberty, which creates the illusion that their beliefs on how society should be ordered are incompatible with one another.

@laspluviosillas
laspluviosillas / question1.rb
Last active October 18, 2017 16:20
Interview Question #1
class Husband < ActiveRecord::Base
attr_accessible :full_name
has_one :wife
end
class Wife < ActiveRecord::Base
attr_accessible :full_name
belongs_to :husband
end
@laspluviosillas
laspluviosillas / comprehension_examples.py
Created June 13, 2017 04:00
Using python comprehension to analyze enron data. (udacity machine learning)
# ===========================================
# Output first entry from dict to see values.
# ===========================================
# print enron_data[enron_data.keys()[0]]
# =============================
# Get # of persons of interest
# (uses dict comprehension)
# ============================
@laspluviosillas
laspluviosillas / polymorphic.rb
Created April 13, 2017 19:50
Issue with polymorphic associations
class Task < ActiveRecord::Base
has_one :notification_preference, as: :notifee
end
class NotificationPreference < ActiveRecord::Base
belongs_to :notifee, polymorphic: true
end
# Code above keeps on looking for notifee_id on Task.
# The foreign keys are obviously in the NotificationPreference table (notifee_id and notifee_type)
@laspluviosillas
laspluviosillas / offerings.rb
Created January 20, 2014 21:37
Example of retrieving offerings.
Spree::LineItem.class_eval do
def offering
variant.offering(self.qty)
end
end
Spree::Variant.class_eval do
# has_many :volume_prices (viene de la gema)
has_many :offerings
Failures:
1) Spree::Admin::VariantsController POST Create a new variant with associated course
Failure/Error: Spree::Variant.all.count.should eq(2)
expected: 2
got: 1
(compared using ==)
# ./spec/controllers/spree/admin/variants_controller_spec.rb:26:in `block (3 levels) in <top (required)>'
class Search
def initialize(searchable)
@searchable = searchable
end
def starts_with(letter, attribute)
@searchable.where(attribute=> 'letter') # would be some variant of a LIKE query.
end
end
class ContentProviderCalculator
def calculate(commissionable)
olei = # find olei content provider
olec = # find olec content provider
content_amount = commissionable.subtotal * .2 # 20% goes to content providers
if commissionable.premium?
# create commission for olei of 66.7% of content_amount
# create commission for olec of 33.3% of content_amount
else
def update
# fetch @conversation having its rank updated.
#
conversations = @discussion.conversations.order(:rank).to_a
# Move conversation to new position by inserting in array at rank and deleting it from previous position.
conversations.insert(@conversation.rank, conversations.delete_at(@conversation))
# Update all conversation ranks to correspond to new array order.
# Very inefficient as this uses a n+1 query. You could optimize to use update_all