Dienstag, 26. Mai 2015

Install CMU Sphinx on Arch Linux on Raspberry

I spent several days now (non-continuus work :)) to install CMU Sphinx on my Raspberry Pi.
First there were problems installing it, cause of a too lower version of cmake on debian. After upgrading debian(Raspbian) to Jessie cmake was fine and CMU Sphinx installation was straight forward. Though after a restart, the Pi didn't boot anymore.
So I tried it again with Arch Linux which was rather painful:

CMU Sphinx wants(!) to use pulseaudio or jack for its audio-input. Though these are not so easy to setup (especially if you don't use a GUI). To force the CMU Sphinx configure script to use simple ALSA run:

sudo mv /usr/include/jack/jack.h /usr/include/jack/jack.h.old
sudo mv /usr/include/pulse/pulseaudio.h /usr/include/pulse/pulseaudio.h.old

Then follow the common installation guides

Have fun.

Montag, 20. April 2015

Creating and using Basic Auth Proxies with Scrapy

It's on Google but cumbersome to find. So here my way to install and use private proxies for Scrapy:


On the server you want to use as proxy
- Install squid3 and apache2-utils
- Put this in your /etc/squid3/squid.conf

auth_param basic program /usr/lib/squid3/ncsa_auth /etc/squid3/passwd
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users
http_port 3128

- Create the password file
htpasswd /etc/squid3/passwd user
<< Enter password two times
- service squid3 restart

Now on scrapy add a middleware (don't forget to add it to the middlewares list in settings.py):
class ProxyMiddleware(object):
    def process_request(self, request, spider):
        try:
            request.meta['proxy'] = spider.proxy
            proxy_user_pass = "vim:<passwordhere>"
            encoded_user_pass = base64.encodestring(proxy_user_pass)
            request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass
        except KeyError: # No proxy address defined in spider? Then skip
            pass

Test your proxy with:
curl --proxy ip:3128 --proxy-user user:password ipecho.net/plain


Thanks to:
http://facts-world.blogspot.ru/2010/05/configuring-squid3-with-basic.html
https://sandalov.org/blog/1711/
http://stackoverflow.com/questions/20792152/setting-scrapy-proxy-middleware-to-rotate-on-each-request

Dienstag, 31. März 2015

Push to deploy

Die einfachste Variante Git Push to deploy einzurichten:

Auf dem Deploy Server(setup_deploy_server.sh):

DEPLOY_DIR=$1
PROJECT_NAME=$2 
cd $DEPLOY_DIR
git init --bare ${PROJECT_NAME}.git
mkdir $PROJECT_NAME
cat <<EOF > ${PROJECT_NAME}.git/hooks/post-update
#!/bin/sh
if [[ "\$3" != "master" ]]
then
    echo "Received branch \$3, not deploying."
    exit
fi
GIT_WORK_TREE="${DEPLOY_DIR}/${PROJECT_NAME}" git checkout -f master
EOF
chmod +x ${PROJECT_NAME}.git/hooks/post-update

Auf dem Dev Rechner im Git Repo

git remote add deploy ssh://deploy_server/${DEPLOY_DIR}/${PROJECT_NAME}.git
git push deploy master