Skip to content

Instantly share code, notes, and snippets.

View drKreso's full-sized avatar

Kresimir Bojcic drKreso

View GitHub Profile
# execute from terminal
bundle install
rails generate devise:install
rails generate devise user
rake db:migrate
# Gemfile.rb
gem 'devise'
# execute from terminal
rails new oauth_example
cd oauth_example
rails g scaffold city name:string postcode:string
# config/initializers/devise.rb
config.omniauth :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET_ID'],
scope: 'email',
info_fields: 'email'
# 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)
@drKreso
drKreso / array_helper.rb
Created October 24, 2016 20:40
Make array flat
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]
```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]
```
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);
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);
}
}
@drKreso
drKreso / gist:5070534
Last active December 14, 2015 10:10 — forked from anonymous/gist:5070416
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) {