Skip to content

Instantly share code, notes, and snippets.

View ychaker's full-sized avatar

Youssef Chaker ychaker

View GitHub Profile
@ychaker
ychaker / facebook_data_feed_controller.rb
Created November 22, 2018 02:37 — forked from octave/facebook_data_feed_controller.rb
Basic Facebook CSV Product Feed Support for Solidus
class FacebookDataFeedController < ApplicationController
def export
@products = Spree::Product.available
respond_to do |format|
format.csv { send_data @products.to_fb_csv, filename: "facebook-data-feed.csv" }
end
@ychaker
ychaker / categories.yml
Created August 21, 2018 13:31
List of categories in order and hierarchy
# Removing Clothes from the top for now, might want to bring it back at a later time
# - name: "Clothes"
# position: 0
# subcategories:
categories:
- name: "Women"
position: 0
subcategories:
- name: "Bottoms"
@ychaker
ychaker / analytics_keen_event_job.rb
Last active January 12, 2018 16:32
Rails: non blocking analytics
module Analytics
class KeenEventJob < ::ActiveJob::Base
queue_as :analytics
def perform event, data
::Keen.publish event.to_sym, data
end
end
end
Verifying my Blockstack ID is secured with the address 14Xd2BHKPndGCdEbAKmtJHE3sAkzW37XcH https://explorer.blockstack.org/address/14Xd2BHKPndGCdEbAKmtJHE3sAkzW37XcH
Verifying that "ychaker.id" is my Blockstack ID. https://onename.com/ychaker
@ychaker
ychaker / create.js.erb
Created February 7, 2017 22:19
Rails + Refile + Dropzone (9)
$('#alerts').html('<%= j render partial: "shared/alerts" %>');
$('input[type="file"]').val('');
$('input[name="doc[file]"]').val('');
var modal;
<% if @operation.valid? %>
modal = $('#upload-modal-<%= @model.doc_task.id %>');
modal.modal('hide');
modal.on('hidden.bs.modal', function() {
$('#tasks').html('<%= j render partial: "doc_tasks/list", locals: { pending_tasks: @pending_tasks, completed_tasks: @completed_tasks } %>');
@ychaker
ychaker / create.rb
Last active February 7, 2017 22:15
Rails + Refile + Dropzone (8)
require 'representable/json'
class Doc::Create < Trailblazer::Operation
include Model
include Responder
include Representer
include Representer::Deserializer::Hash
include Dispatch
model Doc, :create
@ychaker
ychaker / docs_controller.rb
Last active February 7, 2017 22:00
Rails + Refile + Dropzone (7)
class DocsController < ApplicationController
respond_to :json, :js
before_action :get_doc, only: [ :show, :reload_doc ]
def create
create_params = doc_params.to_h.merge!(current_user: current_user)
result, op = Doc::Create.run(create_params)
@operation = op
@ychaker
ychaker / upload_doc.coffee
Last active May 10, 2017 02:05
Rails + Refile + Dropzone (6)
$(document).ready ->
Dropzone.autoDiscover = false
$(document).on 'shown.bs.modal', '.upload-modal', ->
modal = this
previewTemplate = $('#' + modal.id + ' .dz-file-preview')[0].innerHTML
# Make sure to only initialize the dropzone once.
if ( $('#' + modal.id + ' .dropzone:not(.dz-attached)').length )
dropzone = new Dropzone('#' + modal.id + ' .dropzone', {
@ychaker
ychaker / _upload_modal.html.erb
Created February 7, 2017 20:07
Rails + Refile + Dropzone (5)
<!-- Upload Doc Modal -->
<div
class="modal fade upload-modal"
id="upload-modal-<%= task.id %>"
tabindex="-1"
role="dialog"
aria-labelledby="upload-modal-<%= task.id %>"
>
<div class="modal-dialog" role="document">
<div class="modal-content">