Tuesday, December 31, 2013

Code Test

Code Snippets

I’m testing out StackEdit as a blog writing tool. Hopefully this shows some code snippets.

Example Octopress

rake new_page["Hello World"]
rake preview
rake generate

Code block

Hello world
How are you?

Java

  Object obj = new Object();
  obj.getName();

Objective C

  NSString *string = @"Hello World";
  NSDictionary *dictionary = @{ @"title": string };

Written with StackEdit.

Monday, July 15, 2013

Command failed with status (65): [xcodebuild -project ios-sim.xcodeproj]

I'm writing a Sencha/PhoneGap app which has been a story by itself, but here's a problem that I ran into today and solved relatively quickly. I was in the process of install PhoneGap's ios-sim package with Homebrew. I ran into the following error after running brew install ios-sim:

The following build commands failed:
    Ld build/ios-sim.build/Release/ios-sim.build/Objects-normal/i386/ios-sim normal i386
    Ld build/ios-sim.build/Release/ios-sim.build/Objects-normal/x86_64/ios-sim normal x86_64
(2 failures)
rake aborted!
Command failed with status (65): [xcodebuild -project ios-sim.xcodeproj -con...]

Ugh...

Turns out that xcodebuild was pointing to XCode Developer Preview 2, which is not supported by ios-sim. Makes sense. So the solution is to change the path that xcodebuild points to. So I looked for where xcodebuild was pointing.

Jims-MacBook-Air:ios-sim jamesslien$ xcode-select -print-path
/Applications/Xcode5-DP2.app/Contents/Developer

And changed the path using the switch command

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

After that brew installed ios-sim and I'm on my way to packaging up the app for release on iPhone and Android.

Written with StackEdit.

Wednesday, March 6, 2013

Saving User Location · intridea/omniauth Wiki · GitHub

Customizing the callback of an OAuth request using Omniauth is pretty simple.  In you sessions controller where you save the OAuth token, simply add a redirect to omniauth.origin or some other desired destination.  omniauth.origin saves the user's  last location using the http_referrer.



class SessionsController < ApplicationController
  def callback
    # do your authentication stuff here...
    redirect_to request.env['omniauth.origin'] || '/default'
  end
end
I ended up setting the origin in my urls directly.
/auth/twitter?origin=%2Fusers%2Fshow%2F24

Tuesday, February 26, 2013

Wrap Long Strings in Rails


Below is a helper method to wrap long strings.

def wrap(content)
    sanitize(raw(content.split.map{ |s| wrap_long_string(s) }.join(' ')))
end

private

    def wrap_long_string(text, max_width = 30)
      zero_width_space = "&#8203;"
      regex = /.{1,#{max_width}}/
      (text.length < max_width) ? text : 
                                  text.scan(regex).join(zero_width_space)
    end

Pushing to Heroku after Model Migration

Just some stuff to remember after after pushing a rails project to Heroku or some other PaaS when it contains a migration.
In the Terminal:
$ git push heroku
$ heroku pg:reset DATABASE
$ heroku run rake db:migrate
$ heroku run rake db:populate # if you have a db rake utility to fill your database with sample data