Skip to content

Instantly share code, notes, and snippets.

View andrewmp1's full-sized avatar

Drew Purdy andrewmp1

View GitHub Profile
@deanmraz
deanmraz / component-ember.hbs
Last active August 29, 2015 14:05
Ember Component - From jQuery to Ember
<div {{bind-attr class=":zone showZone::hidden errors:with-notify"}}>
<div class="text">
<button class="btn btn-primary">Browse Computer</button><br>
<p class="sub-text">or drag files here</p>
</div>
<input type="file" name="imageLibraries" multiple>
</div>
{{#unless processing}}
<div class="text completed">
@mindscratch
mindscratch / mongoid_id_monkey_patch.rb
Created August 15, 2011 09:24
Mongoid: return 'id' instead of '_id' when serializing documents as JSON
module Mongoid
module Document
def as_json(options={})
attrs = super options
attrs["id"] = attrs.delete "_id" if attrs.has_key? "_id"
attrs
end
end
end
@stu-smith
stu-smith / form-utility.js
Last active October 1, 2015 20:07
Simple utility methods to copy Backbone models to and from forms
define([
'jQuery',
'Underscore'
], function ($, _) {
'use strict';
return {
clearForm: function (f) {
@BDQ
BDQ / order_decorator.rb
Created November 9, 2012 17:09
Spree API patches to allow 'checkout'.
#order model decorator
Order.class_eval do
accepts_nested_attributes_for :line_items, :allow_destroy => true
def self.build_from_api(user, params)
order = create
params[:line_items_attributes].each do |line_item|
order.add_variant(Spree::Variant.find(line_item[:variant_id]), line_item[:quantity])
end
@wolph
wolph / to_json.sql
Created April 6, 2012 10:35
Some functions to convert arrays/hstore to json :)
CREATE OR REPLACE FUNCTION escape_json (text) RETURNS text AS $$
SELECT replace($1, '''', '\'''); $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(text) RETURNS text AS $$
SELECT escape_json($1) $$ LANGUAGE SQL IMMUTABLE;
CREATE OR REPLACE FUNCTION to_json(KEY text, value text) RETURNS text AS $$
SELECT '''' || to_json($1) || ''': ''' || to_json($2) || ''''; $$ LANGUAGE SQL IMMUTABLE;
@ahawkins
ahawkins / deploy.rb
Created March 29, 2012 13:59
Deploy script for Heroku apps
#!/usr/bin/env ruby
# This is a basic deploy script for Heroku apps.
# It provides a structure you can use to expand on
# and add your own prereqs and deploy tasks.
#
# It basically ensures that:
# 1. There are no uncommited files
# 2. You can ssh to github
# 3. You can connect to heroku
@RoyalIcing
RoyalIcing / Dockerfile
Last active April 2, 2020 17:06
Rails 5.1 Dockerfile
FROM ruby:2.4-alpine
ENV PATH /root/.yarn/bin:$PATH
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh build-base nodejs tzdata
RUN apk update \
&& apk add curl bash binutils tar gnupg \
&& rm -rf /var/cache/apk/* \
@BDQ
BDQ / Import
Created December 3, 2008 21:37
namespace :spree do
desc "Export Products to CSV File"
task :export_products => :environment do
require 'fastercsv'
products = Product.find(:all)
puts "Exporting to #{RAILS_ROOT}/products.csv"
FasterCSV.open("#{RAILS_ROOT}/products.csv", "w") do |csv|
csv << ["id", "name", "description","sku", "master_price" ]
@madhums
madhums / mapreduce.js
Created August 3, 2011 20:33
mapreduce using mongodb and mongoose
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/db_name');
// map function
var map = function(){
emit(this.field_to_group_by, {
other_fields: this.other_fields
// list other fields like above to select them
})
}