Skip to content

Instantly share code, notes, and snippets.

View paydro's full-sized avatar
💨

Peter Bui paydro

💨
View GitHub Profile
@paydro
paydro / haproxy.cfg
Created September 20, 2021 17:18
stormlight haproxy config. Used in: https://tightlycoupled.io/stormlight/
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
tune.ssl.default-dh-param 2048
@paydro
paydro / default-config-postgres-updated.sql
Last active August 7, 2020 14:19
A postgres configuration for RDS and self-managed postgres databases. Based on my guide (https://tightlycoupled.io/goto-postgres-configuration-for-rds-and-self-managed-postgres/)
-- Copy/paste this file or execute with `psql -f thisfile.sql`
CREATE ROLE owner CREATEDB LOGIN ENCRYPTED PASSWORD 'secret' CONNECTION LIMIT 3;
ALTER ROLE owner SET statement_timeout = 20000;
ALTER ROLE owner SET lock_timeout = 3000;
ALTER ROLE owner SET idle_in_transaction_session_timeout = 3000; -- v9.6+
CREATE ROLE readwrite_users NOLOGIN;
CREATE ROLE readonly_users NOLOGIN;
@paydro
paydro / default-config-postgres.sql
Last active September 14, 2023 16:24
A base setup for new self-managed postgres databases. See related guide (https://tightlycoupled.io/my-goto-postgres-configuration-for-web-services/). Also, please make sure to change all the passwords from `secret` to something suitable. !! Update !! see this gist for a config that works for self-managed and RDS databases: https://gist.github.co…
CREATE ROLE owner LOGIN ENCRYPTED PASSWORD 'secret' CONNECTION LIMIT 3;
ALTER ROLE owner SET statement_timeout = 20000;
ALTER ROLE owner SET lock_timeout = 3000;
ALTER ROLE owner SET idle_in_transaction_session_timeout = 3000; -- v9.6+
CREATE ROLE readwrite_users NOLOGIN;
CREATE ROLE readonly_users NOLOGIN;
CREATE DATABASE exampledb WITH OWNER owner ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
@paydro
paydro / pyscopg2.py
Last active December 12, 2019 18:23
Connect to my local postgres database in python.
import psycopg2
conn = psycopg2.connect("")
cur = conn.cursor()
# now you can run queries
# cur.execute("SELECT 1")
# See http://initd.org/psycopg/docs/usage.html
@paydro
paydro / example_bucket.yaml
Last active June 3, 2017 00:37
modernization-operations-at-plangrid-post-2-cloudformation
Resources:
SampleBucket:
Type: "AWS::S3::Bucket"
class PlayerShard < ActiveRecord::Base
def self.with_date(date)
current_table_name = self.table_name
self.table_name = self.shard_table_name(date)
create_shard(date)
yield
ensure
self.table_name = current_table_name
@paydro
paydro / javascript_overrides.js
Created February 2, 2015 20:47
Discourse plugin patches to use custom Avatar URL instead of Discourse's avatar system
var safe = Handlebars.SafeString;
Em.Handlebars.helper('bound-avatar', function(user, size, uploadId) {
if (Em.isEmpty(user)) {
return new safe("<div class='avatar-placeholder'></div>");
}
var username = Em.get(user, 'username');
if(arguments.length < 4){
uploadId = Em.get(user, 'uploaded_avatar_id');
@paydro
paydro / proxy.go
Created August 20, 2014 17:37 — forked from vmihailenco/proxy.go
package main
import (
"bytes"
"encoding/hex"
"flag"
"fmt"
"io"
"log"
"net"
@paydro
paydro / apns.rb
Created June 13, 2012 23:38 — forked from scotttam/apns.rb
Sends an Apple Push Notification with Ruby
require "rubygems"
require "yajl"
require "openssl"
require "socket"
device_token = '39cac56f 986a0e66 3c4fd4f4 68df5598 024d2ca3 8b9f307c 741c180e 9fc30c62'
device_token = device_token.gsub(" ", "")
the_byte_token = [device_token].pack("H*")
file = File.open("ruby_the_byte_token", "wb")
@paydro
paydro / image_ready.sh
Created May 29, 2012 20:05
Script to wait on something to happen
while :
do
building=`bulldozer images:list | grep postprocessor-2012-05-29 | grep available | wc -l`
if [ $building -eq 1 ]
then
say "post processor image finished building"
break
fi
sleep 5
done