Skip to content

Instantly share code, notes, and snippets.

@davidbiehl
davidbiehl / ecwid_free_shipping_promo_in_cart.html
Last active March 22, 2016 14:03 — forked from makfruit/ecwid_free_shipping_promo_in_cart.html
An HTML/Javascript code snippet for Ecwid to show a simple promo message popup on the cart page for orders less than the defined subtotal
<!-- An HTML/Javascript code snippet for Ecwid to show a simple promo message popup on the cart page for orders less than the defined subtotal -->
<script>
if (typeof(Ecwid) == 'object') {
Ecwid.OnAPILoaded.add(function() {
var promoMessage = "Orders $99 and up ship free!";
var minSubtotal = 99;
var checkSubtotal = function(order) {
if (order) {
var subtotal = order.total - order.shipping - order.tax;
VsrLoader.bootstrap().then(function() {
console.warn("first", Ecwid, Ecwid.Cart); // Ecwid.Cart is undefined
Ecwid.OnAPILoaded.add(function() {
console.warn("loaded", Ecwid, Ecwid.Cart); // Ecwid.Cart is available
});
});
@davidbiehl
davidbiehl / puppet-elasticsearch.pp
Created January 23, 2015 06:11
Install ElasticSearch with Puppet
# https://github.com/elasticsearch/puppet-elasticsearch
class { 'elasticsearch':
manage_repo => true,
repo_version => '1.4',
version => '1.4.2',
java_install => true
}
elasticsearch::instance { 'es-01': }
App.module "Lib", (Lib, App, Backbone, Marionette, $, _)->
class Lib.ResourceEventRouter extends App.Lib.EventRouter
constructor: (opts = {})->
@resource = _.result(opts, "resource") || _.result(@, "resource")
opts.namespace = @resource
opts.events ||= {}
resourceEvents =
index : @resource
new : "#{@resource}/new"
App.module "Lib", (Lib, App, Backbone, Marionette, $, _)->
class Lib.ResourceAppRouter extends Marionette.AppRouter
constructor: (opts = {})->
@resource = _.result(opts, "resource") || @resource || throw "A ResourceRouter needs a resource defined"
delete opts.resource
super(opts)
@appRoute @resource , "index"
@appRoute "@resource/new" , "new"
@appRoute "#{@resource}/:id" , "show"
App.module "Lib", (Lib, App, Backbone, Marionette, $, _)->
class Lib.EventRouter
constructor: (opts = {})->
@events = _.extend(_.result(@, "events"), _.result(opts, "events"))
@vent = _.result(opts, "vent") || _.result(@, "vent")
@namespace = _.result(opts, "namespace") || _.result(@, "namespace")
@controller = _.result(opts, "controller") || _.result(@, "controller") || @router.controller
@event(name, route) for name, route of @events
@davidbiehl
davidbiehl / mutant_collection.js.coffee
Created October 16, 2014 22:31
Mutant Collection
class MutantCollection extends Backbone.Collection
constructor: (collection, mutator, options = {})->
super(collection.map(mutator), options)
@listenTo collection, 'reset', ->
@reset collection.map(mutator)
@listenTo collection, 'add', (model)->
@add mutator(model)
@davidbiehl
davidbiehl / identity_map.js.coffee
Created October 16, 2014 14:00
Promising Identity Map for Backbone (Draft)
App.module "Data", (Data, App, Backbone, Marionette, $, _)->
class Data.IdentityMap
constructor: (@collection, opts={})->
@promiseAll = false
@promiseEach = {}
if opts.fetch == false
@promiseAll = $.Deferred()
@promiseAll.resolve @collection
@davidbiehl
davidbiehl / Vagrantfile
Created August 7, 2014 14:43
My Favorite Vagrantfile (CentOS 6 with Librarian Puppet)
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos64"
config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210.box"
@davidbiehl
davidbiehl / cr_b_gone.rb
Created July 25, 2014 22:14
Recursively Removes Carriage Returns from Ruby Files
Dir.glob(File.join(%w(** *.rb))) do |filename|
buffer = File.open(filename, "r").read
File.open(filename, "w") do |output|
output.puts buffer.gsub(/\r\n/, "\n")
end
end