Enable backspace when ssh into a debian machine with zsh 2
As many users of mac OS X, I’ve encountered some troubles with the backspace key when ssh into a debian machine.
Reading some posts on the web, I was thinking that the problem was about the shell or the tty. But in fact it was related to zsh.
The default zsh map on debian is not correct for mac users. The solution is to tell zsh how to bind keys.
echo "bindkey ^? backward-delete-char" >> ~/.zshrc
echo "bindkey ^[[3~ delete-char" >> ~/.zshrcUse ctrl+v [key] to generate the ^... characters.
Extract an image screenshot from a Video with ffmpeg 3
Here is a way to extract a sample image from a video with ffmpeg :
$ ffmpeg -itsoffset -4 -i sample.mov -vcodec png -vframes 1 -an -f rawvideo -s 320x240 test.png- -itsoffset -4 : means that you want to extract the image 4 seconds after video starts.
Easy setup a Mongrel cluster with Apache 2.2 on Mac OS X
Mongrel is a very fast and secure server for Ruby On Rails applications. It also supports Nitro and Camping. Setting up a mongrel_cluster on Mac OS X is not very difficult but it is a bit different from other Unix platforms.
What you need to start :Step 1 : Install Mongrel
Mongrel is available for unix platform and Win32 systems as a gem.
$ sudo gem install mongrel mongrel_clusterInstalling Apache 2.2
You can compile it from sources. But it is easier to install it via MacPorts.
$ sudo port install apache2All apache2 files will be installed in /opt/local/apache2, including binaries and configuration files.
Setting up Apache 2.2
chdir to /opt/local/apache2/conf and copy the sample file to httpd.conf$ cd /opt/local/apache2/conf
$ sudo cp httpd.conf.sample httpd.confCreate a new directory that will contain your application specific configuration files for Apache.
$ sudo mkdir myapp
$ cd myappCreate 3 files for your new application. (adapted from codahale blog)
$ sudo touch myapp.common myapp.conf myapp.cluster.confHere is the files content :
myapp.common :
ServerName www.myserver.com
DocumentRoot /path/to/my/app/public
<Directory "/path/to/my/app/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RewriteEngine On
# Make sure people go to www.myapp.com, not myapp.com
RewriteCond %{HTTP_HOST} ^myapp.com$ [NC]
RewriteRule ^(.*)$ http://www.myapp.com$1 [R=301,L]
# Yes, I've read no-www.com, but my site already has much Google-Fu on
# www.blah.com. Feel free to comment this out.
# Uncomment for rewrite debugging
#RewriteLog logs/myapp_rewrite_log
#RewriteLogLevel 9
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
# Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
# Uncomment for deflate debugging
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
#CustomLog logs/myapp_deflate_log deflatemyapp.conf :
<VirtualHost *:80>
Include /opt/local/apache2/conf/myapp/myapp.common
ErrorLog /path/to/logs/error.log
CustomLog /path/to/logs/access.log combined
</VirtualHost>myapp.cluster.conf :
<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002
</Proxy>Now that your files are created. at this to the bottom of /opt/local/apache2/conf/httpd.conf
NameVirtualHost *:80
Include conf/myapp/myapp.conf
Include conf/sites/myapp.cluster.confApache is now ready to run.
Setting up Mongrel cluster
Create a new dir for mongrel cluster config
mkdir /opt/local/etc/mongrel
cd /opt/local/etc/mongrelAnd create a new file “myapp.yml”
---
user: www
group: www
port: "8000"
cwd: /path/to/your/app/root
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 3Setting up Startup Scripts
Enable apache startup script
$ sudo vi /etc/hostconfig
#add the following lines
APACHE2=-YES-
MONGREL=-YES-Copy the following into /Library/StartupItems/mongrel_cluster/mongrel_cluster
(adapted from original mongrel init script)#!/bin/bash
#
# Copyright (c) 2006 Bradley Taylor, bradley@railsmachine.com
#
# mongrel_cluster Startup script for Mongrel clusters.
#
# chkconfig: - 85 15
# description: mongrel_cluster manages multiple Mongrel processes for use \
# behind a load balancer.
#
[ -r "/etc/hostconfig" ] && . "/etc/hostconfig"
CONF_DIR="/opt/local/etc/mongrel"
RETVAL=0
ENABLE_FLAG=${MONGREL:=-NO-}
if [ "${ENABLE_FLAG}" = "-NO-" ]; then
echo "Mongrel is disabled. see /etc/hostconfig"
exit 0
fi
case "$1" in
start)
mongrel_cluster_ctl start -c $CONF_DIR
RETVAL=$?
;;
stop)
mongrel_cluster_ctl stop -c $CONF_DIR
RETVAL=$?
;;
restart)
mongrel_cluster_ctl restart -c $CONF_DIR
RETVAL=$?
;;
*)
echo "Usage: mongrel_cluster {start|stop|restart}"
exit 1
;;
esac
exit $RETVALLinux : ethernet interface supported media
I was just checking on my machines if all my ethernet cards supports 1Gb ethernet. On OS X ifconfig will give you what you want under the section supported media, but on Linux Debian it doesn’t. For this you have to use ethtool :
sudo ethtool eth0Creating favicon.ico on Unix machines
Favicon are little icons that you can see in your browser before URL address.
To create this icons on unix-likes proceed as follow.
Open your favourite Image manipulator program, for me It will be The GIMP.
Create a 16×16 px PNG, and optionally a 32×32 px PNG.
Install png2ico from sources, package or compile it via darwinports.
For OS X with darwinports :
$ sudo port install png2icoand create your favicon file :
$ png2ico favicon.ico favicon16.png favicon32.pngNow that you have your favicon file, just put it in your web server root directory.
You can had the following for IE compatibily in your web pages :
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
Mac OS X : change lookup order, files comes first
I’m originally a Linux user. Then, in Linux lookup default order is to look first in /etc/hosts file and then to launch the dns query.
But In OS X default is to search to into NetInfo DB first.
To change this behaviour you have to change the configuration of the lookup daemon.
$ cd /etc
#if lookupd directory doesn't exists create it
$ sudo mkdir lookupd
$ cd lookupd
$ sudo echo LookupOrder Cache FF NI DNS DS > /tmp/hosts
$ sudo mv /tmp/hosts .
# reload configuration of lookupd
$ sudo lookupd -configurationAll right, you’re now setup the old fashion way.
Mac OS X : Restart ARDAgent from ssh
ARDAgent (Apple Remote Desktop Agent) sometimes freeze and then it may be impossible to control your remote server.
Here is the command line to restart it.
# ssh into you machine
$ ssh user@host
# locate the restart script
$ locate kickstart
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart
# restart the agent
$ cd /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources
$ sudo ./kickstart -restart -agent
Egroupware : hide private contacts in LDAP
Egroupware can store contacts from address book in an LDAP server. So, it is possible to access address book from a Mail client that supports LDAP.
The problem is that users would see any contact, even if it is private.
To prevent this from happening you can add this in slapd.conf :
access to dn.sub="ou=contacts,dc=example,dc=com"
filter="(&(objectClass=phpgwContact)(phpgwContactAccess=private))"
by dn="cn=admin,dc=example,dc=com" write
by * none
access to dn.sub="ou=contacts,dc=example,dc=com"
by dn="cn=admin,dc=example,dc=com" write
by * readaccess to *
by dn="cn=admin,dc=example,dc=com" write
by * readpam_ldap : Impossible to connect with local account when ldap server is down
Versions (debian packages):
- libnss_ldap : 251-1
- libpam-ldap : 180-1
When using ldap authentification with pam_ldap, if ldap server fails it may be impossible, or very slow to login even with a local account.
This happen when libnss-ldap is configured with the option :
bind_policy hard_open
To fix this, use :
bind_policy soft

