tag:blogger.com,1999:blog-19314893604319592612023-11-15T10:53:21.067-08:00Practical Software SolutionsPractical solutions for NIX software developers.Bhttp://www.blogger.com/profile/11411212657027395880noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-1931489360431959261.post-69651732461101112262016-06-24T10:29:00.002-07:002016-06-24T10:31:14.416-07:00The LS command to end all LS commands<p>This can go in your ~/.bashrc file<br />
</p><br />
<pre>alias lls="
LC_COLLATE=C \
ls \
--color=always \
--almost-all \
--no-group \
--file-type \
--group-directories-first \
-g \
-o \
--time-style='+%Y-%m-%d %H:%M:%S' | \
awk \
'{print \$3\"\t\"\$4\" \"\$5\"\t\"\$6}' | \
less \
--RAW-CONTROL-CHARS \
--quit-at-eof \
--quit-if-one-screen \
--no-init
"
</pre>Bhttp://www.blogger.com/profile/11411212657027395880noreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-7629201890885128082012-08-23T19:00:00.004-07:002013-08-27T13:19:13.181-07:00Split a Dict or List into Chunks in Python<p>
Sometimes, it is desirable to split a large python iterable
into smaller iterables. I have developed a small module for
<a href="https://stockr.com/">Stockr</a> which can be used to
help with this common task.
</p>
<p>
Supported iterable types:
</p>
<ul>
<li>Lists</li>
<li>Most Basic Generators</li>
<li>Dictionaries</li>
<li>Django QuerySets</li>
</ul>
<p>
Module: <a href="https://github.com/stockr-labs/list_splitter">List-Splitter</a>
</p>
<p>
Usage:
</p>
<pre>
import list_splitter
inp_dict = {
'a': 1,
'b': 2,
'c': 3,
'd': 4,
'e': 5,
'f': 6
}
inp_list = [
1,
2,
3,
4,
5,
6
]
"""
Prints:
[
{'a': 1, 'b': 2, 'c': 3},
{'d': 4, 'e': 5, 'f': 6}
]
"""
print(list(list_splitter.n_chunks(inp_dict, 2)))
"""
Prints:
[
[1, 2, 3],
[4, 5, 6]
]
"""
print(list(list_splitter.n_chunks(inp_list, 2)))
"""
Prints:
[
{'a': 1, 'c': 3},
{'b': 2, 'e': 5},
{'d': 4, 'f': 6}
]
"""
print(list(list_splitter.chunks_of_n(inp_dict, 2)))
"""
Prints:
[
[1, 2],
[3, 4],
[5, 6]
]
"""
print(list(list_splitter.chunks_of_n(inp_list, 2)))
"""
Prints:
[
[{'a': 1}, {'c': 3}],
[{'b': 2}, {'e': 5}],
[{'d': 4}, {'f': 6}]
]
"""
print(list(list_splitter.chunks_matrix(inp_dict, 1, 2)))
"""
Prints:
[
[[1], [2]],
[[3], [4]],
[[5], [6]]
]
"""
print(list(list_splitter.chunks_matrix(inp_list, 1, 2)))
"""
Prints:
[
[{'a': 1, 'c': 3}],
[{'b': 2, 'e': 5}],
[{'d': 4, 'f': 6}]
]
"""
print(list(list_splitter.chunks_matrix(inp_dict, 2, 1)))
"""
Prints:
[
[[1, 2]],
[[3, 4]],
[[5, 6]]
]
"""
print(list(list_splitter.chunks_matrix(inp_list, 2, 1)))
</pre>
Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-1931489360431959261.post-69185575077409279062011-09-28T14:48:00.000-07:002011-09-28T14:48:10.179-07:00Fixing the DropBox Client for GNU/Linux<p>
I had experienced an issue with the DropBox client for Ubuntu 10.04 where PSD files over 1MB were not consistently syncing. Here is a solution which seems to have fixed the problem.
</p>
<p>
Keep in mind that this involves making changes to <strong>/etc/fstab</strong>, which if not done properly, could cause loss of data or other disasters. First, be sure to backup your <strong>/etc/fstab</strong> file, and read up on some <a href="https://help.ubuntu.com/community/Fstab">fstab documentation</a>.
</p>
<p>
In <strong>/etc/fstab</strong> find the root mount point which should have a forward slash as the 2nd field. Fields are separated by spaces or tabs on a line. Mine looks like this:
</p>
<pre>
/dev/sda3 / ext3 errors=remount-ro 0 1
</pre>
<p>
The 4th field is the <strong>options</strong> field. You will want to append the <strong>user_xattr</strong> option to these options. Options are separated by commas, with no space between them. So, in my case, it would look like this:
</p>
<pre>
/dev/sda3 / ext3 errors=remount-ro,<strong>user_xattr</strong> 0 1
</pre>
<p>
After saving this file, restart your computer and DropBox should work correctly.
</p>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-35977318120431514582011-09-12T18:05:00.000-07:002011-09-12T18:10:34.756-07:00Installing Erlang and Agner Package Manager from Source on Ubuntu 10.04I have had many problems using the default erlang package on ubuntu, so I have found it best to install from source. I also use the <a href="http://erlagner.org/">Agner package manager</a> which simplifies Erlang package management. You will need to run most of these commands as sudo.
<pre>> apt-get purge erlang
> apt-get build-dep erlang
> apt-get install curl
> apt-get install libc6-dev
> apt-get install libncurses5-dev
> apt-get install m4
> apt-get install libssl-dev
> apt-get install erlang-mode
> apt-get install openjdk-6-jdk
> cd /usr/local/src/
> git clone --recursive git://github.com/erlang/otp.git erlang-otp
> cd erlang-otp
> ## Replace this with newer version if you wish
> git checkout OTP_R14B01
> ./otp_build autoconf
> ./configure --prefix=/usr/local
> make
> make install
> curl https://raw.github.com/agner/agner/master/scripts/oneliner | sh
> export ERL_LIBS="/usr/local/agner/packages"
> echo >> /etc/environment
> echo 'ERL_LIBS="/usr/local/agner/packages"' >> /etc/environment
</pre>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1931489360431959261.post-4332261866731072672011-08-11T00:44:00.000-07:002011-09-08T12:39:51.850-07:00Installing RabbitMQ with Management Plugin from Source on Ubuntu 10.04These should be run as sudo...
<pre>$ apt-get purge rabbitmq-*
$ userdel -fr rabbitmq
$ apt-get install xsltproc xmlto
$ useradd -M -r -s /bin/bash -d /var/lib/rabbitmq rabbitmq
$ mkdir -p /usr/local/lib/rabbitmq/plugins/
$ mkdir -p /var/log/rabbitmq/ /var/lib/rabbitmq/ /etc/rabbitmq/
$ chown -R root:root /usr/local/lib/rabbitmq/ /etc/rabbitmq/
$ chown -R rabbitmq:rabbitmq /var/log/rabbitmq/ /var/lib/rabbitmq/
$ chmod -R 775 /usr/local/lib/rabbitmq/ /var/log/rabbitmq/
$ chmod -R 700 /var/lib/rabbitmq/
$ cd /usr/local/src/
$ hg clone http://hg.rabbitmq.com/rabbitmq-public-umbrella
$ cd rabbitmq-public-umbrella
$ hg checkout rabbitmq_v2_5_1
$ make co
$ make release
$ make test
$ cp -fr rabbitmq-server/ebin /usr/local/lib/rabbitmq/
$ cp -f rabbitmq-server/scripts/rabbitmqctl /usr/local/sbin/
$ cp -f rabbitmq-server/scripts/rabbitmq-env /usr/local/sbin/
$ cp -f rabbitmq-server/scripts/rabbitmq-server /usr/local/sbin/
$ cp -f rabbitmq-management/dist/amqp_client-*.ez /usr/local/lib/rabbitmq/plugins/
$ cp -f rabbitmq-management/dist/mochiweb-*.ez /usr/local/lib/rabbitmq/plugins/
$ cp -f rabbitmq-management/dist/rabbitmq_management_agent-*.ez /usr/local/lib/rabbitmq/plugins/
$ cp -f rabbitmq-management/dist/rabbitmq_management-*.ez /usr/local/lib/rabbitmq/plugins/
$ cp -f rabbitmq-management/dist/rabbitmq_mochiweb-*.ez /usr/local/lib/rabbitmq/plugins/
$ cp -f rabbitmq-management/dist/webmachine-*.ez /usr/local/lib/rabbitmq/plugins/
$ bash -c 'echo "export HOME=/var/lib/rabbitmq" >> /etc/rabbitmq/rabbitmq-env.conf'
$ bash -c 'echo "export RABBITMQ_HOME=/usr/local/lib/rabbitmq" >> /etc/rabbitmq/rabbitmq-env.conf'
</pre>
If you want to run RabbitMQ as a background service, add it as a supervisord service. Supervisord can be installed by doing:
<pre>apt-get install supervisor
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-58147236296331923422011-07-29T18:37:00.000-07:002012-06-13T17:03:24.315-07:00Sharing a Terminal Session Between 2 Users Behind a Firewall<p>
Imaging that you have 2 users both using Ubuntu 10.04:
<strong>UserA@HostA</strong>
and <strong>UserB@HostB</strong>. <strong>HostB</strong> is behind a
firewall,
and <strong>UserA</strong> would like to SSH into <strong>HostB</strong>
and share a terminal with <strong>UserB</strong> to
collaborate on some kind of task. This article will attempt to
explain how to do this.
</p>
<ol>
<li>
<p>
Make sure both users have SSH access to a "middle" server. We will
call this <strong>HostC</strong>...
</p>
<pre>root@HostC$ sudo useradd -m -s /bin/bash UserA
root@HostC$ sudo useradd -m -s /bin/bash UserB</pre>
</li>
<li>
<p>
Install <em>OpenSSH Server</em> on <strong>HostB</strong>...
</p>
<pre>UserB@HostB$ sudo apt-get install ssh</pre>
<p>
Keep in mind that this could cause potential security
issues, so you should also familiarize yourself with
how to secure OpenSSH server. Specifically, make sure you
disable the "PermitRootLogin" option.
</p>
</li>
<li>
<p>
Install GNU Screen on <strong>HostB</strong> and
setuid root for GNU Screen...
</p>
<pre>UserB@HostB$ sudo apt-get install screen
UserB@HostB$ sudo chmod u+s /usr/bin/screen
UserB@HostB$ sudo chmod -R 755 /var/run/screen</pre>
</li>
<li>
<p>
Add a new user on <strong>for UserA@HostB</strong>...
</p>
<pre>UserB@HostB$ sudo useradd -m -s /bin/bash UserA
UserB@HostB$ sudo passwd UserA</pre>
<p>
Be sure to remember the password for <strong>UserA</strong>
which was set here.
</p>
</li>
<li>
<p>
Have <strong>UserB</strong> SSH into
<strong>HostC</strong>, setting up a remote forward...
</p>
<pre>UserB@HostB$ ssh -R 20022:localhost:22 UserB@HostC</pre>
<p>
<strong>UserB</strong> will need to keep this terminal window open,
but will not need to enter commands here.
</p>
</li>
<li>
<p>
Have <strong>UserA</strong> SSH into
<strong>HostC</strong>.
</p>
<pre>UserA@HostA$ ssh UserA@HostC</pre>
</li>
<li>
<p>
Now, from <strong>HostC</strong>, have <strong>UserA</strong>
SSH into <strong>HostB</strong>...
</p>
<pre>UserA@HostC$ ssh -p 20022 UserA@localhost</pre>
<p>
Keep in mind that <strong>UserA</strong> will be asked for
a password at this point. This will be the password which
was set earlier.
</p>
</li>
<li>
<p>
At this point, <strong>UserA</strong> should now be logged
in to <strong>HostB</strong>. Now <strong>UserA</strong>
will need to setup a named screen session.
</p>
<pre>UserA@HostB$ screen -S foobar
UserA@HostB$ screen -X multiuser on
UserA@HostB$ screen -X acladd UserB</pre>
</li>
<li>
<p>
In a new terminal window, on <strong>HostB</strong>,
have <strong>UserB</strong> join the screen session...
</p>
<pre>UserB@HostB$ screen -x UserA/foobar</pre>
</li>
</ol>
<p>
At this point, both users will share a terminal session on
<strong>HostB</strong>.
</p>
<p>
If you plan on doing this often, you should familiarize
yourself with <em>iptables</em> so as to properly
setup a firewall for added security.
</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-4121583039569017622011-05-25T00:07:00.000-07:002011-05-25T00:18:49.069-07:00Shell Scripting with GNU ScreenThis launches a program in a new screen, method 1. Does not close window after program terminates...
<pre>
screen -t "my-program" -p "-"
screen -p "my-program" -X stuff "/path/to/program
"
screen -X select "my-program"
</pre>
This launches a program in a new screen, method 2. Closes window after program terminates...
<pre>
screen -t "my-program" -p "-" "/path/to/program"
screen -X select "my-program"
</pre>
This kills a process in another screen. This depends on screen-session which can be found at https://github.com/skoneka/screen-session ...
<pre>
sudo screen-session kill "INT" "my-program"
</pre>
This kills a screen window...
<pre>
screen -p "my-program" -X kill
screen -wipe
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-83659710753092310592011-01-10T16:51:00.000-08:002011-07-29T18:41:05.580-07:00Compiling Nginx from Source on Ubuntu 10.04This needs to be run as root.
<pre>
<strong>## Basic stuff</strong>
apt-get update
apt-get install build-essential git-core wget
<strong>## Install PCRE for rewriting</strong>
apt-get install libpcre3 libpcre3-dev
<strong>## Install ssl</strong>
apt-get install openssl libssl-dev
<strong>## Download nginx sources</strong>
cd /usr/local/src/
svn checkout svn://svn.nginx.org/nginx/trunk nginx
cd nginx/
<strong>## Configure</strong>
./configure \
--prefix="/usr/local" \
--conf-path="/usr/local/etc/nginx/nginx.conf" \
--with-http_ssl_module \
--with-cc-opt="-I /usr/include/" \
--with-cc-opt="-I /usr/include/openssl/"
<strong>## Build and install</strong>
make && make install
<strong>## Install init script</strong>
cd /usr/local/src/
git clone git://github.com/brendoncrawford/nginx-init-ubuntu.git
chmod +x nginx-init-ubuntu/nginx
mkdir -p /usr/local/etc/init.d/
cp nginx-init-ubuntu/nginx /usr/local/etc/init.d/nginx
ln -s /usr/local/etc/init.d/nginx /etc/init.d/nginx
/usr/sbin/update-rc.d -f nginx defaults
<strong>## Cleanup stuff</strong>
rm -f /usr/local/etc/nginx/*.default
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-77043936987030015602010-11-20T17:01:00.000-08:002010-11-20T17:04:22.039-08:004 Ways to Get an IP Address From a Host Name in Shell/Bash<pre>
$ dig +short google.com A | head -n1
$ host -4t A google.com | head -n1 | awk -F' ' '{print $NF}'
$ gethostip google.com | cut -d' ' -f2
$ nslookup google.com | grep -iFA2 'Non-authoritative answer:' | grep -iF 'Address:' | cut -d' ' -f2
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-77418876585897445562009-11-28T21:25:00.006-08:002009-11-28T21:27:51.236-08:00DrupalORM: As a programmatic ORM interface to nodes and their CCK fieldsI have recently put up an initial development version of DrupalORM. This provides a nice OOP-like ORM interface to Drupal nodes. It can handle basic CRUD operations as well as handling recursive nodereference nodes.
The project is located at <a href="http://drupal.org/project/orm/">http://drupal.org/project/orm/</a>.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-78409079345754057062009-11-26T01:22:00.000-08:002011-07-29T18:41:54.664-07:00Fixing Weak Wireless on Asus EEE PC With Ubuntu 9.10As a quick google search will show, the wireless signal on the Asus EEE PC for Ubuntu 9.10 is pretty terrible. I found this little trick to work quite well. (Perform at your own risk)
<pre>
$ sudo apt-get install linux-backports-modules-wireless-karmic-generic
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-25555644058920757432009-08-17T23:03:00.000-07:002011-07-29T18:42:15.863-07:00Write to HFSPlus Formatted iPod From Linux (Ubuntu)If you have an ipod which was formatted in iTunes for OSX, it will most likely be formatted with the HFSPlus filesystem with journalling enabled. Ubuntu, by default can write to HFSPlus, but only if journalling is disabled. To write to your iPod, you will need to issue the following command from within the terminal in OSX...
<pre>
diskutil disableJournal /Volumes/NAME-OF-IPOD
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-53027314145156555712009-08-03T13:34:00.000-07:002011-07-29T18:44:01.390-07:00Enabling Memory Profiling for xDebug 2XDebug has not had memory profiling for the last couple of years. I am not sure why it was taken out, but it was. The APD memory profiling seems for the last year or so to be completely broken, so that is no good as well.
There is a patch over at <a href="http://xdebug.org/archives/xdebug-general/1228.html">http://xdebug.org/archives/xdebug-general/1228.html</a> which will allow for memory profiling in xdebug.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-16286924721543263032009-07-31T19:08:00.000-07:002009-07-31T19:28:13.605-07:00Using GnuCash With Bank of the WestThis is not a tutorial for how to setup GnuCash. There is plenty of documentation out there for that. This, however will give you the settings you need to integrate GnuCash with Bankofthewest etimebanker service. This assumes you live in the USA. Have fun.
<pre>
* AqBanking Wizard
* Users > General...
* User Name: (your name)
* User ID: (your etimebanker id)
* Customer ID: (your etimebanker id)
* Country: United States of America
* Bank ID: (your bank routing code, found at bottom of your check)
* Users > OFX...
* FID: "5809"
* ORG: "BancWest Corp"
* Server URL: "https://olbp.bankofthewest.com/ofx0002/ofx_isapi.dll"
* Server Options
* Supports account list download
* Supoorts statement download
* Force SSLv3
* Expert Settings...
* APPID: "QWIN"
* APPVER: "1800"
* Header Version: "102"
* Accounts > General...
* Account Settings
* Name: "DIRECT CHOICE CHECKING" or "SAVINGS INTEGRATED - PERSONAL"
* Number: (your account number)
* IBAN: (blank)
* Owner Name: (your name)
* Type: "CHECKING" or "SAVINGS"
* Available Users...
* All users of this backend
* Add user
* Bank Settings
* Code: (bank routing code)
* BIC: (blank)
* Name: "Bank of the West"
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-24986130728421890442009-04-16T13:26:00.000-07:002009-04-17T11:10:20.507-07:00Theming the Drupal 6 User Login FormThere are a great deal of articles out there on theming the Drupal User Login Form, but most don't give you granular control over each individual form element. Rather, you are restricted to mainly editing the css. Here is a way to have complete granular control over each element within the user login form...
<strong>1. Place this function either in a module or in your template.php:</strong>
<pre>
function get_user_login_form() {
$form_id = 'user_login';
$form = array();
$form['name'] = array(
'#type' => 'textfield',
'#maxlength' => USERNAME_MAX_LENGTH,
'#required' => TRUE,
'#attributes' => array('tabindex' => '1'),
);
$form['pass'] = array(
'#type' => 'password',
'#required' => TRUE,
'#attributes' => array('tabindex' => '2'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Log in'),
'#weight' => 2,
'#attributes' => array('tabindex' => '3')
);
$form['#validate'] = user_login_default_validators();
$form['#build_id'] = sprintf('form-%s', md5(uniqid(mt_rand(), TRUE)));
$form_state = array();
drupal_prepare_form($form_id, $form, $form_state);
drupal_process_form($form_id, $form, $form_state);
$out = new stdClass;
$out->form_start =
sprintf("<form method='post' accept-charset='UTF-8' action='%s'>",
url('user/login'));
$out->form_end = "</form>";
$out->name = drupal_render($form['name']);
$out->pass = drupal_render($form['pass']);
$out->submit =
drupal_render($form['form_id']) .
drupal_render($form['form_build_id']) .
drupal_render($form['submit']);
return $out;
}
</pre>
<strong>2. In your .tpl.php file, output the fields</strong>
<pre>
<?php
$login_form = get_user_login_form();
?>
<?php print $login_form->form_start; ?>
Username: <?php print $login_form->name; ?><br />
Password: <?php print $login_form->pass; ?><br />
<?php print $login_form->submit; ?>
<?php print $login_form->form_end; ?>
</pre>Unknownnoreply@blogger.com18tag:blogger.com,1999:blog-1931489360431959261.post-64623840413542196932008-07-11T13:58:00.000-07:002008-07-11T14:00:38.589-07:00Drupy: Drupal in Python" Drupy is a Python port of the Drupal content management system, which until now was only available in PHP."
This is a great project, filling a big need. Check it out.
<a href="http://drupy.net">The Drupy Project</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-45696224153692542622008-04-15T00:26:00.000-07:002008-04-15T00:27:36.581-07:00Drupal AJAX Forms ValidationHere is a beautiful little module I have created which will automagically validate your forms via AJAX, so you get no page refresh when getting back validation information on a Drupal form.
<a href="http://drupal.org/project/ajax_validation">Drupal AJAX Forms Validation</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-26781186772520714532008-03-17T15:24:00.000-07:002008-03-17T15:27:17.676-07:00Get Non Up-to-Date Files in CVSHere it is:
<pre style="color:green;">
# Get Non Up-to-Date Files in CVS
# This will not work within a Bash alias without proper escaping
# It would be better to put it in file somewhere within you Bash PATH
cvs -qr status | grep Status: | awk '$4 != "Up-to-date" { print $0 }'
</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1931489360431959261.post-88136505040752639602007-10-18T04:27:00.000-07:002007-10-22T22:51:36.325-07:00Enabling CakePHP 1.1 on Lighttpd 1.5A lot of people out there are trying to figure out how to get CakePHP 1.1x running on Lighttpd 1.5. Here is the solution. Please follow it carefully:
<pre>
<strong>#### Disable BASE_URL ####</strong>
a) Open the file "app/config/core.php"
b) Make sure that the BASE_URL constant is commented out
<strong>#### REDIRECT_URI fix ####</strong>
a) Open the file "cake/basics.php"
b) Go to the function "setUri"
c) Find this line:
<span style='color:green'>if (env('HTTP_X_REWRITE_URL')) {</span>
Replace with this:
<span style='color:green'>if( env('REDIRECT_URI') ) {
$uri = env('REDIRECT_URI');
}
else if (env('HTTP_X_REWRITE_URL')) {</span>
<strong>#### Add rewrite rules to lighttpd.conf ####</strong>
a) Enable mod_rewrite in lighttpd.conf
b) Add this to lighttpd.conf:
<span style='color:green'>url.rewrite-once = (
"^/(css|files|img|js|stats)/(.*)$" => "/$1/$2",
"^/(.*)$" => "/index.php?url=$1"
)</span>
</pre>Unknownnoreply@blogger.com8