Dalla Rosa

3 notes &

Short Post: Writing cross-platform code in Go

Lately I’ve been working on this little project in Go that involves system calls and some other more low level features of the OS. The project is supposed to support both Linux and Mac OSX / BSD so I was wondering how to separate code for those platforms. I found the answer in the Go source: Just name the files according to the target platform!

Example: 

Let’s say we have a project called “Platform Test” and we create the folder platform_test for it. In that folder you’ll have the following files

test_darwin.go

package main
import "fmt" func main() {
fmt.Println("I'm on mac")
}

and

test_linux.go

package main
import "fmt"
func main() {
fmt.Println("I'm on linux")
}

Now, if you run 

go build

in platform_test from your mac, you’ll have an executable called “platform_test” that prints

I’m on mac

and 

I’m on linux

if compiled on  a linux machine

I gotta say, this was a pretty neat way to implement cross-platform support.

Filed under go golang tech cross-platform

0 notes &

Tokyo Golang Developers

Missing some real world community around the Go language in Tokyo, I’ve decided to create the Tokyo Golang Developers meetup. It is a meetup for anyone with interest in the go programming language, be it a super hacker or complete beginner. We’re having (hopefully) our first meetup on the 28th in Shibuya and welcome all of you Tokyo gophers!

Filed under golang go programming tech

0 notes &

greeboslav-deactivated20140413 asked: Hello. I saw your post about slackware on zenbook 3 months ago. I am currently thinking about buying it for usage with some GNU Linux distro so I want to ask a few questions. Do you have any unresolved problems on it? Does it need any non-free software/firmware/drivers to work properly? Is battery life good? Also I saw a post on 4chan/g/ a few days ago where someone said that he was using slackware on this zenbook. Could that be you?

Hey!

 Do you have any unresolved problems on it?>

Actually I do. I still have to write about it but it was kind of painful to get UEFI to work properly and even now I still have a kind of weird boot flow.

Another thing is the Ambient Light Sensor. The asus driver doesn’t know how to handle it and keeps sending nulls to the standard output. It doesn’t really affect most applications but you might notice some weird stuff (Google Drive shows the help dialog for no reason, vim leaving insert mode for no reason). Anyways, you can solve that by putting a piece of tape on the sensor :p My goal for the end of the year holidays is to do something about that driver. 

Does it need any non-free software/firmware/drivers to work properly?>

For the touchscreen, I had to find the maker’s page and download their software: http://home.eeti.com.tw/DriverDownload.html

Is battery life good?>

Battery life is great. I make between 7.5 to 8 hours depending on what I’m doing.

Could that be you?>

I don’t really use 4chan so it wasn’t me. I actually had a guy on my blog asking for a write up on the UEFI and all other problems so it could be him :)

0 notes &

Bluetooth headset on Linux

One of the Holy Grails for electronic device users is eliminating cables and cords. We first started with remote controls, infrared based mouses, wireless and bluetooth devices.

Even though past are the days when it was difficult to connect to wireless or transfer files to/from your pc using bluetooth, a topic that remains full of mistery and problems is bluetooth audio. 

I bought my first bluetooth headset a few years ago and I tried to connect it to my Slackware notebook and I obviously failed miserably.

After many years I decided to buy a HiFi Wireless Headset, something that would allow to both listen to music and take calls with fair quality. After looking around for a while, I decided to with a friends recommendation and bought a Sony Ericcson MW600/B Wireless headsetimage.

Taking a few lines to talk about the device itself, I just love it. The sound quality for both playing music and calling is great, plus the fact that the earphones are not built-in in the device so if you have a more expensive and higher quality pair of earphones you can use those. The battery life is also great. Sony claims that it can do around 8.5 hours of music playback and I can back that. I can leave to work at 10am today with a full charge, spend a big part of my day listening to music and they’ll only die on me the next day if I don’t charge them during the night. Charging only takes around 2.5 hours. Also it can pair with up to 3 devices (it can connect to up to 2 devices at the same time - one in headset mode and the other  in playback mode)

OK! Let’s get over with the digression and back to the main thing of this post, which is talking about how to get this thing working on your Linux machine.

If you have a fairly new distribution running you won’t have problems pairing your device. Just put and pairing mode and let your Bluetooth manager to the rest. 

On KDE, just Alt+F2 to open the “Run Command” dialog and type Bluetooth Devices (probably bluetooth will be enough)

image

Use the “search” and “setup” buttons to properly setup your device. I guess you want to use it to listen to audio so much make sure to set it up as a “A2DP Sink (Send audio)” (in some places it might be written as “Audio Sink”).

