Skip to content

Instantly share code, notes, and snippets.

@Dezinger
Dezinger / postgres-server.bash
Last active May 17, 2020 18:35
Manage postgres server
# Fast server stop
sudo -u postgres /usr/pgsql-9.1/bin/pg_ctl -D /var/lib/pgsql/9.1/data stop -m fast
# To create a database instance, after install do
sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb'
#или
sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb --locale=ru_RU.UTF-8 --lc-collate=ru_RU.UTF-8 --lc-ctype=ru_RU.UTF-8 --encoding=UTF8 -D /opt/local/var/db/postgresql93/localdb'
@Dezinger
Dezinger / search-poccess.shell
Created November 6, 2013 18:58
search poccess
ps -ax | grep post
@Dezinger
Dezinger / lib-ver.shell
Created November 7, 2013 20:40
Узнать версию библиотеки в mac os x
otool -L /usr/lib/libssl.0.9.7.dylib
@Dezinger
Dezinger / pkg-expander.shell
Created November 7, 2013 20:42
Expand pkg
pkgutil --expand MAMP_2.1.1.pkg /tmp/test/mamp211/
@Dezinger
Dezinger / create-table-adn-fill-1m-recs.sql
Created November 23, 2013 13:47
Создаем и заполняем таблицу миллионом записей
CREATE TABLE foo (c1 integer, c2 text);
INSERT INTO foo
  SELECT i, md5(random()::text)
  FROM generate_series(1, 1000000) AS i;
@Dezinger
Dezinger / random-func-postgresql.sql
Created December 10, 2013 16:59
Random Range
by Scott Bailey 'Artacus' 
http://wiki.postgresql.org/wiki/Random_Range
CREATE OR REPLACE FUNCTION random(numeric, numeric)
RETURNS numeric AS
$$
SELECT ($1 + ($2 - $1) * random())::numeric;
$$ LANGUAGE 'sql' VOLATILE;
SELECT random(1,10)::int, random(1,10);
mkdir ~/git/website.git && ~/git/cd website.git
git init --bare
mkdir ~/webapps/website
git config core.bare false
git config core.worktree /home/rafi/webapps/website ; NO TRAILING SLASH!!! Will screw up things real bad.
git config receive.denycurrentbranch ignore
; create a hook
cat > hooks/post-receive
#!/bin/sh
@Dezinger
Dezinger / mcached.shell
Last active August 29, 2015 13:57
Memcached Console
telnet localhost 11211
Command Description Example
get Reads a value get mykey
set Set a key unconditionally set mykey 0 60 5
add Add a new key add newkey 0 60 5
replace Overwrite existing key replace key 0 60 5
append Append data to existing key append key 0 60 15
prepend Prepend data to existing key prepend key 0 60 15
incr Increments numerical key value by given number incr mykey 2
-- Запросы по сбору статистики PostgreSql 9.3.x
-- Процессы которые висят более 20 секунд
select * from pg_stat_activity where state != 'idle' and current_timestamp - query_start > '20 sec';
-- К-во update-тов за время с последнего сброса статистики
SELECT relname, n_tup_ins + n_tup_upd + n_tup_del from pg_stat_user_tables order by 2 desc limit 5;
-- Сброс статистики
SELECT pg_stat_reset();
@Dezinger
Dezinger / composer_gzip_test.php
Last active December 12, 2016 08:31 — forked from radutopala/composer_gzip_test.php
Composer GZIP decoding test
<?php
$retries = 0;
function fetch() {
global $retries;
echo "Retry " . $retries . " | ";
$opts = array(