AngularJS and Uglifier don't mix well.
Uglifier’s mangling messes with AngularJS. To turn it off you should do something like…
# config.assets.js_compressor = :uglifier
config.assets.js_compressor = Uglifier.new(mangle: false) if defined? Uglifier
“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it Currently working for GenieBelt who are based in Copenhagen, Denmark ...”
Uglifier’s mangling messes with AngularJS. To turn it off you should do something like…
# config.assets.js_compressor = :uglifier
config.assets.js_compressor = Uglifier.new(mangle: false) if defined? Uglifier
I totally managed to mess up my Gemfile.lock file setting the versions of many gems to far higher versions than I’d intended. bundle update is bad, even if you set the version in your Gemfile the dependencies of thos gems are not versioned so precisely. I did this in a branch so fortunately the Gemfile.lock in my master branch is accurate.
git checkout master -- Gemfile.lockThat did the job. Then a bundle install puts the changes I’d made to my Gemfile into Gemfile.lock with the correct dependencies as per master. Phew.
If you upgrade to MacOSX Yosemite and get this
Robs-iMac:~ rl$ brew install
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 26: /usr/local/Library/brew.rb: Undefined error: 0you need to do this
cd /usr/local/Library
git pull origin masterThen you’re good again.
Hmmmzzz..
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/rl/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb
creating Makefile
make "DESTDIR=" clean
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
make "DESTDIR="
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
make failed, exit code 69
Gem files will remain installed in /Users/rl/.rvm/gems/ruby-2.1.2@upgrade-ruby/gems/byebug-3.5.1 for inspection.
Results logged to /Users/rl/.rvm/gems/ruby-2.1.2@upgrade-ruby/extensions/x86_64-darwin-13/2.1.0-static/byebug-3.5.1/gem_make.out
An error occurred while installing byebug (3.5.1), and Bundler cannot continue.
Make sure that `gem install byebug -v '3.5.1'` succeeds before bundling.You need to do sudo xcrun cc
..blah blah blah...
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel] agree
If you’re used to rendering your JSON response via call to_json on a collection on an object then it really is as simple as adding the callback option to render. You must ensure the callback parameter on the client end is the correct parameter than you feed to the callback option in your controller. This allows your JSON to be server without or without wrapping the response with a callback function depending on whether you include the callback parameter.
class Api
def index
respond_to do |format|
format.json do
render :json => Thing.all.to_json, :callback => params[:callback]
end
end
end
endHowever, if you use JBuilder or any other JSON template engine then you’ll need to do things slightly differently. Here There is no need to change your controller method at but instead you can wrap the json repsonse in an after_filter which is a little cleaner.
class Api < ApplicationController
after_filter :wrap_response_with_callback
def index
respond_to do |format|
format.json
end
end
private
def wrap_response_with_callback
if request.get? && params[:callback] && params[:format].to_s == 'json'
response['Content-Type'] = 'application/javascript'
response.body = "%s(%s)" % [params[:callback], response.body]
end
end
end
This seemed pretty straight forward to me.
module Something
def api
@api ||= Api.new
end
class Api
def do_something
:doing_something
end
end
end
class Thing
include Something
class Api
def do_thing
:doing_thing
end
end
endSeems legitimate, just extend the class that I’ve included in my module.
2.1.2 :021 > Thing.new.api.do_thing
NoMethodError: undefined method `do_thing' for #<Something::Api:0x007f946546afe0>
from (irb):21
from /Users/rl/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'Wrong! Hmmzz…. I guess the class that the module is instantiating from is the one in the module not the one included in my Thing class I need to ensure that I instantiate from the right one.
module Something
def api
@api ||= self.class::Api.new
end
class Api
def do_something
:doing_something
end
end
end
class Thing
include Something
class Api
def do_thing
:doing_thing
end
end
end
</pre></code>
Works, but hang on.
<pre><code>
2.1.2 :019 > Thing.new.api.do_thing
=> :doing_thing
2.1.2 :020 > Thing.new.api.do_something
NoMethodError: undefined method `do_something' for #<Thing::Api:0x007fa60a4c1fc8>
from (irb):20
from /Users/rl/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'The class is not using the class I’ve defined in my module at all.
module Something
def api
@api ||= self.class::Api.new
end
class Api
def do_something
:doing_something
end
end
end
class Thing
include Something
class Api < Something::Api
def do_thing
:doing_thing
end
end
endBetter,
You can create a transparent PNG with Imagemagick fairly easily.
Robs-MacBook-Pro:lcf roblacey$ convert -size 200x100 xc:none transparent.pngSuppose you wanted to base64 the output to embed it in HTML
Robs-MacBook-Pro:lcf roblacey$ convert -size 200x100 xc:none png:fd:1 | base64 -i - -o -
iVBORw0KGgoAAAANSUhEUgAAAMgAAABkAQAAAADr/UKmAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAnRSTlMAAHaTzTgAAAACYktHRAAB3YoTpAAAABlJREFUSMftwYEAAAAAw6D5Ux/gClUBAMAbCigAAUr66mAAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTQtMTEtMDdUMDI6MDE6NDcrMDA6MDCn12GlAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE0LTExLTA3VDAyOjAxOjQ3KzAwOjAw1orZGQAAAABJRU5ErkJggg==Of course when I do this in HTML…..
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkAQAAAADr/UKmAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAnRSTlMAAHaTzTgAAAACYktHRAAB3YoTpAAAABlJREFUSMftwYEAAAAAw6D5Ux/gClUBAMAbCigAAUr66mAAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTQtMTEtMDdUMDI6MDE6NDcrMDA6MDCn12GlAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE0LTExLTA3VDAyOjAxOjQ3KzAwOjAw1orZGQAAAABJRU5ErkJggg==">The image is transparent and therefore you can’t see it.
This one is mildly more interesting, maybe.
Robs-MacBook-Pro:lcf roblacey$ convert -size 200x100 xc:"#000000" png:fd:1 | base64 -i - -o -
iVBORw0KGgoAAAANSUhEUgAAAMgAAABkAQAAAADr/UKmAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAnRSTlMAAHaTzTgAAAACYktHRAAB3YoTpAAAABlJREFUSMftwYEAAAAAw6D5Ux/gClUBAMAbCigAAUr66mAAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTQtMTEtMDdUMDI6MDE6NDcrMDA6MDCn12GlAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE0LTExLTA3VDAyOjAxOjQ3KzAwOjAw1orZGQAAAABJRU5ErkJggg==Wait for it…….
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkAQAAAADr/UKmAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAAZSURBVEjH7cGBAAAAAMOg+VMf4ApVAQDAGwooAAFK+upgAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE0LTExLTA3VDAyOjEwOjM1KzAwOjAwFMHNawAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNC0xMS0wN1QwMjoxMDozNSswMDowMGWcddcAAAAASUVORK5CYII=">…worth waiting for.
TextileEditorHelper even though I had to then hack the helper to not overwrite the textarea class.
module ActionView::Helpers
module FormHelper
def textile_editor(object_name, method, options = {})
output = []
name = "#{object_name}[#{method}]"
output << text_area_tag(name, nil, options.merge(class: [options[:class], 'textile_editor'].reject(&:blank?).join(' ')))
output.join("\n").html_safe
end
end
endTrying to work out why compressing jQuery in Rails 4 breaks IE8. Then realising.
jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8.
and the BitMapCatNap

Waking up to an unexpected encoding error. Turns out the client has posted bullet points in their form data. It appears this isn’t working because the database is actually encoded in Latin1. Whereas it should be UTF-8.
An ActiveRecord::StatementInvalid occurred in jobs#create:
Mysql2::Error: Incorrect string value: '\xE2\x80\xA8\x0D\x0A\x0D...' for column 'description' at row 1: INSERT INTO `stuffs`Converted the character set to UTF-8 easily. However, through checking is probably prudent given that mixed encodings and converting them can have unexpected results
mysql> ALTER TABLE stuffs CONVERT TO CHARACTER SET utf8;
Query OK, 2350 rows affected (1.25 sec)
Records: 2350 Duplicates: 0 Warnings: 0
Different kind of Programming this time Drum Programming Guide $15. Bargain.