Ok! After doing that your device is properly connected to your machine and ready to play some music! Then you try it….just to see it fail. What do you have to do? 

Actually we’ve already had to deal with the something similar when we fixed the problems with HDMI audio

We need to let ALSA know that the bluetooth device is there and can be used (or in case you want to, you make it the default device). Let’s see how we do that. 

As root, open the file /etc/asound.conf and add the following lines

What you’re doing is, first adding a control device of the type bluetooth and a pcm device. That should already be enough for you to be able to choose the headset (it will be called “btheadset”) to be the playback device.

Lastly, like with HDMI, applications like Chrome and the Flash Player, they will use the default pcm device so you’ll have to change that too:

pcm.!default {
type plug
slave.pcm “btheadset”
}

The lines above go into the .asoundrc, in your home directory. (Check the HDMI article for more details)

Filed under bluetooth linux slackware tech audio

0 notes &

Tokyo Android Developers

It’s been a while since my last post but today I’m here to do some advertising!

Since July I’ve taken over the Tokyo Android Developers meetup and I’d like to invite of all you who are in the Tokyo area and are interest in Android development to show up if you can!

Our next meetup will be on the 29th of October with a talk by me about the basics of Android development, and a talk about how to develop Android apps using Scala, by Devon Stewart, the guy behind the Tokyo Scala Meetup 

Hope to see you there!

Filed under android meetup tech scala october

0 notes &

RPM Packages: Compilation flags

Since October last year I took over the server management tasks in my project. Unfortunately, those machines are loaded not with Debian but with Scientific Linux (Why SL is one of the great mysteries of universe). 

One of these days I needed to know which were the compilation flags of a package. 

TL;DR:

rpm -q --queryformat="%{NAME}: %{OPTFLAGS}\n" PACKAGE_NAME

Long Version:

-q or —query is the flag for querying information about a package.

—queryformat is quite obvious but here it is: use this flag to set the the output format of the query result.

A bit more on —queryformat:

According to the docs:

Query formats are modifed versions of the standard printf(3) formatting.

Ok, how can I get a list of the information I can output?

Again, from the docs:

rpm will print a list of all of the tags it knows about when it is invoked with the —querytags argument.

Kinda weird to be writing about RPM based distributions but oh well, at least I’m not managing Windows servers ;)

Filed under centos linux rpm tech server

1 note &

Exchanging your notebook LCD screen in Japan

This is the second time I break the screen of a notebook.

First time was with this this Asus Eee PC 1000HE I had for a 1 year and a half. The little boy was on beside my bed and so it had an encounter with my foot, long enough just to crack the LCD screen. The second time was a few weeks ago. I was doing some work on the bed before sleeping but I actually fell asleep. The notebook just fell. Here I am again with a broken LCD screen.

The first time I really had no idea of where to buy a new screen, so I just went around the web looking for some japanese site that seemed reliable enough and that was selling notebook LCD screens. The search took a few days but I ended finding 液晶プロ(Ekishou Pro - “LCD Pro”).

They specialize on replacement LCD screens for notebooks and have a pretty nice line up, covering most brands like Asus, Dell and even Apple.

The looks of the website don’t really help but my first buying went really smooth. The screen for my notebook was listed as in “contact us” so I sent them an email which was quickly replied by their staff with a link to the an available screen, compatible with my model. Payment can be done through credit card or bank transfer. 

The LCD arrived in a few days and worked all pretty well.

So, this time when I got yet another screen broken it was a no brainer. Just went to Ekishou Pro and looked up my model (Dell Inspiron 1122 - or M102z) and quickly found it around the Dell, 11.6 inches category.

Can’t wait for it to arrive soon and get my machine back!

Filed under lcd ekishoupro tech dell apple asus inspiron eeepc

0 notes &

Dynamically adding attribute accessors in Ruby

A simple way for adding attribute accessors to a class dynamically:

class MyClass
  def add_attr(name, value)
    self.class.send(:attr_accessor, name)
    instance_variable_set("@#{name}", value)
  end
end
just call the add_attr method passing the name of the accessor (as a string) and a value that will be assigned to the variable.
You can also turn this in to a module so that you can easily add the functionality to all your classes.
I’m actually using this in a script I made to easily change data in long csv files.
I wanted to be able to convert CSV files into Ruby objects before changing the data, even if the fields change from file to change.
I know some people are gonna say “just use an existing gem or so”, but this is being fun.

Filed under tech ruby programming accessors