Skip to content

Instantly share code, notes, and snippets.

Andrew Leung a-leung

Block or report user

Report or block a-leung

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Dockerfile
FROM ruby:2.5.1-slim
RUN apt-get update && apt-get install -qq -y --no-install-recommends \
build-essential \
libsqlite3-dev \
nodejs \
sqlite3 \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir /app
@a-leung
a-leung / boolean_parsing_spec.rb
Created Nov 15, 2017
quick way to parse boolean in JSON
View boolean_parsing_spec.rb
require 'rspec'
require 'json'
require 'pry'
def convert_json(json)
JSON.parse(json)
end
def evaluate_json(input)
key = input.keys.first
@a-leung
a-leung / jail.local
Last active Mar 2, 2017
Basic fail2ban configuration file
View jail.local
# Fail2Ban configuration file.
#
# This file was composed for Debian systems from the original one
# provided now under /usr/share/doc/fail2ban/examples/jail.conf
# for additional examples.
#
# Comments: use '#' for comment lines and ';' for inline comments
#
# To avoid merges during upgrades DO NOT MODIFY THIS FILE
# and rather provide your changes in /etc/fail2ban/jail.local
@a-leung
a-leung / auth.log
Created Feb 16, 2017
server log for article - auth.log
View auth.log
This file has been truncated, but you can view the full file.
Jan 11 01:54:31 ip-172-31-1-163 sshd[1106]: Server listening on 0.0.0.0 port 22.
Jan 11 01:54:31 ip-172-31-1-163 sshd[1106]: Server listening on :: port 22.
Jan 11 01:55:59 ip-172-31-1-163 sshd[1301]: Connection closed by 127.213.25.139 [preauth]
Jan 11 01:56:37 ip-172-31-1-163 sshd[1303]: Accepted publickey for ubuntu from 127.213.25.139 port 65087 ssh2: RSA 0a:78:92:3c:c8:27:13:d3:f7:ee:d5:ac:75:45:31:5c
Jan 11 01:56:37 ip-172-31-1-163 sshd[1303]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
Jan 11 01:58:12 ip-172-31-1-163 sudo: ubuntu : TTY=pts/0 ; PWD=/var/log ; USER=root ; COMMAND=/usr/bin/apt-get update
Jan 11 01:58:12 ip-172-31-1-163 sudo: pam_unix(sudo:session): session opened for user root by ubuntu(uid=0)
Jan 11 01:58:18 ip-172-31-1-163 sudo: pam_unix(sudo:session): session closed for user root
Jan 11 01:59:05 ip-172-31-1-163 sudo: ubuntu : TTY=pts/0 ; PWD=/var/log ; USER=root ; COMMAND=/usr/bin/apt-get install unattended-upgrades
@a-leung
a-leung / refund_stripe.rb
Last active Mar 8, 2016
Stripe Stripe-Mock refunding
View refund_stripe.rb
gem 'stripe', '1.31.0'
require 'stripe'
Stripe.api_key = <insert API key here>
token = Stripe::Token.create(
:card => {
:number => "4242424242424242",
:exp_month => 3,
:exp_year => 2017,
:cvc => "314"
@a-leung
a-leung / refund.rb
Created Feb 8, 2016
rspec mocking issue
View refund.rb
def refund
self.items
ActiveRecord::Base.transaction do
self.items.each { |i| i.update!(refund: true) }
end
end
def refund_v2
refundable_items = self.items.where(refund: false)
@a-leung
a-leung / output from pg_restore
Last active Feb 4, 2016
postgres pg_restore debug
View output from pg_restore
pg_restore: executing SEQUENCE SET key_configurations_id_seq
pg_restore: processing data for table "kiosk_scans"
out of memory
@a-leung
a-leung / model.rb
Last active Jan 28, 2016
rspec and ActiveRecord::Base.transaction testing
View model.rb
def set_new_name_on_items?
success = ActiveRecord::Base.transaction do
model.items.each do |i|
i.name = 'new name'
i.save or raise ActiveRecord::Rollback
end
!!success
end
View model_A.rb
has_many model_B
before_save set_model_b_attributes
def set_model_b_attributes
self.bs.each do |b|
b.value = self.value
end
end
View controller_spec.rb
param[:attribute] = true
# model passes validation as model.attribute = true
You can’t perform that action at this time.