Skip to content

Instantly share code, notes, and snippets.

View myfashionhub's full-sized avatar

Nessa Nguyen myfashionhub

View GitHub Profile
@myfashionhub
myfashionhub / refactor-examples.md
Last active August 6, 2019 15:35
Code refactor examples
class ElasticSearchCartDaily(object):
    def __init__(self, es_index_name, host=None, version=_CONFIG.ELASTICSEARCH_VERSION):
        hosts = (host, ) if host else _CONFIG.ELASTICSEARCH_HOSTS
        self.es = Elasticsearch(hosts)
        self.version = version

        # Need two indices, one to alias to when we update the index, and one to hold historical stats.
        # They will both be alternating as a search or update index per build
        self.es_index_name_a = u'{}_a'.format(es_index_name)
SELECT DATE_TRUNC('day', checkout.created) AS checkout_date,
DATE_TRUNC('day', interaction.created) AS interaction_date,
CASE WHEN DATEDIFF('days', interaction.created, checkout.created) <= 15 THEN checkout.value
ELSE NULL END AS value,
interaction.owner_pub_id AS pub_id,
interaction.interaction_type AS interaction_type,
checkout.auction_id
FROM (
SELECT interaction.interaction_type AS checkout_type,
interaction.owner_merch_id AS merch_id,
@myfashionhub
myfashionhub / subscription_initiation.rb
Created July 21, 2015 21:48
Subscription initiation
require 'time'
class SubscriptionInitiationWorker < Boxxspring::Worker::TaskBase
def process_payload(payload)
if payload['create_subscription_tasks']
properties_and_sources.each do |property_id, sources|
sources.each_with_index do |source, index|
if source.last_polled_at.nil? || Time.now.utc >= Time.parse(source.last_polled_at) + source.time_to_live
self.logger.info("Source (id: #{source.id}) was last polled more than (or exactly) #{source.time_to_live} seconds ago.")
@myfashionhub
myfashionhub / distribution_worker.md
Last active August 29, 2015 14:25
Bedrocket API: Distribution worker

Adding a new distribution to Bedrocket API:

Bedrocket-api:

  • If the service doesn’t already exist (Google, Facebook, Dailymotion), add the service & its oauth options:
# bedrocket-api/app/models/[service name]_service.rb

class DailymotionChannelService < SocialService
  oauth 2, :dailymotion, client_options: :client_options, authorize_params: :authorize_params
@myfashionhub
myfashionhub / open_ssl_error.sh
Last active August 29, 2015 14:24
SSL error stacktrace
2015-07-13T22:07:47.482910+00:00 heroku[vimeo_metadata.1]: Starting process with command `bundle exec rake worker:vimeo_metadata --trace`
2015-07-13T22:07:47.909739+00:00 heroku[vimeo_metadata.1]: Stopping all processes with SIGTERM
2015-07-13T22:07:48.063182+00:00 heroku[vimeo_metadata.1]: State changed from starting to up
2015-07-13T22:07:48.376967+00:00 app[vimeo_metadata.1]: rake aborted!
2015-07-13T22:07:48.377053+00:00 app[vimeo_metadata.1]: SignalException: SIGTERM
2015-07-13T22:07:48.377122+00:00 app[vimeo_metadata.1]: /app/vendor/ruby-2.1.6/lib/ruby/2.1.0/net/protocol.rb:155:in `select'
2015-07-13T22:07:48.377127+00:00 app[vimeo_metadata.1]: /app/vendor/ruby-2.1.6/lib/ruby/2.1.0/net/protocol.rb:155:in `rescue in rbuf_fill'
2015-07-13T22:07:48.377128+00:00 app[vimeo_metadata.1]: /app/vendor/ruby-2.1.6/lib/ruby/2.1.0/net/protocol.rb:152:in `rbuf_fill'
2015-07-13T22:07:48.377129+00:00 app[vimeo_metadata.1]: /app/vendor/ruby-2.1.6/lib/ruby/2.1.0/net/protocol.rb:134:in `readuntil'
2015-07-13T22:07:48.3771
@myfashionhub
myfashionhub / Sequence generator
Last active August 29, 2015 14:05
Sequence generator (Javascript exercise)
var naturals = new NaturalGen();
var evens = new EvenGen();
var odds = new OddGen();
var fibbs = new FibbGen();
var matches = new Match(evens, fibbs);
for (var i = 0; i < 10; i++) {
console.log(naturals.next());
console.log(evens.next());
console.log(odds.next());
@myfashionhub
myfashionhub / article.js
Last active August 29, 2015 14:02
Circular reference in ArticleView render
// REFACTOR 1
function loadFeed(url) {
var feed = new google.feeds.Feed(url);
feed.setNumEntries(1);
feed.load(function(result) {
for (var i = 0; i < result.feed.entries.length; i++) {
var $article = $('<div>').addClass('article');
var $date = $('<div>').addClass('date').append(result.feed.entries[i].publishedDate);
var $link = $('<a>').attr('href', result.feed.entries[i].link);
var $title = $('<h3>').append(result.feed.entries[i].title);
@myfashionhub
myfashionhub / Rspec error
Created May 22, 2014 03:35
Rspec error: Relation table does not exist
$ rspec
F
Failures:
1) Fashionista has a username
Failure/Error: fashionista = Fashionista.new(username: 'myfashionhub')
ActiveRecord::StatementInvalid:
PG::UndefinedTable: ERROR: relation "fashionistas" does not exist
LINE 5: WHERE a.attrelid = '"fashionistas"'::regclass