Zach Dwiel http://dwiel.net Repository of code snippits and ideas Fri, 06 Jan 2012 03:36:06 +0000 en hourly 1 http://wordpress.org/?v=3.3.1 Carbon Footprint of Plastic http://dwiel.net/blog/carbon-footprint-of-plastic/ http://dwiel.net/blog/carbon-footprint-of-plastic/#comments Fri, 06 Jan 2012 03:36:06 +0000 dwiel http://dwiel.net/?p=363 We've been discussing the materials used in our new house and are pretty set on not using any plastic. However, there are a few key places where it might be extremely helpful so I decided to look into how bad it really is (from a carbon footprint perspective). I am still strongly opposed to having exposed plastic that would off-gas and degrade into the air, but if it is built into the structure maybe I wouldn't mind quite so much. Here are the numbers I can up with:

  • 600 square feet of 6 mil plastic → 100 kilowatt hours of electricity
  • 100' of 3/4" PEX tubing → 45 kilowatt hours of electricity

This is only counting the manufacture of the materials I believe, not the transport of the finished product. for a reference point, our current house uses about ~120 kilowatt hours of electricity per month. The average home in the US uses about 800 kilowatt hours. This will be helpful in determining when we want to use plastic.

Sources:

]]>
http://dwiel.net/blog/carbon-footprint-of-plastic/feed/ 0
service error when starting mongodb http://dwiel.net/blog/service-error-when-starting-mongodb/ http://dwiel.net/blog/service-error-when-starting-mongodb/#comments Fri, 26 Aug 2011 13:12:45 +0000 dwiel http://dwiel.net/?p=335 I was trying to start mongodb just now and couldn't understand why it wasn't working. Turns out I needed to be sudo - not the most clear error message ...

 
$ service mongodb start
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.11
212" (uid=1000 pid=1360 comm="start) interface="com.ubuntu.Upstart0_6.Job" membe
r="Start" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart
" (uid=0 pid=1 comm="/sbin/init"))
$ sudo service mongodb start
mongodb start/running, process 1326
]]>
http://dwiel.net/blog/service-error-when-starting-mongodb/feed/ 2
Ubuntu 11.04 on Thinkpad T420s http://dwiel.net/blog/ubuntu-11-04-on-thinkpad-t420s/ http://dwiel.net/blog/ubuntu-11-04-on-thinkpad-t420s/#comments Sun, 17 Jul 2011 15:00:01 +0000 dwiel http://dwiel.net/?p=329 Just bought this thinkpad 420s. The first thing I did when I got it was install Ubuntu 11.04 on it. Most everything worked on first install, including things which many people seemed to have problems with on the forums.

Working:

  • Displays work fine with 3d effects and everything (dual monitor with and without docking station) (Intel HD Graphics 3000)
  • Built in speakers and headphone jack both work
  • Built-in mic and web-cam both work - I used skype and google hangouts and both worked flawlessly.
  • wireless worked with my open network connection (I haven't yet tried it on secure networks)
  • Bay battery seems to work.

Not Working:

  • Audio output on docking station
  • Dual Displays sometimes reset to showing the same image on both rather than two seperate displays. This has always been fixed by reseting the settings in the Monitor configuration page.

I am impressed with how flawless the install was. I was dreading it because last time I did this on my last laptop 4 years ago, I spent a few hours getting everything in working order. So far I have not yet had to do any custom installation. Everything that I needed working, worked out of the box!

Let me know if you want me to test anything out and I'll try if I can.

]]>
http://dwiel.net/blog/ubuntu-11-04-on-thinkpad-t420s/feed/ 14
python onexit http://dwiel.net/blog/python-onexit/ http://dwiel.net/blog/python-onexit/#comments Fri, 15 Jul 2011 22:39:28 +0000 dwiel http://dwiel.net/?p=313 Was looking for python's equivalent to onexit and found this:

import atexit
atexit.register(function_that_will_be_called_before_this_program_exits)
]]>
http://dwiel.net/blog/python-onexit/feed/ 0
web.py: error: No socket could be created http://dwiel.net/blog/web-py-error-no-socket-could-be-created/ http://dwiel.net/blog/web-py-error-no-socket-could-be-created/#comments Thu, 14 Jul 2011 16:40:06 +0000 dwiel http://dwiel.net/?p=307 This error message most often occurrs when trying to run web.py on an invalid address and port. An example of an invalid address would be example.net, instead of a proper ip address like 98.228.37.242.

Other Causes:

Was just trying to get a simple web.py test running:

import web
 
urls = (
  '/x', 'X',
)
 
class X :
  def GET(self) :
    return 'x'
 
app = web.application(urls, globals())
app.run()

but I kept getting the error:

error: No socket could be created

The problem was that due to the way web.py loading works, you need to have the creation and running of the app only occur if this is the main entry point of the program. Otherwise, the class loader in web.py will reload this file again later, and wind up spawning a new server when its intent was simply to load a class:

