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 / attribute-resolver-idem-ad.xml
Created October 18, 2022 05:14 — forked from daserzw/attribute-resolver-idem-ad.xml
IDEM Shibboleth Active Directory Attribute Resolver
<?xml version="1.0" encoding="UTF-8"?>
<AttributeResolver
xmlns="urn:mace:shibboleth:2.0:resolver"
xmlns:sec="urn:mace:shibboleth:2.0:security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd
urn:mace:shibboleth:2.0:security http://shibboleth.net/schema/idp/shibboleth-security.xsd">
<!-- ========================================== -->
@ArthurZheng
ArthurZheng / opt1_template.j2
Created February 2, 2022 23:24 — forked from halberom/opt1_template.j2
ansible - example of template if else
{# style 1 - long form #}
{% if filepath == '/var/opt/tomcat_1' %}
{% set tomcat_value = tomcat_1_value %}
{% else %}
{% set tomcat_value = tomcat_2_value %}
{% endif %}
{# style 2 - short form #}
{% set tomcat_value = tomcat_1_value if (filepath == '/var/opt/tomcat_1') else tomcat_2_value %}
@ArthurZheng
ArthurZheng / exception_spec.rb
Created November 14, 2021 09:34 — forked from tcnksm/exception_spec.rb
How to stub raising exceptions in rspec
class Foo
class << self
def exec
something
rescue => ex
ex.message
end
def something
"something"
@ArthurZheng
ArthurZheng / README.md
Created November 4, 2021 01:31 — forked from Eyjafjallajokull/README.md
AWS EBS - Find unused snapshots

This script can help you find and remove unused AWS snapshots and volumes.

There is hardcoded list of regions that it searches, adjust the value to suit your needs.

Use snapshot.py snapshot-report to generate report.csv containing information about all snapshots.

snapshot.py snapshot-cleanup lets you interactively delete snapshot if it finds it is referencing unexisting resources.

./snapshots.py --help
@ArthurZheng
ArthurZheng / ActiveRecord Cheat Sheet v1
Created October 14, 2021 20:34 — forked from jessieay/ActiveRecord Cheat Sheet v1
Active Record cheat sheet with examples of queries I've needed most so far
ActiveRecord cheat sheet / EXAMPLES
INSTALL
=======
$ gem install activerecord
in GEMFILE: gem ‘activerecord’
REQUIRE
=======
require ‘active_record’
@ArthurZheng
ArthurZheng / pr.md
Created September 10, 2021 03:55 — forked from karlhorky/pr.md
Fetch all GitHub pull requests to local tracking branches

NOTE

You may not need local branches for all pull requests in a repo.

To fetch only the ref of a single pull request that you need, use this:

git fetch origin pull/7324/head:pr-7324
git checkout pr-7324
# ...
@ArthurZheng
ArthurZheng / cleanup.py
Created September 6, 2021 04:22 — forked from luhn/cleanup.py
An AWS Lambda function to delete old AMIs.
"""
Code adapted from and inspired by http://blog.ranman.org/cleaning-up-aws-with-boto3/.
"""
import os
import re
from datetime import datetime, timedelta
import boto3
@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)
@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'

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(
 '-'