Skip to content

Instantly share code, notes, and snippets.

@joergpatz
joergpatz / apache-proxy-vhost
Last active February 4, 2016 21:27
apache-proxy-vhost
# Forward Proxy
<VirtualHost *:80>
ServerAdmin admin@localhost
RewriteEngine On
ProxyPreserveHost On
RewriteRule ^/(.*) http://<HOST-OR-IP>/$1 [P]
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
@joergpatz
joergpatz / convert-date-to-timestamp-in-PHP.php
Created June 23, 2014 18:55
convert date to timestamp in PHP
// DateTime API
$dateTime = new DateTime('2014-06-23');
echo $dateTime->format('U');
echo $dateTime->getTimestamp();
// or
$dateTime = DateTime::createFromFormat('!d-m-Y', '23-06-2014');
// or IntlDateFormatter API
$fmt = new IntlDateFormatter(
@joergpatz
joergpatz / start-agent.sh
Created June 15, 2014 15:40
automatic-start-ssh-agent
SSH_ENV=$HOME/.ssh/environment
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
@joergpatz
joergpatz / htaccess-rewrite-rules.md
Last active August 29, 2015 14:02
htaccess and rewrite rules

I can't remember rewrite rules:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.your-domain\.com [NC]
RewriteRule (.*) http://www.your-domain.com/$1 [L]


RewriteCond %{HTTP_HOST} !^www\.other-domain\.com [NC]
RewriteRule (.*) http://www.other-domain.com/$1 [L]
@joergpatz
joergpatz / avg-of-count.md
Last active August 29, 2015 14:00
mysql code snippets

use the average aggregate function of a count query:

SELECT AVG (sender_count)
FROM (
  SELECT COUNT(sender_mail) AS sender_count
  FROM event

) AS event

@joergpatz
joergpatz / import-mysql-dumpfile.md
Created April 30, 2014 10:47
import mysql dump

mysql -h<hostname> -u<user> -p<password> <database> < example.sql

gz'ed dumpfile

gunzip &lt; .sql.gz | mysql -h -u -p

@joergpatz
joergpatz / apache-prefork-vs-worker.txt
Created April 30, 2014 10:40
Apache prefork vs. worker
##
## Server-Pool Size Regulation (MPM specific)
##
# prefork MPM
# implements a non-threaded, pre-forking web server (isolating each request)
# physical RAM hungry, maxclients is important
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
@joergpatz
joergpatz / allow-only-a-ip-range.md
Last active August 29, 2015 14:00
Apache mod_rewrite
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^(192\.168\.56\.1|192\.168\.56\.2)$
RewriteCond %{REQUEST_URI} (/login.*|/node.*|/welcome.*) [NC]

RewriteRule ^(.*)$ index.php [F,L]

        $ids = DB::table('service')
                ->select(DB::raw('DISTINCT label_id AS cat_label_id'))
                ->whereNull('deleted_date')
                ->lists('cat_label_id');

$ids will be an array.