Using Luxafor with Linux

Luxafor makes a nice busy status indicator light for the office. Unfortunately it only provides software for Windows and Mac. But it’s not hard at all to get it working on Ubuntu with PyUSB.

1- You need PyUSB installed

pip install pyusb

2- PyUSB basically lets you do anything you want with the USB device including some pretty dangerous stuff so it’s naturally open to super users. It’d be really annoying to have to sudo every light control though, so we’ll open this one particular device to your user. Create a luxafor.rules file in /etc/udev/rules.d/ and put in:

SUBSYSTEM=="usb", ATTR{idVendor}=="04d8", ATTR{idProduct}=="f372" MODE="0664", OWNER="[your user name]"

Read More…

Call jQuery Functions from Dart

The standard documentation for Dart and JavaScript interoperability isn’t great. It refers to the ‘dart:js’ library which although works is a bit verbose to get things done.

For instance, to call a jQuery function, you would need

import 'dart:js';
 
...
context.callMethod(r'$', ['.some.class.selector']).callMethod('someFunction');
...

The dart team has since then released the js package with which you can simply call

import 'package:js/js.dart';
 
...
context.$('.some.class.selector').someFunction();
...

Basically native syntax. Of course you have to add it to the yaml and pub get again.

Moving Between Directory History in Fish Shell

Fish shell is supreme! Finally a shell whose config doesn’t look like a Perl hack. Too bad it doesn’t get much publicity.

Here’s an awesome feature. In zsh, I’d be used to doing stuff like

dirs -v
cd -2

to move between previous directories. In fish, there’s a cd – to move to the previous history but much more powerfully, you can just do alt-left/right arrow to move through your entire directory history without typing anything.

It’s boss!

Functional Programming Example in Dart

For a quick reference.

At the time of writing (Feb 2014), the top results from a Google search on ‘Dart functional programming’ or ‘Dart list comprehension’ don’t immediately yield clear examples. That’s crazy given that Dart is such a boss language. So here’s an example:

// double all values
List myList = [1, 2, 3, 4];
List doubledList = myList.map((x) => x * 2);

You can do the standard map, reduce, filter on Iterables on Dart. Of course you can chain them up like other languages. Although it’s not strictly using the set building notation like in Python, you can still pretty much do everything so something like:

[x * 2 for x in myList if x % 2 == 0]

in Python would look like:

myList.where((x) => x % 2 == 0).map((x) => x * 2);

Iterating Python Lists 2 by 2

Not necessarily the most superior way performance/Pythonicity wise but it’s simple to remember and short:

list = [1, 2, 3, 4, 5, 6, ...]
pairs = zip(list[::2], list[1::2])
for pair in pairs:
    # do stuff

pair will be (1, 2), (3, 4) etc.
The 2 list slices turn the original into odd/even sets and zip merges them

Alternative to HttpClient for Windows Phone 7.5

If you wanted to move your WinRT project to support Windows Phone 7.5, you’ll rejoice at the recent news that Microsoft’s Microsoft.bcl.Async package in Nuget that allows using Async keywords and Task class but in the end, you really used them in WinRT because HttpClient class had a GetAsync method which is not available outside WinRT.

Worry not, the Microsoft.bcl.Async package comes with a Microsoft.Threading.Tasks.Extensions assembly that if you look inside, includes:

public static System.Threading.Tasks.Task<webresponse>GetResponseAsync(this System.Net.WebRequest source)
Member of AsyncExtensions</webresponse>

Which means you can use System.Net.WebRequest in its place and it supports Task/Async.

So you can do something like:

WebRequest request = WebRequest.Create(uri);
await request.GetResponseAsync();

How to Debug/Deploy WinRT/Windows 8 App to ARM Tablet

You’ve now made your app and tested it on desktop and want to use the same code for your developer unlocked the tablet. Until there’s an ARM version of Visual Studio, here’s what you can do. The basic process would be to set up a Remote Debugger service on your tablet and from a desktop on the same subnet, run on it directly. This assumes you have a development tablet device and a desktop running the same user (who also has admin rights) Read More…

Sharing to Facebook/Twitter from Windows 8/WinRT App

Sharing on “Metro style”/”Windows Store” app is a bit different from what we used to. Instead of invoking it directly in code, Microsoft encourages us to use the centralised “charm” bar where we would then implement a page event handler to fill in details to share.

To personalise share details, we would fill a DataPackage that would then be used across various media such as email or message or other apps. Read More…

Django ModelForm Required ForeignKey not Connecting?

You have a ModelForm based on a Model with a non-optional ForeignKey field. You already connected it via something like

instance = SomeClass(someRelatedObject = someObject)
form = SomeForm(request.POST, instance = instance)

but form.is_valid() is still giving you an error saying someRelatedObject can’t be null. One possible solution is to check your SomeClass’s definition of someRelatedObject. Try putting ‘editable = False’ in your ForeignKey constructor and it may solve your problem.

No Chinese Fonts on XBMC Eden 11.0

Simple solution. Many posts online points to replacing fonts etc but with Eden, the included Arial has unicode support. You just had a shitty theme with custom non-unicode font. Just go to the skinning section of your theme (skins can change the hierarchy) and change the font from default to Arial. Easy!

Solve XBMC Tearing on Ubuntu 12.04

Definitely not an exhaustive fix but did fix it for me on a Zotac ID80 with Nvidia GT 520m. Disable composite with

sudo nvidia-xconfig --no-composite

It’s a very obscure note on the XBMC’s unreachable wiki. It mentions that XBMC is not compatible with Compiz and has a link to a german site that among other things, has the code above. It works.

Django Development Server with HTTPS

Sometimes you can’t avoid using HTTPS right starting from development (such as for developing Facebook canvas applications). You can setup Apache on your local machine and go through a bunch of trouble setting up your domain and setting up the certificate etc but there’s an easy way of using Django’s python manage.py runserver to work with HTTPS.

This can be done with stunnel that lets the Facebook server and stunnel on your machine communicate in SSL and stunnel turns around to communicate with Python in HTTP. First install stunnel. For instance in Mac OS X:

brew install stunnel

Read More…

1 2 3 6  Scroll to top