git verbose pull
To get a more verbose output when doing a pull, you can have this:
GIT_CURL_VERBOSE=1 GIT_TRACE=1 git pull
access google+ API from node.js
Steps:
- enable Google+ API in google console
- create credentials for
1
Web Application
- here’s the code snippet I used to obtain the code:
const google = require('googleapis');
const dotenv = require("dotenv").config();
const exec = require('child_process').exec;
const util = require("util");
const readline = require('readline');
const rl = readline.createInterface(process.stdin, process.stdout);
let client_id = process.env.GOOGLE_APP_CLIENT_ID,
client_secret = process.env.GOOGLE_APP_CLIENT_SECRET;
let app_google_auth_url = process.env.GOOGLE_APP_AUTH_URL;
let client = new google.auth.OAuth2(client_id, client_secret, app_google_auth_url);
console.log(`client_id ${client_id} client_secret ${client_secret} oauth_url ${app_google_auth_url}`);
let scopes = [
'https://www.googleapis.com/auth/plus.me'
];
let url = client.generateAuthUrl({
access_type: 'offline',
scope: scopes
});
console.log(`URL:${url}`);
rl.setPrompt('enter authorization code here> ');
rl.prompt();
rl.on('line', function(line) {
client.getToken(line, function(err, tokens) {
if(!err) {
console.log(util.inspect(tokens));
}
process.exit(0);
});
}).on('close',function(){
process.exit(0);
});
- I’m using
for node in this example, and I had the values for client_id, client_secret, and the redirect url mentioned there.1
dotenv
- at some point, the application will show the URL in the console, copy it and visit it in your browser
- google will redirect to your registered application URL with a
parameter. Write that down, paste it, and press enter. For this purpose, I had a rails app running in the background, with a1
code
so that I could inspect what’s sent as1
binding.pry
.1
params
- you will then see in the console the access_token, refresh_token and expiry_date. Those you can use when you make the API calls.
gunzip without overwriting interactively
This will keep the archive after decompressing, and in case a file already exists, instead of seeing the prompt with
,
1
do you with to overwrite
will instead be sent. Found solution here1
n
yes n | gzip -v -dk *.gz
ruby can't dump hash with default proc
Received the error ruby can’t dump hash with default proc. It was raised by a 3rd party lib, that was using
.
Turns out, I had a hash defined like this:1
Marshal.dump
hash = Hash.new{|h,k| h[k] = []}
The fix was to remove the initialization block, and instead use it like this in my code:
hash[some_value] ||= []
hash[some_value] << some_other_value
postgresql installed via homebrew that won't start
After a reboot, postgresql wouldn’t start. Tried
and still nothing.
Checked the /usr/local/var/postgres/server.log and it was complaining about /usr/local/var/postgres/postmaster.pid.
My first thought was to delete it, but I ran a google search before. Luckily, I found this link where
it clearly says that deleting the pid file is not recommended. So, I ran a cat command and found the PID ( it’s the first line in the file ),
and did a kill -9 PID. After that, running again brew services postgresql restart worked, and PG booted.1
brew services restart postgresql
run custom jquery in ember route
Needed to initialize some jquery elements in a route. This provided the answer:
export default Ember.Route.extend({
actions: {
didTransition() {
Ember.run.next(this, 'initTooltip');
}
},
initTooltip() {
Ember.$('[data-toggle="tooltip"]').tooltip();
}
});
find empty json objects in postgres
Say you have a content column of type json, which holds arrays, and you want to delete the empty ones:
select * from events where content::text = '[]'::text;
ember check if model settled before displaying
If you have a model with relationships, the
property could be of some use, to avoid drawing only partial state, in case of ajax,
or even screen flickering:1
isSettled
Display some data here Loading ...