Monday, April 28, 2014

Discourse As Potential Mailing List Replacement

While tested out Discourse, I only found a few negative things:
  1. To make it act like a mailing list, it currently requires each user to change settings on their account: https://github.com/discourse/discourse/blob/master/docs/MAILING-LIST-SETUP.md#suggested-user-preferences
    I commented on a thread about a new feature that allows setting defaults for this: https://meta.discourse.org/t/default-email-settings-for-a-new-user/14980
  2. It doesn't allow setting defaults for which categories the user has "Watched". For example, I would want to default the "General" list to "Watched", but more obscure lists would only be watched if the user chooses to.
  3. It uses a different e-mail address for each e-mail it sends you (this is to keep track of which thread it belongs to), here's an example of a "From" address: testdiscourse+43854630fb3a3d9492505fa5a23db196@gmail.com
    Google Groups always has the same to/from e-mail address and magically figures this out. This might be weird in some peoples' email clients.
As a forum, this beats the crap out of PhpBB, but as a mailing list it's not a clear winner over Google Groups yet. It's open source, has a better web interface, and the "Categories" are a cool feature for keeping all the lists in the same place. But, the "email in" functionality was too recently implemented, and it might take a few months before it's as polished as Google Groups.

It's going to be a very tempting replacement if they add default settings for user preferences.

Screenshots:






Data source name not found and no default driver specified - SQLalchemy/Sybase

I was getting this error when trying to connect to a sybase database using Microsoft's odbc driver by using the connection string shown in the SqlAlchemy examples:
DBAPIError: (Error) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') None None

The following code worked to connect:
import pyodbc, sqlalchemy

def connect():
    return pyodbc.connect('DSN=<dsn name>;UID=<username>;PWD=<password>')

srcEngine = sqlalchemy.create_engine('sybase+pyodbc://', creator=connect, echo=True)

Saturday, April 26, 2014

Docker Not Starting - Ubuntu

I was getting this error message because docker was refusing to start: Cannot connect to the Docker daemon. Is 'docker -d' running on this host?

This issue was occurring because my kernel was refusing to upgrade, because I was on a VPS. (you need to get your VPS provider to upgrade it for you)

Run uname -r, if it returns something like this: "2.6.32-042stab084.20" That's probably the reason why docker isn't starting. Your kernel isn't compatible.

If you're not on a VPS and can upgrade your kernel, try instructions on this page: http://docs.docker.io.s3-website-us-west-2.amazonaws.com/installation/ubuntulinux/

E: Sub-process /usr/bin/dpkg returned an error code (1)

I was getting this error message while I was trying to upgrade the kernel on my VPS:
/usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?).
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 1
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-3.8.0-34-generic.postrm line 328.
dpkg: error processing linux-image-3.8.0-34-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-3.8.0-34-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

You might not be able to upgrade the kernel on your VPS. Contact your VPS provider and get them to upgrade the kernel for you.

WHMCS Cronjob Not Running On Ubuntu

My issue was the user with the cronjob did not have access to run the cronjob php file. So, I needed to make the new cronjob for the correct user.

Solution:

  1. Find out the owner of your apache process (usually www-data).
  2. Look at the top of the "Automation Settings" page in your WHMCS admin area. It should say something like: php -q /var/www/whmcs/admin/cron.php (keep this handy for step 4)
  3. In terminal run: crontab -e -u www-data
  4. Ensure you have a line that says:
    0   6   *   *   *    php -q /var/www/whmcs/admin/cron.php (note: this should be the same file path you got for your own install in step 2)



Http Port 443 Working But Https Port 443 Not Working In CherryPy - Python

I was able to visit my site using HTTP and port 443, but nothing would even show in the log when I tried to visit with HTTPS and port 443.

This seems to only be an issue with CherryPy 3.3.0, I switched back to CherryPy 3.2.3 and it worked again.

I noted it on their bitbucket issue here: https://bitbucket.org/cherrypy/cherrypy/issue/1298/ssl-not-working

OpenSSL DLL load failed On Windows - Python

The DLL load failed error happened when cherrypy tried the following import: "from OpenSSL import SSL"

