Disabling an nvidia graphics card with bbswitch on Fedora


bbswitch is a kernel module which automatically detects the required ACPI calls for two kinds of Optimus laptops. It has been verified to work with “real” Optimus and “legacy” Optimus laptops.

kernel-headers and kernel-devel are needed to install bbswitch with dkms. Now, installing with dkms ensures that bbswitch is going to survive future kernel upgrades.

sudo yum install kernel-headers kernel-devel dkms

Download the latest stable version of bbswitch, extract, and install with dkms.

wget https://github.com/downloads/Bumblebee-Project/bbswitch/bbswitch-0.5.tar.gz
tar -xf bbswitch-0.5.tar.gz
cd bbswitch-0.5
sudo make -f Makefile.dkms

The nouveau driver needs to be unloaded before bbswitch can be loaded. If nouveau driver is being used somewhere, then the way around is to blacklist nouveau, and rebuild initramfs.

A simple lsmod can reveal if nouveau driver is being used:

lsmod | grep nouveau

You can also try unloading nouveau:

sudo modprobe -r nouveau

If the above fails, we are heading over to blacklisting nouveau and rebuilding initramfs.

su -c "echo 'blacklist nouveau' >> /etc/modprobe.d/disable-nouveau.conf"
sudo mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img
sudo dracut --omit-drivers nouveau /boot/initramfs-$(uname -r).img $(uname -r)

If all goes well, reboot.

Nouveau driver can now be easily removed and bbswitch can be loaded once the system has restarted.

sudo modprobe -r nouveau
sudo modprobe bbswitch

Once, bbswitch is loaded, disabling and enabling the graphics card is just a walk in the park:

sudo tee /proc/acpi/bbswitch <<< OFF    # disable
sudo tee /proc/acpi/bbswitch <<< ON     # enable

Verifying the status of the card is as easy as:

cat /proc/acpi/bbswitch

Native apps using web technologies with Node-Webkit


node-webkit allows you to design and implement desktop applications using web technologies. Everything runs on the client side, and is backed up by node.js. It offers the perfect combo to build native apps using node.js + HTML.

node-webkit is an app runtime based on Chromium and node.js. You can write native apps in HTML and JavaScript with node-webkit. It also lets you call Node.js modules directly from the DOM and enables a new way of writing native applications with all Web technologies.

It’s created and developed in the Intel Open Source Technology Center.

node-webkit can be downloaded from here.

Setting the node-webkit command:

alias nw='path/to/node-webkit/executable'

node-webkit also  comes with the browser restrictions removed, so it perfectly adapts to native app development.

App creation:

A package.json and an index.html are the minimum requirements to create an app. An example package.json would look like:

"name": "MyApp",
"main": "index.html",
"author": "Souradeep De",
"email": "souradeep.2011@gmail.com",
"window": {
"toolbar": false,
"width": 1000,
"height": 600,
"min_width": 500,
"min_height": 300

view raw


hosted with ❤ by GitHub


Packaging the app is even simpler. We only need to create a zip archive, and change its extension to “.nw”.  This archive can then be exectued with the node-webkit command.

Or, the app can also be provided as a stand-alone one, users don’t need  to download node-webkit separately to run the app, making it easy for all kinds of end users. More information here.

Realtiming with Flask-socketIO


Small, realtimed applications are just beautiful. One can think of an idea, and implement it in no time, and still have a very lively app. I was searching for realtime possibilities which can couple up with Flask, and found a pretty decent solution, a Flask extension, Flask-socketIO.

In a nutshell, socketio is a nodejs realtime app framework, which allows realtimed bidirectional communication.

Since we are using Flask (python), and socketio is written in JavaScript, Flask-socketIO is in turn dependent on gevent-socketio.

On to the code, we need the following pythonic requirements:

  1. gevent-socketio
  2. flask
  3. Flask-socketIO
  4. gevent-websocket

Flask-socketIO makes it very simple to implement event based communication.

Here is a sample server code:

from gevent import monkey
from flask import Flask, render_template
from flask.ext.socketio import SocketIO, emit
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
def index():
return render_template('index.html')
def channel_a(message):
Receives a message, on `channel-a`, and emits to the same channel.
print "[x] Received\t: ", message
server_message = "Hi Client, I am the Server."
emit("channel-a", server_message)
print "[x] Sent\t: ", server_message
def say_hello_world():
Another way of emitting messages, when event based communication is
not possible
hello_message = "Hello World!"
socketio.emit("channel-a", hello_message)
print "[x] Sent\t: ", hello_message
if __name__ == '__main__':
app.debug = True
socketio.run(app, port=3000)

view raw


hosted with ❤ by GitHub

And this is the client JavaScript (Socket.IO required):

WEB_SOCKET_SWF_LOCATION = "/static/WebSocketMain.swf";
socket = io.connect('http://&#39; + document.domain + ':' + location.port);
var client_message = "This is a client, I am attemping to communicate";
socket.emit("channel-a", client_message);
console.log("[x] Sent : " + client_message);
socket.on('channel-a', function(message) {
console.log("[x] Received : " + message);

view raw


hosted with ❤ by GitHub

Messages in server logs:

Screenshot from 2014-12-20 23:01:17

Messages in client JavaScript console:

Screenshot from 2014-12-20 23:01:14

This example is extremely simple, and I hope is self-explanatory. The Flask-SocketIO provides a lot more than this, here are the links to the Flask-SocketIO documentation and this example’s source.

Another project of mine, “CodeCast“, has a  more practical implementation of Flask-socketIO, which might provide a better understanding of the scenario.