Skip to content

Instantly share code, notes, and snippets.

@ksin
ksin / copy_attachments.rb
Last active February 13, 2017 19:59
Paperclip copy attachments s3
### s3 implementation of Paperclip module that supports deep
### cloning of objects by copying image attachments.
### Refer to Paperclip issue: https://github.com/thoughtbot/paperclip/issues/1361#issuecomment-39684643
### Original gist works with fog: https://gist.github.com/stereoscott/10011887
module Paperclip
module CopyAttachments
def copy_attachments_from(source_obj, source_bucket = nil, destination_bucket = nil)
self.class.attachment_definitions.keys.each do |attachment_name|
source_attachment = source_obj.send(attachment_name)
def to_roman(num)
results = ""
if num % 5 == 4
if num > 5
results = "IX"
else
results = "IV"
end
elsif num == 5
# Convert an integer into its English equivalent.
def in_words(int)
# Your glorious code here
end
### Test code
in_words(4) # => "four"
in_words(27) # => "twenty seven"
in_words(102) # => "one hundred two"
module Roman
MAP = {
1000 => "M",
900 => "CM",
500 => "D",
400 => "CD",
100 => "C",
90 => "XC",
50 => "L",
40 => "XL",
module Numbers
WEIRD = {
0 => "zero",
1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
6 => "six",
7 => "seven",
#Cookies & Ovens
#Oven
#-on, off -empty, full
#-temperature -how many cookies it has?
#-store cookies in it. making instances of Cookie and passing them into Oven
#oven has many cookies
#Cookie
#-doughy, baked, burnt
@ksin
ksin / components.alert-pow.js
Last active October 15, 2015 17:38
Twiddle to see if overriding .on works
import Ember from 'ember';
export default Ember.Component.extend({
powPow: function() {
alert('POW POW POW!!!');
}.on('didInsertElement')
});
import Ember from 'ember';
import { moduleForComponent } from 'ember-qunit';
export default function (name, options={}) {
moduleForComponent(name, {
integration: true,
setup() {
this.select = function (from, text) {
let $el = this.$(from);
let $option = $el.find(`option:contains(${text})`);
@ksin
ksin / controllers.application.js
Created February 19, 2019 18:19
Null and undefined in hbs
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
nullProperty: null,
undefinedProperty: undefined
});