Skip to content

Instantly share code, notes, and snippets.

View andy9775's full-sized avatar
🏠
Working from home

Andy Chrzaszcz andy9775

🏠
Working from home
  • Toronto, Ontario
View GitHub Profile
@andy9775
andy9775 / add_cloudflare_ips.sh
Created January 5, 2021 05:54 — forked from dduvnjak/add_cloudflare_ips.sh
Add CloudFlare IP addresses to an EC2 Security Group using awscli
# first we download the list of IP ranges from CloudFlare
wget https://www.cloudflare.com/ips-v4
# iterate over the lines in the downloaded file
# make sure to set `--group-id` and `--port`; more details at http://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html
while read p; do aws ec2 authorize-security-group-ingress --group-id sg-e0000000 --protocol tcp --port 80 --cidr $p; done< ips-v4
@andy9775
andy9775 / IAMCredentials.json
Created December 28, 2020 05:12 — forked from ServerlessBot/IAMCredentials.json
Minimum credential set for Serverless Framework
{
"Statement": [
{
"Action": [
"apigateway:*",
"cloudformation:CancelUpdateStack",
"cloudformation:ContinueUpdateRollback",
"cloudformation:CreateChangeSet",
"cloudformation:CreateStack",
"cloudformation:CreateUploadBucket",
@andy9775
andy9775 / lfu.go
Created March 7, 2019 22:14 — forked from fteem/lfu.go
Code example for the article "When to use Least Frequenty Used cache and how to implement it in Golang" https://ieftimov.com/golang-least-frequently-used-cache
package main
import (
"container/list"
"fmt"
)
type CacheItem struct {
key string // Key of item
value interface{} // Value of item
# Be aware to first setup a valid Python 3 environment with the proper requirements installed.
# Also activate your Python installation/venv before executing those commands.
VER=0.19.4
PROGS?=app1 app2 app3 app4
PROGS_PY:=$(addsuffix .py,$(PROGS))
PROGS_EXE:=$(addsuffix .exe,$(PROGS))
let UserContext = React.createContext();
class App extends React.Component {
state = {
user: null,
setUser: user => {
this.setState({ user });
}
};
@andy9775
andy9775 / gist:6fcb7dcb68f28c281433e740cc0bcd89
Created September 11, 2018 03:16 — forked from prsws/gist:8162386
A Multi-Tenant Strategy using Yii and MySQL

Introduction

This article describes an implementation of multi-tenancy using Yii and MySQL. “Multi-tenancy” is but one (yet crucial) aspect of SaaS applications; refer to the IBM document Convert your web application to a multi-tenant SaaS solution for more information on what else makes a webapp a SaaS application.

Moreover, there are three main architectures for multi-tenant databases: separate database, separate schemas and a single database. Refer to the Microsoft document Multi-Tenant Data Architecture for more information.

As MySQL doesn’t have schemas (at least the same way MS SQL Server and Oracle do) the only choices are a separate database for each tenant and single database with “commingled” tenant data. SaaS applications with a relatively small number of tenants can be easily managed with a database for each one, but for large numbers of tenants its

@andy9775
andy9775 / activerecord_callback.md
Created July 6, 2018 01:57 — forked from ostinelli/activerecord_callback.md
ActiveRecord callback when connection is made

The ConnectionAdapter defines two callbacks :checkout (connect) and :checkin (disconnect).

ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.set_callback :checkout, :after do
  raw_connection
end

Source.

@andy9775
andy9775 / read-access.sql
Created December 15, 2017 23:51 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@andy9775
andy9775 / story.md
Created September 9, 2017 02:16 — forked from posener/go-shebang-story.md
Story: Writing Scripts with Go

Story: Writing Scripts with Go

This is a story about how I tried to use Go for scripting. In this story, I’ll discuss the need for a Go script, how we would expect it to behave and the possible implementations; During the discussion I’ll deep dive to scripts, shells, and shebangs. Finally, we’ll discuss solutions that will make Go scripts work.

Why Go is good for scripting?

While python and bash are popular scripting languages, C, C++ and Java are not used for scripts at all, and some languages are somewhere in between.

@andy9775
andy9775 / encrypted-git-repo.md
Created August 21, 2017 02:13
Transparent Git Encryption

Transparent Git Encryption

This document has been modified from its [original format][m1], which was written by Ning Shang ([email protected]). It has been updated and reformatted into a [Markdown][m2] document by [Woody Gilk][m3] and [republished][m4].

Description

When working with a remote git repository which is hosted on a third-party storage server, data confidentiality sometimes becomes