This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # execute from terminal | |
| bundle install | |
| rails generate devise:install | |
| rails generate devise user | |
| rake db:migrate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Gemfile.rb | |
| gem 'devise' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # execute from terminal | |
| rails new oauth_example | |
| cd oauth_example | |
| rails g scaffold city name:string postcode:string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config/initializers/devise.rb | |
| config.omniauth :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET_ID'], | |
| scope: 'email', | |
| info_fields: 'email' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/models/user.rb | |
| def self.new_with_session(params, session) | |
| super.tap do |user| | |
| if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"] | |
| user.email = data["email"] if user.email.blank? | |
| end | |
| end | |
| end | |
| def self.from_omniauth(auth) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def make_flat(array, result = []) | |
| array.each do |item| | |
| item.class == Array ? make_flat(item, result) : result << item | |
| end | |
| result | |
| end | |
| puts make_flat([[1,2,[3]],4,[[4,6]]]) == [1,2,3,4,4,6] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ```ruby | |
| def make_flat(array, result = []) | |
| array.each do |item| | |
| item.class == Array ? make_flat(item, result) : result << item | |
| end | |
| result | |
| end | |
| puts make_flat([[1,2,[3]],4,[[4,6]]]) == [1,2,3,4,4,6] | |
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use DBIish; | |
| my $mdriver = 'Pg'; | |
| my $host = 'localhost'; | |
| my $port = 5432; | |
| my $database = 'inframe_dev'; | |
| my $test_user = 'postgres'; | |
| my $test_password = 'blabla'; | |
| my $drh = DBIish.install_driver($mdriver); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (!body->lib_handle) { | |
| INTVAL pos = STRING_index(interp, $2, Parrot_str_new(interp, ".bundle", 0), 0); | |
| if (pos >= 0) { | |
| STRING *lib_name_alternative = Parrot_str_replace(interp, $2, pos, 7, Parrot_str_new(interp, ".dylib", 0)); | |
| lib_name_2 = Parrot_str_to_cstring(interp, lib_name_alternative); | |
| body->lib_name = lib_name_2; | |
| body->lib_handle = dlLoadLibrary(strlen(lib_name_2) ? lib_name_2 : NULL); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| char *lib_name_2; | |
| /* Initialize the object; grab native call part of its body. */ | |
| NativeCallBody *body = get_nc_body(interp, $1); | |
| /* Try to load the library. */ | |
| body->lib_name = lib_name; | |
| body->lib_handle = dlLoadLibrary(strlen(lib_name) ? lib_name : NULL); | |
| if (!body->lib_handle) { |