Skip to content

Instantly share code, notes, and snippets.

@marcioj
marcioj / tinymce-view
Created July 29, 2013 21:09
Integration of Tinymce with emberjs
Ember.TinymceView = Ember.TextArea.extend({
editor: null,
_suspendValueChange: false,
didInsertElement: function(){
var id = "#" + this.get("elementId");
var view = this;
tinymce.init({
selector: id,
setup : function(ed) {
view.set("editor", ed);
@marcioj
marcioj / boostrap-carousel-view.js
Last active December 20, 2015 16:28
Bootstrap carousel with ember.js
@marcioj
marcioj / video-templates.html
Created August 11, 2013 22:04
Displays a video with data binding using ember.js http://jsfiddle.net/marciojunior/KZxgp/.
<script type="text/x-handlebars" data-template-name="video">
{{view view.embedView}}
</script>
<script type="text/x-handlebars" data-template-name="embed">
<object width="640" height="390">
<param name="movie" {{bindAttr src="view.src"}} ></param>
<param name="allowScriptAccess" value="always"></param>
<param name="playerapiid" value="main"></param>
<embed {{bindAttr src="view.src"}} type="application/x-shockwave-flash" allowscriptaccess="always" width="640" height="390"></embed>
@marcioj
marcioj / application_helper.rb
Last active April 25, 2016 19:12
Url normalization. Appends http to url which doesn't have it
module ApplicationHelper
def expand_url(url)
return url if url.blank? || /(http:\/\/|https:\/\/)/ =~ url
"http://#{url}"
end
end
@marcioj
marcioj / sublist.js
Created June 29, 2014 21:30
sublist.js
#!/usr/bin/env node
/**
*
* Utility function to not become the code more confuse
*
* Iterates over an array with a advantage of reset the
* iterator and start again in the first element of the array
* increasing the initial index to one
*
@marcioj
marcioj / Gemfile.rb
Created August 28, 2014 15:52
Organize js files in rails
# ...
gem 'jquery-turbolinks' # for not bother with vendor plugins not loading
gem 'es6_module_transpiler-rails' # to use es6 modules
# ...
@marcioj
marcioj / sessions_controller_spec.rb
Created October 14, 2014 21:52
Supress devise flash messages
require 'rails_helper'
RSpec.describe Devise::SessionsController, :type => :controller do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
end
def action
post :create
end
@marcioj
marcioj / controller_spec.rb
Last active August 29, 2015 14:10
Template to scaffold controller with rspec, factory girl, shoulda matchers
# Put this in lib/templates/rspec/scaffold/controller_spec.rb
require 'rails_helper'
<% module_namespacing do -%>
RSpec.describe <%= controller_class_name %>Controller, :type => :controller do
<% unless options[:singleton] -%>
describe "GET #index" do
let!(:<%= file_name %>) { create(:<%= file_name %>) }
@marcioj
marcioj / index.js
Created December 2, 2014 04:09
Regenerator
// app/routes/users/index.js
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
remove: function(model) {
if(confirm('Are you sure?')) {
model.destroyRecord();
}
@marcioj
marcioj / controller_macro.rb
Created January 13, 2015 20:44
Devise rspec controller macro
# Taken from https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-(and-RSpec),
# with some minor changes
module ControllerMacros
def login_admin(&proc)
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:admin]
admin_user = proc ? instance_eval(&proc): FactoryGirl.create(:admin_user)
sign_in admin_user
end