Skip to content

Instantly share code, notes, and snippets.

@goncha
goncha / postgres_queries_and_commands.sql
Created April 10, 2020 00:04 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), 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(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@goncha
goncha / git-proxy.txt
Last active January 20, 2020 17:20
Git and socks5 proxy
gang@debian:~$ sudo apt-get install netcat-openbsd
gang@debian:~$ cat /usr/local/bin/git-proxy-wrapper
#!/bin/bash
nc -xlocalhost:1080 -X5 $*
gang@debian:~$ export GIT_PROXY_COMMAND=/usr/local/bin/git-proxy-wrapper
@goncha
goncha / gist:3741416
Last active September 7, 2017 09:40
iptables nat & port forwarding
## set net.ipv4.ip_forward = 1 in /etc/sysctl.conf
## NAT:
iptables -t nat -A POSTROUTING -s 1.1.9.251/32 -o ${INET_DEV} -j SNAT --to-source ${INET_IP}
## PORT FORWARDING:
iptables -t nat -A PREROUTING -i ${INET_DEV} -p tcp -m tcp --dport ${INET_PORT} -j DNAT --to-destination ${LOCAL_IP}:${LOCAL_PORT}
@goncha
goncha / jetty6.xml
Last active February 16, 2017 22:52
jetty.xml to add a single context
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="Server" class="org.mortbay.jetty.Server">
<Set name="ThreadPool">
<New class="org.mortbay.thread.QueuedThreadPool">
<Set name="minThreads">10</Set>
<Set name="maxThreads">200</Set>
<Set name="lowThreads">20</Set>
@goncha
goncha / pull_voanews.sh
Created August 27, 2013 05:19
Pull voanews mp3 files
#!/bin/sh
cd $HOME/public_html/voanews
SENEWS=$(date '+%y%m%d')_SE_NEWS.mp3
HLNEWS=$(date '+%y%m%d')_HL_NEWS.mp3
wget -O "${SENEWS}" \
"http://www.voanews.com/mp3/voa/english/spec/SPECIAL_ENGLISH_NEWS.mp3"
@goncha
goncha / paulgraham.el
Created August 24, 2013 11:33
Emacs Lisp script to merge articles from www.paulgraham.com into one single html.
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
(setq temp-articles '(
"progbot.html"
"lwba.html"
"avg.html"
"javacover.html"
"popular.html"
@goncha
goncha / haproxy-naming-based-dispatch.conf
Created August 12, 2013 05:31
Haproxy naming based dispatch
backend host1
mode http
server inst1 host1:port1
backend host2
mode http
server inst1 host2:port2
frontend http-in
bind :80
@goncha
goncha / fedora-setup.org
Last active December 20, 2015 14:39
Fedora 20 Setup

System

  1. Disable SELinux in `/etc/selinux/config` (need reboot)
  2. Install RPMFusion free&nofree repos rpm
  3. Install Wifi BCM4313 driver `yum install kmod-wl` after Step 2
  4. Install Adobe and Google repos rpm
  5. Install 163 mirror repos (http://mirrors.163.com/.help/fedora.html)
  6. Install build-essential alternative, `yum install make automake gcc gcc-c++ kernel-devel` or `yum-builddep sqlite` or `yum groupinstall “Development Tools”`
  7. Configure yum use proxy in /etc/yum.conf
@goncha
goncha / about-filter
Created July 12, 2013 04:43
cgit's about-filter, to render text file with line breaks
#!/usr/bin/env perl
print "<pre>\n";
while (<STDIN>) { print; }
print "</pre>\n";
@goncha
goncha / tomcat.zookeeper.StandardServerListener.java
Created September 14, 2012 06:45
Register Tomcat server instance in ZooKeeper directory
package tomcat.zookeeper;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;