Skip to content

Instantly share code, notes, and snippets.

View encoreshao's full-sized avatar

Encore Shao encoreshao

View GitHub Profile
@encoreshao
encoreshao / v2ray_install.sh
Last active November 14, 2022 13:11
Install v2ray VPN Vultr
#!/bin/bash
red='\e[91m'
green='\e[92m'
yellow='\e[93m'
magenta='\e[95m'
cyan='\e[96m'
none='\e[0m'
_red() { echo -e ${red}$*${none}; }
_green() { echo -e ${green}$*${none}; }
@encoreshao
encoreshao / PostgreSQL-12-Streaming-Replication-in-Ubuntu-18.04.md
Last active July 4, 2024 09:48
PostgreSQL 12 Streaming Replication in Ubuntu 18.04

How To Configure PostgreSQL 12 Streaming Replication in Ubuntu 18.04

  • Build two boxes and install ubuntu18.04

    • box1: master -> Ubuntu 18.04 with PG 12
      • static ip: 192.168.33.33
      • hostname: master
    • box2: slave -> Ubuntu 18.04 with PG 12
      • static ip: 192.168.33.44
      • hostname: slave
@encoreshao
encoreshao / PostgreSQL-10-Master-Slave-Replication.md
Last active June 7, 2022 15:19
PostgreSQL 10 Master-Slave Replication on Virtualbox

PostgreSQL 10 Master-Slave Replication on Virtualbox

Preparations

@encoreshao
encoreshao / postgres_commands.sql
Last active March 28, 2018 01:44
Useful PostgreSQL Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@chmarr
chmarr / blocked.sql
Created November 5, 2015 18:30
PostgreSQL query to display blocked and blocking queries. Updated from PG Wiki.
SELECT blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
now() - blocked_activity.query_start
AS blocked_duration,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
now() - blocking_activity.query_start
AS blocking_duration,
blocked_activity.query AS blocked_statement,
blocking_activity.query AS blocking_statement
function copyToClipboard( text ){
var copyDiv = document.createElement('div');
copyDiv.contentEditable = true;
document.body.appendChild(copyDiv);
copyDiv.innerHTML = text;
copyDiv.unselectable = "off";
copyDiv.focus();
document.execCommand('SelectAll');
document.execCommand("Copy", false, null);
document.body.removeChild(copyDiv);
@sj26
sj26 / README.md
Created March 12, 2012 10:27
RSpec ExampleGroup extensions for CarrierWave

RSpec ExampleGroup extensions for CarrierWave

Infers as much as possible about uploader—the model class, what it's mounted as, etc—, sets up an uploader for specs, handles dis/enabling processing for only uploader specs, and makes it easy to describe behaviour of versions.

Drop it in spec/support/carrierwave.rb or something similar.

TODO: Microgem coming, can't get it all loading in the right order.

@lpar
lpar / timeout.rb
Created June 17, 2011 20:41
Run a shell command in a separate thread, terminate it after a time limit, return its output
# Runs a specified shell command in a separate thread.
# If it exceeds the given timeout in seconds, kills it.
# Returns any output produced by the command (stdout or stderr) as a String.
# Uses Kernel.select to wait up to the tick length (in seconds) between
# checks on the command's status
#
# If you've got a cleaner way of doing this, I'd be interested to see it.
# If you think you can do it with Ruby's Timeout module, think again.
def run_with_timeout(command, timeout, tick)
output = ''