if __name__ == '__main__' :
  app = web.application(urls, globals())
  app.run()
]]>
http://dwiel.net/blog/web-py-error-no-socket-could-be-created/feed/ 3
python random timezone http://dwiel.net/blog/python-random-timezone/ http://dwiel.net/blog/python-random-timezone/#comments Tue, 12 Jul 2011 01:44:46 +0000 dwiel http://dwiel.net/?p=302   import random import pytz   pytz.timezone(random.choice(pytz.all_timezones))   ]]> http://dwiel.net/blog/python-random-timezone/feed/ 0 python-memcache is thread safe http://dwiel.net/blog/python-memcache-is-thread-safe/ http://dwiel.net/blog/python-memcache-is-thread-safe/#comments Thu, 30 Jun 2011 05:53:34 +0000 dwiel http://dwiel.net/?p=296 python-memcache is a thread safe library. In memcache.py, which is the single source file, you'll find:

 
try:
    # Only exists in Python 2.4+
    from threading import local
except ImportError:
    # TODO:  add the pure-python local implementation
    class local(object):
        pass
class Client(local):
  ...
 

Which means that all data accessed through self.variable_name have values which are thread specific (as long as you are running python version 2.4 or higher.) Very cool. Before I looked at the code, I wrote some multi-threaded tests to check and see if anything fishy would happen. I'd say looking at the code is a better solution.

more details threading.local

]]>
http://dwiel.net/blog/python-memcache-is-thread-safe/feed/ 0
PiCloud Simulation: OSError: [errno 13] permission denied http://dwiel.net/blog/picloud-simulation-oserror-errno-13-permission-denied/ http://dwiel.net/blog/picloud-simulation-oserror-errno-13-permission-denied/#comments Wed, 22 Jun 2011 04:06:58 +0000 dwiel http://dwiel.net/?p=286 I tried running a PiCloud simulation on Ubuntu 10.04 on linode and got the following error:

OSError: [errno 13] permission denied

I found the solution here:

add the following line to your fstab and reboot:

none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0

If you don't want to reboot, a temporary fix might be:

sudo chgrp $GROUP /dev/shm
sudo chmod g+w /dev/shm

That last part might not be the best way to do it, but it worked for me.

]]>
http://dwiel.net/blog/picloud-simulation-oserror-errno-13-permission-denied/feed/ 0
python: parsing the output of datetime.isoformat() http://dwiel.net/blog/python-parsing-the-output-of-datetime-isoformat/ http://dwiel.net/blog/python-parsing-the-output-of-datetime-isoformat/#comments Tue, 21 Jun 2011 19:12:02 +0000 dwiel http://dwiel.net/?p=280 I couldn't find this explicitly anywhere, so here it is. A function to parse a string which was generated by datetime.isoformat()

import datetime
 
def parse_iso_datetime(str) :
  # parse a datetime generated by datetime.isoformat()
  try :
    return datetime.datetime.strptime(str, "%Y-%m-%dT%H:%M:%S")
  except ValueError :
    return datetime.datetime.strptime(str, "%Y-%m-%dT%H:%M:%S.%f")
 
# and a simple test case
def test() :
  d = datetime.datetime.now()
  assert parse_iso_datetime(d.isoformat()) == d
  d = datetime.datetime.now().replace(microsecond = 0)
  assert parse_iso_datetime(d.isoformat()) == d
 
]]>
http://dwiel.net/blog/python-parsing-the-output-of-datetime-isoformat/feed/ 0
TP-Link TL-WN722N on Ubuntu 10.04 http://dwiel.net/blog/tp-link-tl-wn722n-on-ubuntu-10-04/ http://dwiel.net/blog/tp-link-tl-wn722n-on-ubuntu-10-04/#comments Fri, 13 May 2011 17:02:38 +0000 dwiel http://dwiel.net/?p=267 Note: according this guy this set of steps also works for Fedora 15.

I had a lot of trouble getting this card to work. Here is how I finally got it.

I am running 2.6.32-30-generic-pae #59-Ubuntu SMP
running "lsusb" shows the following line for my device: 0cf3:9271 Atheros Communications, Inc.

I tried a bunch of different compat-wireless versions and this one finally did it. At the time, it was the latest stable release. The daily snapshots were causing kernel panics ... Download it, decompress it and build it:


$ tar xvf compat-wireless-2.6.38.2-2.tar.bz2
$ cd compat-wireless-2.6.38.2-2
$ ./scripts/driver-select ath9k_htc
$ sudo make
$ sudo make install

I had to download version 1.2 of htc_9271.fw the firmware from here and copied the file to /lib/firmware.

I was getting wlan%d instead of something reasonable like wlan0. Running sudo ifconfig wlan%d showed me the mac address which I could use to add an entry to /etc/udev/rules.d/70-persistent-net.rules. Heres the entry I added: (note that the browser adds newlines here, but you should add just two lines: one for the comment, and one for the rule)


# USB device 0x0cf3:0x9271 (usb)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="54:e6:fc:94:91:35", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan2"

reload the drivers by running:

sudo modprobe ath9k_htc

Now plug in the device. There were a lot of other steps that I followed while trying to get this to work, so I may have left something out.

]]>
http://dwiel.net/blog/tp-link-tl-wn722n-on-ubuntu-10-04/feed/ 21