ChannelFailures: VerificationError("importing 'C:\\\\Python27\\\\lib\\\\site-packages\\\\cryptography\\\\_Cryptography_c
ffi_48bbf0ebx93c91939.pyd': DLL load failed: %1 is not a valid Win32 application.",)

These error messages are solved with this install: http://slproweb.com/download/Win32OpenSSL-1_0_1g.exe

If you have a 32-bit version of python, that install will move the correct DLLs to your system32 folder.

Thursday, April 24, 2014

My First Python Library

https://github.com/pawl/Chinese-RFID-Access-Control-Library

I purchased a chinese access controller and reverse engineered some functionality of the windows software that came with it. I made a python library that does some of the same functions as the desktop software: https://github.com/pawl/Chinese-RFID-Access-Control-Library/

I use this library to tie our access controller into with our billing system (called WHMCS) and another web application (which is meant to be a self-documenting way to activate/deactivate RFID badges): https://github.com/pawl/MakerManager

Now, whenever someone stops paying for 5+ days, their RFID badge is deactivated because a "hook" in WHMCS sends a request to a webservice that uses the access control library.

Sunday, April 20, 2014

Android Bitcoin OutOfMemoryError Or Crashing On Startup

This page explains the problem: https://code.google.com/p/bitcoin-wallet/wiki/OutOfMemory

At one point, it got so bad that the application would not even start anymore.

Solution:

  1. Get Root Explorer
  2. Navigate to your system folder and open "build.prop" in the text editor
  3. Edit "dalvik.vm.heapsize" and "dalvik.vm.heapgrowthlimit" to the following:
    dalvik.vm.heapsize=256m
    dalvik.vm.heapgrowthlimit=128m
  4. Restart your phone, open the bitcoin application, and backup your keys before it crashes again.

Monday, April 14, 2014

Lock wait timeout exceeded - MySQL

OperationalError: (OperationalError) (1205, 'Lock wait timeout exceeded; try restarting transaction')

After trying a bunch of different solutions in the code, I ended up having to restart MySQL to get this error message to go away.

Solution To Apache Triggering OOM-Killer

Update: We switched to Prefork apache and have been experiencing significantly fewer problems.

In this instance, we were getting hit with web crawlers according to the access log and the syslog was saying this: /usr/sbin/apach invoked oom-killer

This issue occurs when apache opens up too many child processes, uses up too much memory, then OOM killer starts shutting down random processes like mysql.

The problem ended up being that our apache2.conf did not have any configuration limiting the number of processes that Apache could open. It might have had a default, but the default was too high. We were using Apache ITK MPM and the apache2.conf only mentioned prefork, worker, and event MPMs. You can check which MPM you are running with "apache2 -V".

Adding this to the configuration solved the problem:
<IfModule mpm_itk_module>
    StartServers 5
    MinSpareServers 5
    MaxSpareServers 10
    ServerLimit 75
    MaxClients 75
    MaxRequestsPerChild 5000
</IfModule>

At first I had the ServerLimit and MaxClients set to 150 and it seemed like apache was ignoring ServerLimit and Maxclients. However, ITK MPM creates an extra fork for each request (according to their site), that's why there was 200+ processes running for my limit of 150. So, the process count is going to be 2x the limit you set.

Thursday, April 3, 2014

Edit A Sharepoint List Page

Add the following to the end of the List page's URL:  ?ToolPaneView=2

Tuesday, April 1, 2014

Override ModelView Class - Flask-Admin

This has an awesome example of how to override your base ModelView: http://code.vokor.org/vokorbb/src/04de9dcb666d2fb35513ca29c97654b6eef80648/vokorbb/admin.py?at=tip

You would want to do this if you wanted to add something to all of your admin classes. Use cases:

  • If you wanted to require login by overriding is_accessible for all of your ModelViews.
  • If you wanted to add an export method to all of your ModelViews.

Flask-Admin Export CSV

Edited: This was recently added to Flask-Admin as a feature.

You can add "can_export = True" to your ModelView to enable it.

More info here: http://flask-admin.readthedocs.org/en/latest/api/mod_model/#flask_admin.model.BaseModelView.can_export

Print URL With Request Parameters/Arguments - Python Flask / Jinja2

You need to add the following to your jinja2 template:
{{ request.path ~ '?' ~ request.query_string }}

You can also print only the Get Variables / URL Parameters / Argument String with the following:
print request.query_string

The example is available here: http://stackoverflow.com/a/11781872/1364191