Skip to content

Instantly share code, notes, and snippets.

@a-leung
a-leung / auth.log
Created February 16, 2017 13:35
server log for article - 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
Jan 11 01:59:05 ip-172-31-1-163 sudo: pam_un
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 November 15, 2017 18:11
quick way to parse boolean in JSON
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 March 2, 2017 13:39
Basic fail2ban configuration file
# 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
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
# Default screens
screen -t shell1 0
screen -t shell2 1
screen -t server 2 ssh me@myserver
@a-leung
a-leung / .tmux.conf
Last active March 17, 2016 19:23
tmux.conf
###################
# Prefix key setup
###################
set -g prefix C-a # remap prefix to Control + a --> i'm old that way.
# bind 'C-a C-a' to type 'C-a'
bind a send-prefix # send 'C-a' into terminal app by typing: 'C-a a'
bind C-a last-window # bounce between windows just by typing 'C-a C-a'
unbind C-b # get rid of C-b as prefix
########################
@a-leung
a-leung / refund_stripe.rb
Last active March 8, 2016 21:04
Stripe Stripe-Mock refunding
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 February 8, 2016 16:50
rspec mocking issue
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 February 4, 2016 22:05
postgres pg_restore debug
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 January 28, 2016 20:36
rspec and ActiveRecord::Base.transaction testing
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