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

Keybase proof

I hereby claim:

  • I am arthurzheng on github.
  • I am junzheng (https://keybase.io/junzheng) on keybase.
  • I have a public key ASBjSqeSkrMbZ6s8W8f6OkDU_G6QLOZbl8tybTUg8REEvwo

To claim this, I am signing this object:

@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
@ArthurZheng
ArthurZheng / iterm2-solarized.md
Created July 28, 2021 10:09 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@ArthurZheng
ArthurZheng / MySQL_5-7_macOS.md
Last active August 16, 2021 11:13 — forked from robhrt7/MySQL_5-7_macOS.md
Install MySQL 5.7 on macOS using Homebrew

This is a fork of original gist https://gist.github.com/nrollr/3f57fc15ded7dddddcc4e82fe137b58e, with slight changes on pointing to 5.7 version branch, instead of 8 (latest default of MySQL in Hombrew).

Install MySQL 5.7 on macOS

This procedure explains how to install MySQL using Homebrew on macOS (Sierra 10.12 and up)

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.

How to break long lines up in Ruby

This page lists the options for breaking single-line expressions into multiple lines in Ruby.

Developers and teams need to come to their own decisions about which guideline(s) they prefer (preferences below are just my personal choices and I encourage you to disregard them).

# With trailing parens
x = [1, 2, 3].join(
 '-'
@ArthurZheng
ArthurZheng / gist:64cf0565586258e63b833b344495b8cf
Created August 27, 2021 21:35 — forked from JanDintel/gist:6088237
Using RSpec with Rails 4 PATCH method

Using Rspec with Rails 4 patch method

In Rails 4 PATCH is the new HTTP methode for an update action. You can find the details here: http://weblog.rubyonrails.org/2012/2/25/edge-rails-patch-is-the-new-primary-http-method-for-updates/

Using PATCH in your specs

As you can imagine you need to use the PATCH method to test the update action in your controller. Because of how the users controller in this example works you need to specify the id and user. This particular spec tests whether the user gets redirected if it's not logged in.

(./spec/controllers/users_controller_spec.rb)

require 'spec_helper'
@ArthurZheng
ArthurZheng / aws_delete_ami_boto3.py
Created September 6, 2021 03:30 — forked from nirbhabbarat/aws_delete_ami_boto3.py
Delete/Deregister 30 days old AMI in AWS using boto3 and python
#!/usr/bin/env python
##### USE ON YOUR OWN RISK - THIS IS GOING TO DEREGISTER AMI OLDER THAN 30 DAYS
import boto3
from dateutil.parser import parse
import datetime
age = 30
aws_profile_name = 'prod'
def days_old(date):
get_date_obj = parse(date)