16 3 / 2013
After creating my first errbit cookbook, and publishing it on the chef community site, I’d to do some stretches to publish it.
First, you need to tgz your cookbook and it should have the
metadata.json file otherwise the validation fails and the cookbook won’t be published.
So, I am putting it here for me and others:
In your cookbook dir, create a dir
.chef with a
knife.rb file in it with the following line:
Then issue the command
knife cookbook metadata . (Don’t forget the dot)
This will generate
Better to commit it here and push the changes to your git repo.
Now step out 1 dir path from your cookbook folder and do the compressing.
cd .. tar -czf errbit.tgz --exclude bin --exclude .envrc --exclude .vagrant --exclude .bundle errbit
You might have to change/add the
--exclude vars according to your setup.
Now we’ve the
errbit.tgz file with the
metadata.json file in it which you can upload to the community site at http://community.opscode.com/cookbooks/new
When updating the cookbook later, do change the version in
metadata.rb file and repeat the same process to publish your cookbook’s changes.
Permalink 1 note
01 3 / 2013
Its always tricky to post on the wall of the FB Page. It requires PAGE_ID and ACCESS_TOKEN (Not the user’s access token) and so many questions on how to get facebook page id and access token.
The FB Developers webapp way
First create a page by visiting http://www.facebook.com/pages/create.php?ref_type=sitefooter But this is optional. If you’ve already created the page, the just skip this part.
Create an App
Created App admin page
Graph API Explorer
Get Access Token
In the Extended Permissions tab, select manage_pages and publish_stream and click Get Access Token
Authorize you account
Copy the blue-highlighted temporary access token
Permanent Access Token
The above temporary access token is also valid. But its limited to 60 days. Its better to have the permanent access token so that it works in the long run, though I forget to updated periodically.
To get this, go the following url replacing the TEMPORARY_ACCCESS_TOKEN value with the temporary access token.
First we need to get the PAGE_ID of the page. To get this, visit https://www.facebook.com/pages/
And on the left sidebar under Pages section, select the page.
Copy the Page id from the address bar
Here I’m using the fb_graph gem
require ‘rubygems’ require ‘fb_graph’ require ‘pry’ FbGraph.debug!
PAGE_ID = “349835561791721” YOUR_ACCESS_TOKEN = “……”
owner = FbGraph::User.me(USER_ACCESS_TOKEN) pages = owner.accounts
page = pages.detect do |page| page.identifier == PAGE_ID end
There is the page access_token
07 12 / 2012
In some situation, I’d to invoke rake task from the console itself. This makes me do it that with just 3 lines of code right from the rails console.
require 'rake' MyApp::Application.load_tasks Rake::Task['the_rake_task'].invoke
28 11 / 2012
Dealing with the singleton resource was quite a bit tricky:
# config/routes.rb resource :passion # form.html.slim = form_for @passion do |f|
Throws an error:
undefined method `passions_path' for #<#<Class:0x0000012d957008>:0x000001347f1ae0>`
So the fix is:
= form_for @passion, url: passion_path do |f|
23 9 / 2012
While building a Gem or API or any rubyish, the active_support library comes in so handy. So, listing here some usages as a reminder for me (maybe for you too).
- Mongoid Indifferent Access
- Ruby on Rails3 Tutorial Book Ref
I’ll be updating this list as I find its other use-cases or you can add on the comments and I’ll update this.
Permalink 1 note