From b3eea95eef0786c423e24ab35f36893ad222be2d Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Sun, 25 Nov 2012 12:13:51 +0800 Subject: [PATCH] Updates. --- activeadmin.md | 67 +++++++++++++++++++++++++++++++++++++++++ canvas.md | 42 +++++++++++++++++++++----- pry.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ rails-models.md | 6 +++- 4 files changed, 187 insertions(+), 8 deletions(-) create mode 100644 activeadmin.md create mode 100644 pry.md diff --git a/activeadmin.md b/activeadmin.md new file mode 100644 index 000000000..1253fb5b3 --- /dev/null +++ b/activeadmin.md @@ -0,0 +1,67 @@ +title: ActiveAdmin +--- + +### Listing scopes + +Allows you to filter listings by a certain scope. + + scope :draft + scope :for_approval + +### Sidebar filters + + filter :email + filter :username + +### Custom actions + +You can define custom actions for models. + + before_filter only: [:show, :edit, :publish] do + @post = Post.find(params[:id]) + end + +Make the route: + + member_action :publish, method: :put do + @post.publish! + redirect_to admin_posts_path, notice: "The post '#{@post}' has been published!" + end + +Link it in the index: + + index do + column do |post| + link_to 'Publish', publish_admin_post_path(post), method: :put + end + end + +And link it in show/edit: + + action_item only: [:edit, :show] do + @post = Post.find(params[:id]) + link_to 'Publish', publish_admin_post_path(post), method: :put + end + +### Columns + + column :foo + + column :title, sortable: :name do |post| + strong post.title + end + +### Other helpers + + # Grey, green, orange, red + status_tag "Done" + status_tag "Finished", :ok + status_tag "You", :warn + status_tag "Failed", :error + +### Disabling 'new post' + + ActiveAdmin.register Post do + actions :index, :edit + # or: config.clear_action_items! + end diff --git a/canvas.md b/canvas.md index 55ddd8737..62b007b1d 100644 --- a/canvas.md +++ b/canvas.md @@ -8,16 +8,43 @@ // x = 10, y = 20, width = 200, height = 100 c.fillStyle = '#ff0000'; c.strokeStyle = '#ff00ff'; + c.lineWidth = 5; c.lineCap = 'round'; + c.fillRect(10, 20, 200, 100); + c.stroke(); + c.fill(); + +### Saving and restoring + + c.save(); + + // Saves: + // strokeStyle fillStyle globalAlpha lineWidth lineCap lineJoin miterLimit + // shadowOffsetX shadowOffsetY shadowBlur shadowColor + // globalCompositeOperation + // Transformations: translate rotate scale transform setTransform + // Clipping path + + c.restore(); + +### Transformations + + c.translate(0, 0) + c.rotate(Math.PI*2/5) + c.scale(1.0, 1.0) + +See [MDN: Transformations][xform]. ### Image drawing c.drawImage(image, dx, dy, [dw, dh]); /* `image` can be HTML Image/Canvas/Video */ +See [MDN: Images][images]. + ### Colors, styles shadows c.strokeStyle = '#ff00ff'; @@ -28,6 +55,8 @@ c.shadowOffsetBlur = 3.0; c.shadowColor = 'rgba(0,0,0,0.2)'; +See [MDN: Styles][styles]. + ### Gradients gr = c.createLinearGgadient(x0,y0,x1,y1) @@ -47,12 +76,11 @@ c.arc(...) c.closePath() -### Text +### More resources + * [Canvas Cheatsheet PDF][pdf] - -### Resources - - * [Canvas Cheatsheet PDF][cc] -[cc]: http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.pdf - +[pdf]: http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.pdf +[xform]: https://developer.mozilla.org/en-US/docs/Canvas_tutorial/Transformations +[styles]: https://developer.mozilla.org/en-US/docs/Canvas_tutorial/Applying_styles_and_colors +[images]: https://developer.mozilla.org/en-US/docs/Canvas_tutorial/Using_images diff --git a/pry.md b/pry.md new file mode 100644 index 000000000..c06de2783 --- /dev/null +++ b/pry.md @@ -0,0 +1,80 @@ +title: Pry +-- + +### cd / ls + + > cd Array + + > ls + Array.methods: [] try_convert + Array#methods: & * + abbrev assoc at ... + + > ls # All + + > ls -m # Methods + > ls -M # Instance methods + + > ls -g # Globals + > ls -l # Local vars + > ls -c # Constants + + > ls -i # Instance vars + + > ls -G xx # Grey by regex + +### Shell integration + +shell-mode adds dir to the prompt + + pry(main)> shell-mode + pry(main):/home/x $ + +Commands with `.` are shell commands + + pry(main)> .cat hello.txt + +### Inspection + + > show-method Array#select + + > ri Array#each + > cd Gem + > show-doc try_activate + +Finding + + > find-method each + Array#each + Array#each_index + Enumerable#each_slice + ... + +### Editing + + > edit-method Pry#repl + +### Gems + + > gem-cd foo # Switch to gem's dir + > gem-install foo + > gem-list + +### Misc commands + + > hist # History + > wtf? # Trace of recent exception + +### Rails console + + $ pry -r ./config/environment + +### Bonus: hirb + + > table User.all + > view User.all + > view User.all, fields: %w[id name email] + +### Reference + + * [Pry](https://github.com/pry/pry) + * [Hirb](https://github.com/cldwalker/hirb) diff --git a/rails-models.md b/rails-models.md index 09e54588d..a54db255a 100644 --- a/rails-models.md +++ b/rails-models.md @@ -203,8 +203,12 @@ API item.valid? item.invalid? + * [Guides: callbacks](http://guides.rubyonrails.org/active_record_validations_callbacks.html) -http://guides.rubyonrails.org/active_record_validations_callbacks.html +### Sorting + + posts.order(:title) + posts.order(:title).reverse ### Mass updates