Chao Lam

Working on the next small things …

Integrating your app with Zapier using OAuth2

leave a comment »

If you’re trying to add your own trigger or action for Zapier, and your end point is only accessible via a valid OAuth2 token, be sure to add the Bearer token in the API end point headers!

Here’s what I tripped me for a couple of hours:

I had some API end point. I even tested it as a “test” end point when setting up OAuth v2 authentication and everything worked. But the end point kept returning a 401 Unauthorized code.

I finally figured out I had to manually add the OAuth2 access token http header for each endpoint url:

Advertisements

Written by Chao

July 22, 2019 at 9:39 pm

Posted in Uncategorized

Twitter Activity Webhook – Inexplicable error

leave a comment »

I had some code relying on Twitter’s Activity Webhook which I hadn’t touched for a while.

Today, when I started playing around with the project again, I got this inexplicable error that took me a while to figure out:
HTTP Error 348: Client application is not permitted to access this user’s webhook subscriptions

After many other rabbit holes, I finally found the solution. It turns out if you have changed your Twitter apps permissions, your accessToken and accessTokenSecret keys will be changed

But that isn’t the half (or quarter of it :). These changed keys won’t help you create a subscription. You now need to go to your “regular” Twitter account “app and settings” and revoke access to this app. Finally, you need to regenerate the apps access token and access token secret.

Phew! Would never figured this out without this helpful link:
https://twittercommunity.com/t/getting-error-code-348-while-trying-to-add-subscription/101796

Once again coding by googling ftw!

Written by Chao

May 2, 2019 at 5:21 pm

Posted in Uncategorized

Force legacy database using BLOBs to behave as utf-8 strings in rails

leave a comment »

I was working on a legacy mysql database which had a BLOB column “user_name”. I think it used a blog so that it could have emojis as strings (before utf8mb4?)

Anyway, my action mailer emails were failing when they encountered these emoji characters. ActiveRecord does all these magical things behind the scenes, but unfortunately it was magically convert the BLOB to 8-bit ASCII upon which action mailer barfed when it encountered these emoji characters.

Finding the issue was the hard part, the fix was easy:

  def user_name
    self.attributes['user_name'].force_encoding('utf-8')
  end

Written by Chao

April 23, 2019 at 6:01 pm

Posted in Uncategorized

TLS/SSL on Mac Postgres.app

leave a comment »

This article was helpful but out of date:
http://blog.workherder.com/enable-ssl-in-the-postgres-app-on-mac-os-x/

This is the latest Postgres 11 docs to create self-signed certs:
https://www.postgresql.org/docs/11/ssl-tcp.html

This talks about creating client certs but I’m not sure if it’s needed (at least if client/server are on the same machine):
https://www.howtoforge.com/postgresql-ssl-certificates

Written by Chao

April 2, 2019 at 11:08 pm

Posted in Uncategorized

Default Active Record tables to utf8mb4 encoding

leave a comment »

I found several articles on how to convert existing rails tables to support 4-byte unicode characters including emojis but didn’t find one talking about how to create a new table.

So, here’s the code I used:

create_table :twitter_users, {options:"DEFAULT CHARSET=utf8mb4"} do |t|
...
t.timestamps
end

Written by Chao

February 14, 2019 at 10:14 pm

Posted in Uncategorized

Adventures in KenKen

leave a comment »

My Mom enjoys sudoku and I like playing KenKen!

Here’s one I think is worth replaying:

I quickly started out with the basic rules to get this layout:

The only “given” 3 provides a clue to the 45x at the top. The candidates are 1335, given the fixed 3, there can be only 2 possible set of positions for the 45x. A tricked I figured out for 19+ is that it cannot contain digits 1,2 and 3. Thus :

With the double 3s in place, looking at 168x, there are two possible combinations 378 or 467. The double 3s preclude 378, so 467 it is! And with our 21+ eliminating 6 and 7, one of those squares can only be a 4:

Then, looking at the 48x just below 168x, We know there are 4 possible combinations: 344, 624, 618, 328. The first is now eliminated with the 4. 624 and 614 are also eliminated because of the 67 above. So the only combination left is 328:

Now looking at 112x at the bottom. there are 3 combinations: 7144,7224,7128. But the double 2s and 4s are not possible because of the double 24s on the last column (and last two rows). So the only combination 7128. After applying some other clean on the left, we get:

Now here comes a tricky part: The two pairs 15 and 56 circled above, ensures that 19+ cannot have a 5. When 5 is eliminated, 19+ then also cannot have a 6. In fact, the only combination left standing is 478:


Looking at 70x, we know it needs a 2 (in 257), so the 8+ above cannot have a 2, which means it’s 17. Hence (with more cleanup):

becomes:

which collapses and leads to the solution:

Written by Chao

February 11, 2018 at 5:54 am

Posted in Uncategorized

IFTTT maker (webhook) test with Curl

leave a comment »

IFTTT used to have a test page for developers who wanted to implement the Maker (now called webhook) trigger. Unfortunately they initially hid it and then finally removed it entirely (not sure why). But here’s a command line curl command to simulate the test page:

curl -H “Content-Type: application/json” -X POST -d ‘{“value1″:”xyz”,”value2″:”222″}’ https://maker.ifttt.com/trigger/<$YourEventName>/with/key/<$YourOwnKey&gt;

where <$YourEventName> = your IFTTT app event name

<$YourOwnKey> = user’s IFTTT key

 

Written by Chao

March 22, 2017 at 10:22 pm

Posted in Uncategorized