Skip to content

Instantly share code, notes, and snippets.

View ArthurZheng's full-sized avatar
😊

Jun ArthurZheng

😊
  • The Australian Access Federation
  • Melbourne Vic, 3000 Australia
View GitHub Profile
@ArthurZheng
ArthurZheng / example.md
Created September 20, 2017 01:50 — forked from pcn/example.md
Using jq to get+filter aws data

I've been playing with jq, and I've been having a hard time finding examples of how it works with output from a service like AWS (which I use a lot).

Here is one I use a lot with vagrant-ec2.

When we're launching and killing a lot of instances, the AWS API is the only way to track down which instances are live, ready, dead, etc.

To find instances that are tagged with e.g. {"Key" = "Name", "Value" = "Web-00'} in the middle of a vagrant dev cycle, or a prod launch/replace cycle, you can do something like this:

require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@ArthurZheng
ArthurZheng / rspec_model_testing_template.rb
Created December 4, 2017 05:30 — forked from PWSdelta/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@ArthurZheng
ArthurZheng / composing-software.md
Created January 30, 2019 10:33 — forked from rosario/composing-software.md
Eric Elliott's Composing Software Series
"""
A TestRunner for use with the Python unit testing framework. It
generates a tabular report to show the result at a glance.
The simplest way to use this is to invoke its main method. E.g.
import unittest
import TestRunner
... define your tests ...
@ArthurZheng
ArthurZheng / git-cleanup
Created January 30, 2020 22:01 — forked from yakovkhalinsky/git-cleanup
Prune local GIT branches that are merged into origin master
git branch --merged master | grep -v '^[ *]*master$' | xargs git branch -d
@ArthurZheng
ArthurZheng / Rails-applications-health-codes.md
Created February 2, 2021 05:37 — forked from kathyonu/Rails-applications-health-codes.md
Rails Applications Upgrade Steps for Ruby, Rails and Gems

Commands to keep your app healthy, Ruby and Rails gems wise.

Open new Terminal, note the gemsets showing:

rvm gemset list

You will see you are using the (default) gemset.
Keep your system up to date with rvm and brew:

rvm get head

Setup

Replace IRB with Pry (in your Gemfile) and Byebug with pry-byebug.

gem 'pry-rails', group: [:development, :test]
gem 'pry-byebug', group: [:development, :test]

Using PRY

@ArthurZheng
ArthurZheng / configmap.yaml
Created June 25, 2021 23:37 — forked from jferris/configmap.yaml
Rails Kubernetes Manifests
apiVersion: v1
kind: ConfigMap
metadata:
name: example
namespace: default
data:
APPLICATION_HOST: example.com
LANG: en_US.UTF-8
PIDFILE: /tmp/server.pid
PORT: "3000"
@ArthurZheng
ArthurZheng / memoized-helper-methods.md
Created July 25, 2021 10:30 — forked from bloudermilk/memoized-helper-methods.md
Explaining the rationale behind using memoized helper methods for controller resources

Last year I started playing around with using memoized private helper methods in my controllers instead of the traditional instance variable assigns we see in RoR controllers. Here's an example:

class PostsController < ApplicationController
  helper_method :new_post, :post, :posts
  
  def new; end
  def show; end
  def edit; end
 def index; end