Skip to content

Instantly share code, notes, and snippets.

View cihangir's full-sized avatar
💭
Closed sourcing

Cihangir cihangir

💭
Closed sourcing
View GitHub Profile
@cihangir
cihangir / inselect.sql
Created June 27, 2015 09:44
Inserts if not exists or select in one-trip to database
--sql, args := DB.
-- Insect("tab").
-- Columns("b", "c").
-- Values(1, 2).
-- Where("d = $1", 3).
-- Returning("id", "f", "g").
-- ToSQL()
WITH
sel AS (SELECT id, f, g FROM tab WHERE (d = $1)),
@cihangir
cihangir / install_nginx_with_tcp_proxy_module.sh
Last active August 29, 2015 14:24
Compile Ngnix from source with TCP Proxy Module enabled
nginxVersion="1.9.2"
wget http://nginx.org/download/nginx-$nginxVersion.tar.gz
tar -xzf nginx-$nginxVersion.tar.gz
ln -sf nginx-$nginxVersion nginx
cd nginx
git clone [email protected]:yaoweibin/nginx_tcp_proxy_module.git
patch -p1 < ./nginx_tcp_proxy_module/tcp.patch
@cihangir
cihangir / nginx.conf
Created July 7, 2015 01:07
Generic 301 re-direction
server {
# just a random port
listen 81;
# why we have 2 different if checks? because www redirector block catches
# all the requests, we should be more precise with the host
# redirect http://kodingen.com to https://koding.com
if ($host = "kodingen.com") {
return 301 https://koding.com;
@cihangir
cihangir / gist:c5a0ff9bca6ab74638e3
Created November 19, 2015 02:18 — forked from jberkus/gist:6b1bcaf7724dfc2a54f3
Finding Unused Indexes
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@cihangir
cihangir / fizzbuzz.sql
Created November 19, 2015 02:57
SQL FizzBuzz
WITH RECURSIVE numbers(n) AS (
SELECT 1
UNION ALL
SELECT n + 1
FROM numbers
WHERE n < 102
) SELECT CASE
WHEN n % 3 = 0 AND n % 5 = 0 THEN
'FizzBuzz'
WHEN n % 3 = 0 THEN
@cihangir
cihangir / nginx.conf
Created February 18, 2016 19:02
redirect www to non-www
# redirect www to non-www
server {
server_name "~^www.(.*)$" ;
return 301 $scheme://$1$request_uri ;
}

Keybase proof

I hereby claim:

  • I am cihangir on github.
  • I am cihangir (https://keybase.io/cihangir) on keybase.
  • I have a public key whose fingerprint is 78A4 94A3 25BA 1DD6 35C9 1991 C6B2 BA6E 6276 29F0

To claim this, I am signing this object:

Koding Individual Contributor License Agreement ("Agreement")
In order to clarify the intellectual property license
granted with Contributions from any person or entity, Koding
must have a Contributor License Agreement ("CLA") on file that has
been signed by each Contributor, indicating agreement to the license
terms below. This license is for your protection as a Contributor as
well as the protection of Koding and its users; it does not
change your rights to use your own Contributions for any other purpose.
0x08c92d58d2e9e2a8491468f1e0e702dd12bb6981
@cihangir
cihangir / update.sh
Created November 24, 2017 22:54
update vendor/golang.org/x folder
#!/bin/bash
set -euo pipefail
PATHS="./go/src/vendor/golang.org/x/"
REPOS=$(ls $PATHS)
rm -rf ./go/src/golang.org
rm -rf ./go/src/vendor/golang.org