Skip to content

Instantly share code, notes, and snippets.

Avatar
💨

Peter Bui paydro

💨
View GitHub Profile
@paydro
paydro / default-config-postgres-updated.sql
Last active Aug 7, 2020
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/)
View default-config-postgres-updated.sql
-- 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 Jan 9, 2020
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…
View default-config-postgres.sql
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 Dec 12, 2019
Connect to my local postgres database in python.
View pyscopg2.py
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 Jun 3, 2017
modernization-operations-at-plangrid-post-2-cloudformation
View example_bucket.yaml
Resources:
SampleBucket:
Type: "AWS::S3::Bucket"
View player_shard_v1.rb
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 Feb 2, 2015
Discourse plugin patches to use custom Avatar URL instead of Discourse's avatar system
View javascript_overrides.js
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');
View proxy.go
package main
import (
"bytes"
"encoding/hex"
"flag"
"fmt"
"io"
"log"
"net"
@paydro
paydro / apns.rb
Created Jun 13, 2012 — forked from scotttam/apns.rb
Sends an Apple Push Notification with Ruby
View apns.rb
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
Script to wait on something to happen
View image_ready.sh
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
@paydro
paydro / wrapper.sh
Created May 16, 2012
Monit wrapper script that start/stops a process that doesn't use a pid
View wrapper.sh
#!/usr/bin/env bash
case $1 in
start)
PID=$(start statsd | awk '{print $4}');
echo $PID > /var/run/statsd.pid;
;;
stop)
kill `cat /var/run/statsd.pid` ;;
*)
You can’t perform that action at this time.