Add
{code} {code}
== ==
* *
_ _
[]
*
#
MySQL mean calculation
SELECT avg(t1.val) as median_val FROM (
SELECT @rownum:=@rownum+1 as `row_number`, d.val
FROM data d, (SELECT @rownum:=0) r
WHERE 1
-- put some where clause here
ORDER BY d.val
) as t1,
(
SELECT count(*) as total_rows
FROM data d
WHERE 1
-- put same where clause here
) as t2
WHERE 1
AND t1.row_number in ( floor((total_rows+1)/2), floor((total_rows+2)/2) );
Little helpers for PHP
function issetget($var) {
$v = &$var;
for ($i = 1; $i < func_num_args(); $i++) {
$key = func_get_arg($i);
if (!isset($v[$key])) {
return null;
}
$v = &$v[$key];
}
return $v;
}
function issetdefault($set, $default) {
return $set ?: $default;
}
Install pinba engine on Mac OS X 10.9
Downloads:
mysql-server sources at http://dev.mysql.com/downloads/mysql/
Generic Linux (Architecture Independent), Compressed TAR Archive 5.6.19 31.4M (mysql-5.6.19.tar.gz)
cmake binary distribution http://www.cmake.org/cmake/resources/software.html
Mac OSX 64/32-bit Universal (for Intel, Snow Leopard/10.6 or later) cmake-3.0.0-Darwin64-universal.dmg
libevent http://libevent.org
libevent-2.0.21-stable.tar.gz Released 2012-11-18
judy http://sourceforge.net/projects/judy/
Judy-1.0.5.tar.gz
homebrew https://github.com/Homebrew/homebrew/wiki/Installation
curl -L https://github.com/Homebrew/homebrew/tarball/master|tar x
glibtoolize
~/homebrew/bin/brew install glibtoolize
pinba engine http://pinba.org
git@github.com:tony2001/pinba_engine.git
commit 6c75b83d612df41fae979219b1ad605e1c71605e
Merge: f9f0b1c 40330fc
Author: Antony Dovgal <tony2001@php.net>
Date: Mon Jun 9 19:15:05 2014 +0400
Edits:
diff --git a/build.mk b/build.mk
index f2dc502..2b7d842 100644
--- a/build.mk
+++ b/build.mk
@@ -5,10 +5,11 @@ AUTOCONF ?= 'autoconf'
ACLOCAL ?= 'aclocal'
AUTOHEADER ?= 'autoheader'
AUTOMAKE ?= 'automake'
-LIBTOOLIZE ?= $(shell uname -s | grep Darwin >/dev/null && echo 'glibtoolize' || echo 'libtoolize')
+LIBTOOLIZE ?= ~/homebrew/bin/glibtoolize
config_h_in = config.h.in
targets = $(config_h_in) configure makefiles
+glibtoolize_include = -I/Users/emakhrov/homebrew/share/aclocal
all: $(targets)
@@ -16,7 +17,7 @@ ltmain:
$(LIBTOOLIZE) --force --copy
aclocal.m4: configure.ac
- $(ACLOCAL)
+ $(ACLOCAL) $(glibtoolize_include)
$(config_h_in): configure
@echo rebuilding $@
./build.mk
./configure
./configure --with-mysql=/Users/emakhrov/Downloads/mysql-5.6.19 --libdir=/usr/local/mysql/lib/plugin/
make
sudo make install
mysql -uroot
INSTALL PLUGIN pinba SONAME 'libpinba_engine.so';
CREATE DATABASE pinba;
mysql -uroot -D pinba < default_tables.sql
php -dextension=pinba.so -dpinba.server=127.0.0.1:30002 -dpinba.enabled=1 -r '$t = pinba_timer_start(["hello" => "world"]); sleep(1);pinba_flush();'
mysql> select * from timer t join timertag tt on t.id = tt.timer_id join tag ta on tt.tag_id = ta.id;
+----+------------+-----------+---------+----------+--------+-------+----+-------+
| id | request_id | hit_count | value | timer_id | tag_id | value | id | name |
+----+------------+-----------+---------+----------+--------+-------+----+-------+
| 1 | 2 | 1 | 1.00052 | 1 | 0 | world | 0 | hello |
+----+------------+-----------+---------+----------+--------+-------+----+-------+
1 row in set (0,00 sec)
Set hostname
sudo scutil --set HostName name-you-want
Mavericks
# Mount the installer image
hdiutil attach /Applications/Install\ OS\ X\ Mavericks.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
- Convert the boot image to a sparse bundle
- Increase the sparse bundle capacity to accommodate the packages
- Mount the sparse bundle for package addition
- Remove Package link and replace with actual files
- Unmount the installer image
- Unmount the sparse bundle
- Resize the partition in the sparse bundle to remove any free space
- Convert the sparse bundle to ISO/CD master
- Remove the sparse bundle
- Rename the ISO and move it to the desktop
installing mitmproxy
ezh@magify ~/python_nest$ mkdir -p /Users/ezh/python_nest/lib/python2.7/site-packages
ezh@magify ~/python_nest$ PYTHONPATH=/Users/ezh/python_nest/lib/python2.7/site-packages easy_install --prefix=/Users/ezh/python_nest pip
#not sure if it needed
ezh@magify ~/python_nest$ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future PYTHONPATH=/Users/ezh/python_nest/lib/python2.7/site-packages easy_install --prefix=/Users/ezh/python_nest PIL
#not sure if it needed
ezh@magify ~/python_nest$ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future PYTHONPATH=/Users/ezh/python_nest/lib/python2.7/site-packages bin/pip install --user Pillow
ezh@magify ~/python_nest$ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future PYTHONPATH=/Users/ezh/python_nest/lib/python2.7/site-packages bin/pip install --user mitmproxy
$ mitmproxy
$ cd ~/.mitmproxy && php -S 0.0.0.0:8080
install ca.pem onto device
$ sudo sysctl -w net.inet.ip.forwarding=1
$ cat > pf.conf
rdr on en1 inet proto tcp to any port 80 -> 127.0.0.1 port 8080
rdr on en1 inet proto tcp to any port 443 -> 127.0.0.1 port 8080
$ sudo pfctl -f pf.conf
$ sudo pfctl -e
$ sudo visudo
ALL ALL=NOPASSWD: /sbin/pfctl -s state
$ mitmproxy -T --host
$ vi /usr/local/etc/dhcpd.conf
host victim { hardware ethernet 18:35:d0:88:14:fc; fixed-address 192.168.0.100; option routers 192.168.0.20; }
Then commands from here
http://mitmproxy.org/doc/transparent/osx.htmlPHPUnit ctype dependency
*/
protected function toAbsolutePath($path, $useIncludePath = FALSE)
{
if (!function_exists('ctype_alpha')) {
function ctype_alpha($str) {
for ($i = strlen($str); $i--;)
if (($str[$i] < "A" || $str[$i] > "Z") && ($str[$i] < "a" || $str[$i] > "z"))
return false;
return true;
}
}
// Check whether the path is already absolute.
if ($path[0] === '/' || $path[0] === '\\' ||
(strlen($path) > 3 && ctype_alpha($path[0]) &&
Proper way to close TCP socket
Now playing: Jungle Buddha – Hired Gun
http://www.tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF.htm
http://www.tcpipguide.com/free/t_TCPConnectionTermination.htm
http://www.gnu.org/software/libc/manual/html_node/Closing-a-Socket.html
http://vadmyst.blogspot.ru/2008/04/proper-way-to-close-tcp-socket.html
The key is to shutdown socket for writing - not for reading or both.
http://www.php.net/manual/en/function.socket-shutdown.php
Here is nginx/1.2.5
PHP Socket HTTP webserver
http://www.tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF.htm
http://www.tcpipguide.com/free/t_TCPConnectionTermination.htm
http://www.gnu.org/software/libc/manual/html_node/Closing-a-Socket.html
http://vadmyst.blogspot.ru/2008/04/proper-way-to-close-tcp-socket.html
The key is to shutdown socket for writing - not for reading or both.
http://www.php.net/manual/en/function.socket-shutdown.php
Here is nginx/1.2.5
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [S], seq 3352127545, win
IP 192.168.88.3.1180 > 192.168.88.4.63157: Flags [S.], seq 3734171680, ack 3352127546, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [.], ack 1, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [P.], seq 1:86, ack 1, win
IP 192.168.88.3.1180 > 192.168.88.4.63157: Flags [.], ack 86, win
IP 192.168.88.3.1180 > 192.168.88.4.63157: Flags [P.], seq 1:273, ack 86, win
IP 192.168.88.3.1180 > 192.168.88.4.63157: Flags [F.], seq 273, ack 86, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [P.], seq 86:1616, ack 1, win
IP 192.168.88.3.1180 > 192.168.88.4.63157: Flags [.], ack 1616, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [P.], seq 1616:1701, ack 1, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [P.], seq 1701:3231, ack 1, win
IP 192.168.88.3.1180 > 192.168.88.4.63157: Flags [.], ack 3231, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [P.], seq 3231:3316, ack 1, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [P.], seq 3316:4846, ack 1, win
IP 192.168.88.3.1180 > 192.168.88.4.63157: Flags [.], ack 4846, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [.], ack 273, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [P.], seq 4846:4931, ack 273, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [.], ack 274, win
IP 192.168.88.4.63157 > 192.168.88.3.1180: Flags [FP.], seq 4931:5016, ack 274, win
IP 192.168.88.3.1180 > 192.168.88.4.63157: Flags [.], ack 5017, win
PHP Socket HTTP webserver
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [S], seq 2625331027, win
IP 192.168.88.3.1090 > 192.168.88.4.63152: Flags [S.], seq 4045590166, ack 2625331028, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [.], ack 1, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 1:86, ack 1, win
IP 192.168.88.3.1090 > 192.168.88.4.63152: Flags [.], ack 86, win
IP 192.168.88.3.1090 > 192.168.88.4.63152: Flags [P.], seq 1:582, ack 86, win
IP 192.168.88.3.1090 > 192.168.88.4.63152: Flags [F.], seq 582, ack 86, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 86:1616, ack 1, win
IP 192.168.88.3.1090 > 192.168.88.4.63152: Flags [.], ack 1616, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 1616:1701, ack 1, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 1701:3231, ack 1, win
IP 192.168.88.3.1090 > 192.168.88.4.63152: Flags [.], ack 3231, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 3231:3316, ack 1, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 3316:4846, ack 1, win
IP 192.168.88.3.1090 > 192.168.88.4.63152: Flags [.], ack 4846, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 4846:4931, ack 1, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 4931:6461, ack 1, win
IP 192.168.88.3.1090 > 192.168.88.4.63152: Flags [.], ack 6461, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 6461:6546, ack 1, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 6546:7566, ack 582, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [P.], seq 7566:7651, ack 583, win
IP 192.168.88.4.63152 > 192.168.88.3.1090: Flags [FP.], seq 7651:7821, ack 583, win
IP 192.168.88.3.1090 > 192.168.88.4.63152: Flags [.], ack 7822, win
Things digest November 15
Listen to
Machinae Supremacy – FanVaCoolt (instrumental)
Play in Dragon Nest http://dn.mail.ru/download?counter=1
Implement password store http://habrahabr.ru/qa/27877/
Give a chance to play XCOM on MacOS http://openxcom.org/index.php/downloads/
Download cracked new XCOM 2012 http://www.youtube.com/watch?feature=player_embedded&v=GAFw60ZKLl0
Give up IPoE http://habrahabr.ru/post/108453/
Programming projects: Selenium PHP Neural Network captcha * Homepage Blog microBlog Task list by own framework
Play in Dragon Nest http://dn.mail.ru/download?counter=1
Implement password store http://habrahabr.ru/qa/27877/
Give a chance to play XCOM on MacOS http://openxcom.org/index.php/downloads/
Download cracked new XCOM 2012 http://www.youtube.com/watch?feature=player_embedded&v=GAFw60ZKLl0
Give up IPoE http://habrahabr.ru/post/108453/
Programming projects: Selenium PHP Neural Network captcha * Homepage Blog microBlog Task list by own framework
VK background
ezh@magify ~$ cat /Applications/Opera.app/Contents/Resources/styles/user.css
body.is_rtl.font_default.pads {
background: url('http://eelf.ru/img/background/abstract2.jpg') fixed !important;
}