Skip to content

Instantly share code, notes, and snippets.

Avatar

Amiel Martin amiel

View GitHub Profile
@amiel
amiel / application_decorator.rb
Created Nov 3, 2011
Some handy I18nization for my ApplicationDecorator
View application_decorator.rb
class ApplicationDecorator < Draper::Base
# See +ApplicationDecorator.humanize+
def humanize(attribute, key = model.send(attribute), default = key.to_s.humanize)
self.class.humanize attribute, key, default
end
# By default, humanize the attributes listed.
#
# Contrived Example:
@amiel
amiel / my_uploader.rb
Created May 22, 2012
Simple watermarking with Thumbkit and CarrierWave
View my_uploader.rb
class MyUploader < CarrierWave::Uploader::Base
include Thumbkit::Adapters::CarrierWave
# Watermark should always be processed after thumbkit, ensuring that we always
# have a valid image and we don't need to change the extension
def watermark(watermark_image, options = {})
cache_stored_file! if !cached?
Watermarker.new(current_path, watermark_image).watermark!(options)
end
View adapters.shop-language.js
import Adapter from 'ember-data/adapters/json-api';
import UrlTemplates from "ember-data-url-templates";
export default Adapter.extend(UrlTemplates, {
urlTemplate: '/shops{/shopId}/languages{/id}',
});
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
});
@amiel
amiel / README.md
Created Oct 28, 2011
post-commit git hook for simple deploys
View README.md

Put the ruby file in .git/hooks/post-commit

Create a deploy script as .deploy_*

Example:

# File: .deploy_production
scp -R html example.com:public_html

Then use "deploy *" in your commit message.

View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
init() {
this._super(...arguments);
this.set('myArray', []);
},
getNewItem() {
@amiel
amiel / my-controller.js
Created May 8, 2014
ember-validators with server validation errors
View my-controller.js
MyController = Ember.Controller.extend({
actions: {
save: function() {
this.get('model').save().then(function() {
// Success, maybe transitionToRoute or whatever
}, function(xhr) {
// Oh noes, we had an error, maybe it's a validation error
if (xhr.status == 400) {
$.parseJSON(xhr.responseText).each(function(attribute, errors) {
this.get('errors').set(attribute, errors);
@amiel
amiel / adapters.user.js
Last active Dec 23, 2016 — forked from samselikoff/mirage.config.js
Mirage dev boilerplate
View adapters.user.js
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
buildURL(type, id) {
return `/users/${id}.json`;
},
});
@amiel
amiel / controllers.application.js
Last active Sep 9, 2016
Example PromiseProxyMixin issue
View controllers.application.js
import Ember from 'ember';
const { inject } = Ember;
export default Ember.Controller.extend({
myService: inject.service(),
appName: 'Ember Twiddle',
});
@amiel
amiel / delete.js
Created Jun 16, 2016
Usage of delete in javascript
View delete.js
object = { foo: 'bar', foobar: undefined };
$.param(object); // => "foo=bar&foobar="
delete object.foobar;
$.param(object); // => "foo=bar"
You can’t perform that action at this time.