Friday, October 21, 2011

PDO utf-8 issues

Had issues with json_encode complaining:
Invalid UTF-8 sequence in argument 

Fixed it by adding

PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
to the PDO creation line.. ie:
$pdo = new PDO(
    'mysql:host=mysql.example.com;dbname=example_db',
    "username",
    "password",
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));


source

Tuesday, October 11, 2011

Emacs, geben and xdebug

* sudo pecl install xdebug
* edit php.ini
  zend_extension=/path/to/xdebug.so
; usually /usr/lib/php5/20060613+lfs/xdebug.so
  [debug]
  xdebug.remote_autostart=off
  xdebug.remote_enable=on
  xdebug.remote_handler=dbgp
  xdebug.remote_mode=req
  xdebug.remote_host=localhost
  xdebug.remote_port=9000
* restart apache: /etc/init.d/apache2 restart
* download geben: http://trac.sakura.ne.jp/geben/
* unpack it into ~/emacs.d/ (emacs includes folder) * add this to your .emacs file:
(add-to-list 'load-path "/home/your/emacs.files/geben")
(add-to-list 'load-path "/home/your/emacs.files/geben/gud")
* restart emacs and run geben with `M-x geben`
* open a php service with the parameter
`?XDEBUG_SESSION_START` to start debugging


source

Thursday, September 22, 2011

Ignoring changes in a tracked file in git

Ignore changes:

git update-index --assume-unchanged 

Un-ignore changes:
git update-index --no-assume-unchanged



[source]

Thursday, September 15, 2011

Smugly accusing someone of anger doesn’t do anything to discount the content of the argument. [1]

Monday, August 8, 2011

Setting 'git pull' to use --rebase for all branches

git config --global branch.autosetuprebase always

Thursday, June 30, 2011

Gettext and codesets. UTF-8 in particular

For the longest time, Japanese translations weren't working and kept returning ???? instead of the correct Japanese characters. A college finally found the solution:

bind_textdomain_codeset("messages", 'UTF-8');


where "messages" is the text domain that was bound with the textdomain command.

Stupidly difficult bug to tackle.

Tuesday, May 3, 2011

Gettext workflow

1. Define your bindtextdomain and textdomain as
bindtextdomain('hello', '/usr/share/locale')
textdomain('hello')

2. Wrap strings to be translated in gettext('translate me') or, using the gettext alias, _('translate me').
return _('this string is to be translated');
3. Extract the strings using the xgettext utility.
xgettext -d hello -s -o hello.pot hello.c
4. Turn the .pot file into a .po file that can be passed on to the translators
msginit -l es_US -o spanish.po -i hello.pot
5. Translate the strings in the .po file
msgid "Hello\n"
msgstr "Hola\n"
6. Convert the .po file into a compiled .mo using the msgfmt utility, note that the output filename must match the domain given as the first argument to bindtextdomain and textdomain and must be placed in the location specified as the second argument to bindtextdomain
joined with the language set in setlocale or set in the environment
msgfmt -c -v -o hello.mo spanish.po
cp hello.mo /usr/share/locale/es_US/LC_MESSAGES
source

Friday, April 22, 2011

Veetle player and ICEauthority

Installing the Veetle player on Ubuntu by running the install script as super user causes issues by changing the owner of your home directory to 1016 (or a similar #). This can easily be rectified by simply chown/chgrp your home directory back to your user and by replacing .ICEauthority file in your home directory with the /var/lib/gdm/.ICEauthority file (you also have to chown/chgrp the .ICEauthority file once you've copied it).



Source

Adding locales for gettext

Go to System -> Administration -> Language Support and add the languages you want to support.

Once those have installed, run

sudo dpkg-reconfigure locales

Done

Source

Wednesday, April 6, 2011

Emacs Tramp Cheatsheet

Open a file on a remote machine:
C-c C-f /user@machine:path/to.file

Sudo with Tramp:
C-c C-f /sudo::/path/to/file

Source

Tuesday, March 15, 2011

Emacs back references in replace-regex.

From http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Replace.html

In replace-regexp, the newstring need not be constant: it can refer to all or part of what is matched by the regexp. ‘\&’ in newstring stands for the entire match being replaced. ‘\d’ in newstring, where d is a digit, stands for whatever matched the dth parenthesized grouping in regexp. (This is called a “back reference.”) ‘\#’ refers to the count of replacements already made in this command, as a decimal number. In the first replacement, ‘\#’ stands for ‘0’; in the second, for ‘1’; and so on. For example,

M-x replace-regexp <RET> c[ad]+r <RET> \&-safe <RET>

replaces (for example) ‘cadr’ with ‘cadr-safe’ and ‘cddr’ with ‘cddr-safe’.

Wednesday, February 9, 2011

mod_proxy in ubuntu

In order to get mod_proxy running in ubuntu I had to:
  • ln -s /etc/apache2/mods-available/proxy.conf /etc/apache2/mods-enabled/proxy.conf
  • ln -s /etc/apache2/mods-available/proxy.load /etc/apache2/mods-enabled/proxy.load
  • ln -s /etc/apache2/mods-available/proxy_http.load /etc/apache2/mods-enabled/proxy_http.load
Then in my conf file (sites-enabled/my-site) I added between the VirtualHost tag

<proxy>
Order deny,allow
Allow from all
</proxy>

<location /pickup >
ProxyPass http://qa-ox3-datamart-xv-01.xv.dc.openx.org/pickup/
ProxyPassReverse http://qa-ox3-datamart-xv-01.xv.dc.openx.org/pickup/
</location>

Delete a remote branch in git

git push origin :branchname

Monday, January 31, 2011

Simple wsgi apps without using a framework.

Using apache and mod_wsgi, serve a dirt simple app (useful for mocking services that havent been created yet by other programmers).

After installing mod_wsgi (sudo apt-get install libapache2-mod-wsgi)

Apache conf:
WSGIScriptAlias /webdir/ /filesys/dir/
With this you can call wsgi scripts in 'webdir' as localhost/webdir/test.py

python WSGI code for the file /filesys/dir/test.py:

def application(environ, start_response):
response_body = '{"fake-json":"temp-output"}'
status = '200 OK'
response_headers = [('Content-Type', 'application/json'),
('Content-Length', str(len(response_body)))]
start_response(status, response_headers)

return [response_body]

Done. No stupid framework needed for stupid simple apps.