Skip to content

Instantly share code, notes, and snippets.

# config/initializers/devise.rb
# for web
config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'],
{ access_type: "offline",
prompt: "consent",
select_account: true,
provider_ignores_state: true,
scope: "plus.profile.emails.read,calendar,contacts" }
# for api
let result = await fetch({
api: "http://localhost:3000/users/auth/google_oauth2_for_api/callback",
method: 'get',
params: {
code: response.params.code,
redirect_uri: redirectUrl
}
})
// The result is from rails side.
let redirectUrl = Expo.AuthSession.getRedirectUrl();
let response = await Expo.AuthSession.startAsync({
authUrl:
`https://accounts.google.com/o/oauth2/v2/auth?` +
`&client_id=${GOOGLE_WEB_APP_ID}` +
`&redirect_uri=${encodeURIComponent(redirectUrl)}` +
`&response_type=code` +
`&access_type=offline` +
`&prompt=consent` +
`&scope=${encodeURIComponent('https://www.googleapis.com/auth/plus.profile.emails.read https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/contacts')}`,
@ilake
ilake / wallet.js
Last active September 28, 2017 08:33
var wallet = artifacts.require("./MyWallet.sol");
var receivedProposal = function (walletInstance, from, to) {
return new Promise((resolve, reject) => {
var event = walletInstance.proposalReceived({from: from, to: to}, {fromBlock: 0, toBlock: "latest"});
event.watch(function(error, response) {
event.stopWatching();
if (error) {
# find node name is gd:email and attribute rel value contains work wording
node = doc.xpath("//*[name()='gd:email'][contains(@rel, 'work')]").first
# change email address attribute value
node.attributes["address"].value = value[:address]
# change node content <node>{content is here}</node>
node.content = value
# remove all nodes that name is gd:phoneNumber
> Rails.application.config_for(:database)
=> {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"listia_development", "pool"=>5, "username"=>"listia", "socket"=>"/tmp/mysql.sock"}
> h = Hashie::Mash.new(Rails.application.config_for(:database))
=> #<Hashie::Mash adapter="mysql2" database="listia_development" encoding="utf8" pool=5 reconnect=false socket="/tmp/mysql.sock" username="listia">
> h.adapter
=> "mysql2"
> h.database
=> "listia_development"
# When you use select * for update, other process only could touch the query when it be `committed`
# Query 1
User.transaction do
User.find(1).groups.joins(:owner).lock.each(&:destroy)
end
User.transaction do
# If the groups has same owner, it will wait the query 1
# If not, it will continue
#include "stdio.h"
bool leap_year(int y) {
int is_leap;
is_leap = (y % 400 == 0) ||
((y % 4 == 0) && !(y % 100 == 0));
return is_leap;
}
int main(void) {
#include "stdio.h"
int main(void) {
int leap_year(int y)
{
int is_leap;
is_leap = (y % 400 == 0) ||
((y % 4 == 0) && !(y % 100 == 0));
return is_leap;
}
# Some default enhancements/settings for IRB, based on
# http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks
unless defined? ETC_IRBRC_LOADED
# Require RubyGems by default.
require 'rubygems'
# Activate auto-completion.
require 'irb/completion'