The place for tech

The place for simple tutorials, software reviews, and many things tech.

Friday, July 1, 2016

How to Fix: No Audio with a bluetooth headset in Linux

Hopefully I can help some of your with this problem that I had a few months ago. Here was the scenario: everything seemingly worked fine with my bluetooth headset. It connected, played music flawlessly and everything on first connect... but as soon as I rebooted the headphones, nothing.

They still connected as a media device. The volume control on the computer still worked. But no sound at all would transfer between my computer and the headphones. Weird.

First Things First
Let's make sure they're configured in the first place. Consult your manual on how to sync your device. Then, from your desktop environment's settings (if you're not using a Desktop Environment, check out blueman), click "Bluetooth"

It should say "Connected". This is a sign that the bluetooth device is properly connecting to your Linux box, but not that audio is properly being transmitted. 

A Lesson in Linux Audio
Linux Audio is notirously painful to configure. There are 3 sound systems that distributions tend to use. These are Alsa, PulseAudio, and OSS, which really isn't used all that much.

How To fix
Okay, so now you have to install a package called pavucontrol, which is short for Pulse Audio Volume Control. It's not installed by default on most Linux distributions because it provides some more advances facilities for managing your audio. Once it's installed, run "pavucontrol" from a terminal to open it.

First, make sure that the audio isn't muted on your headset here (either on the bar or the speaker mute button). You should have your channels locked together, and it should be a fallback. Now, if all of this is set up (it was for me), there is one last step you need to do to fix your audio.

In the "configuration" tab at the top, go down to your headset. As misleading as it is, change your headset from either "Off" or "Headset head unit" to "High Fidelity Playback (A2DP Sink)"
Now, after changing that, you should be good to go. If you're not, there is one last thing you can try.

Install alsamixer if you don't already have it and run it in a terminal. If you see "MM" at the bottom, hit "M" to unmute that channel, and use the up arrow to turn the volume of it all the way to 100%. If it's possibly reading your sound card wrong, you can use "F6" here to change that.

Good luck. Audio issues are a true pain to work through, and are seemingly impossible to fix. Hopefully these steps solve your audio problems as they did mine.

Installing Minecraft in Fedora 23 and 24

Minecraft on Fedora can be a bit of a pain. You may even have experience working with .jar files, download Minecraft, and it still doesn't work! This post will explain why that is, and how to get the game installed on your computer. You'll be minin' and craftin' before you know it.

Installing Minecraft is as easy as these steps:

  • Download Minecraft
  • Install Java
  • Run
and has one optional step that I highly recommend

  • Create a Desktop file

I've tried to put together a small script to do this for you. If it doesn't work, then follow along with the steps below and tell me which part is giving you trouble:

x86: wget "" -O ~/Downloads/Minecraft.jar; wget "" -O ~/Downloads/jre.rpm; sudo dnf install ~/Downloads/jre.rpm; wget "" -O ~/Downloads/Minecraft.desktop; sudo cp ~/Downloads/Minecraft.desktop /usr/share/applications/;wget "" -O ~/Downloads/minecraft.png

x86_64: wget "" -O ~/Downloads/Minecraft.jar; wget "" -O ~/Downloads/jre.rpm; sudo dnf install ~/Downloads/jre.rpm; wget "" -O ~/Downloads/Minecraft.desktop; sudo cp ~/Downloads/Minecraft.desktop /usr/share/applications/; wget "" -O ~/Downloads/minecraft.png

After using these scripts, you should be able to play Minecraft by typing:

cd /usr/java/jre*; bin/java -jar ~/Downloads/Minecraft.jar 

at the terminal, or by rebooting and selecting "Minecraft" from your applications menu.

Download Minecraft
This is probably the easiest step. Assuming you already have a Minecraft account, you can just download the game to get started with this command:

wget "" -O ~/Downloads/Minecraft.jar
This will put Minecraft inside of your "Downloads" folder in your home directory.

Download and Install Java
Thankfully, because you run Fedora, Java provides a .rpm file for their JRE. This makes the installation far easier.

Also note that we must install Oracle's propriety JRE in order to run Minecraft, as there is (at least at the time of writing) an incompatbility between swing on OpenJDK and the official JDK.

x86 (32-bit) system users can download their rpm from this link.
x86_64 (64-bit) system users can download their rpm from this link.

By downloading either file you are accepting Oracle's license. If those links don't work or are outdated, visit the website directly here:

Find where Java was Installed and Run Minecraft
The .rpm will automatically install Java. But... where. If you tried to do "java -jar Minecraft.jar" right now it would fail still, because it's still using the OpenJDK version of java. In order to launch Minecraft, you have to do this:

cd /usr/java/jre*; bin/java -jar ~/Downloads/Minecraft.jar 

because Java is installed in /usr/java/ in a directory name that corresponds to its version, which is bound to change. If you're comfortable with leaving it at this, you can. However, having to use that command every time you want to play Minecraft is a bit cumbersome, so we're going to make a .desktop file to do it.

Make the Desktop File
.desktop files are what control launching desktop applications on Linux. When you see "Files" and a picture of a filing cabinet that launches nautilus, for instance, that's the result of a Desktop File. We can make our own desktop file to launch Minecraft with that code above. One caveat is that Desktop files aren't run like normal terminal commands, so we have to give our command up there a shell, since it has it change its working directory.

The content of the Minecraft.desktop file should be as follows: 

#!/usr/bin/env xdg-open

[Desktop Entry]
Exec=bash -c "cd /usr/java/jre*; bin/java -jar ~/Downloads/Minecraft.jar"


which you can write in almost any text editor. This expects there to be an icon for Minecraft in your Downloads folder, but it will launch the game even if there's not.

Great! Now...

Install the Desktop File
Move the file into /usr/share/Applications/. This will install the Minecraft launcher system-wide. It may take a reboot for this to actually work.

And you're ready to roll! Have fun

How To: Set up timestamps in Emacs Documents

This will be a pretty straightforward how-to guide on how to implement timestamping in Emacs. This will insert the time directly into the document, under the cursor, so if you want something fancier than unfortunately the GNU Emacs Documentation will have to hold you over.

The Command
The command to actually insert the time into the document is this:

(insert (current-time-string))

The Keybind
Now, if it doesn't exactly sound like your cup of tea to have to copy-and-paste that Lisp command every time you want to insert the timestamp, open up your .emacs file (or wherever you store your Emacs configuration file. If you don't have one, you can just create a file called ".emacs" in your home directory).

Insert this line:

(global-set-key (kbd "C-c C-c") (lambda () (interactive) (insert (current-time-string)))

This tells Emacs that whenever you press Control-C, Control-C, it should insert the default time string (which looks like: 

Fri Jul  1 10:57:35 2016

Note the (lambda (interactive()). This is only required because global-set-key expects interactive commands.

Modifying the Time
Obviously, having a string that long doesn't work for everybody. Maybe you don't want the day of the week to show, or you only care about the year, etc. Luckily, Emacs comes with a command called format-time-string which allows us to control what kind of format the date will be output as. So, let's change up that (current-time-string)!

(global-set-key (kbd "C-c C-c") (lambda () (interactive) (insert (format-time-string "%I:%M:%S%p"))))

This will give you just the 12-hour time (i.e "10:57:35pm"). To see a list of all the options you can use with format-time-string, either run man strftime (on linux) or go to The GNU Documentation on the function.

Only in Certain Modes
Now, in my case, I only want time-stamping to be enabled when I'm in Markdown Mode. The code (still using the 12-hour time format) would be this:

(add-hook 'markdown-mode-hook (global-set-key (kbd "C-c C-c") (lambda () (interactive) (insert (format-time-string "%I:%M:%S%p")))))

There are a ton of hooks out of the box, and even more in the thousands of MELPA packages, so you can modify 'markdown-mode-hook to be anything.

Thursday, June 30, 2016

Deploying a ASP.NET MVC Application on Mono

Ever tried to deploy an ASP.NET MVC application before? Well, it's the bee's knees... on Windows, where most Visual Studio project types are first class citizens of the ecosystem (sorry, F#). However, things get a tad trickier on Linux / Mono, so let's run through the very basics of setting up an environment like this.

This post will not cover advanced topics, such as setting up an SSL certificate or linking with a database. It will just get the barebones ASP.NET server deployed. Note, however, that there are better ways to deploy an ASP.NET MVC service than what this post describes (through fastcgi or mod_mono), so if you're concerned about the RIGHT way of doing things rather than the FAST way of doing things, follow that link.

Structure - Skip if you have a project
Let's make ourselves an ASP.NET MVC application in Monodevelop. If you don't already have monodevelop, you'll need to install the following packages:

  • monodevelop
  • xsp
  • mono-devel
from your distribution's repository. If some of those aren't found, it may be okay, as both tend to be bundled with monodevelop itself. Now, make an ASP.NET MVC project with Razor

this should create an ASP.NET MVC project that's ready for deploying.

Now, it's time to compile the project. This is where a program from mono-devel comes into play. xbuild, an implementation of msbuild (link)  is what will generate what the web server runs. The binaries are generated from the .sln or .csproj file itself.

So, open up a terminal and go to the project root, where your project file is.
Then issue the "xbuild" command on your file. This will build all targets for the project, which are Debug and Release by default in Monodevelop

xbuild {file.sln}

Wonderful! If everything in your project passes, you have successfully built your ASP.NET MVC application

Now, here are where the tough decisions are made. If you are truly deploying a production service, you should do the following things:

  • Secure a webserver, preferably a dedicated virtual machine
  • Generate SSL certificates / other cryptographic keys
  • Create a user for running your service
  • Install the fastcgi-mono or mod_mono (apache) modules and run your service from Apache

However, the quick-n'-dirty way I do it is with xsp4. xsp is yet another pet project of Mono's, that aims to be a fast ASP.NET web server for development. However, there is nothing that says you can't use it in production. It allows SSL certificates, variable ports, etc. so you won't find yourself missing too many features from Apache.

Running xsp4 is dead simple. Go to the build directory (the one under your project root) and run "

xsp4 --port 80"

if all goes well with this, you should have a full-fledged ASP.NET MVC 4 application deployed under Linux, and available on the standard http port. This is, of course, the unsecure, bare-bones deployment with xsp4. But it's a good starting point. To find out how to make xsp4 handle errors, set up your certificates, etc. issue the command 

xsp4 --help

Hope you found this useful!

Wednesday, June 29, 2016

Using SQLite server with C# / Mono on Linux

If you've arrived on this post, it means that you're using Mono on Linux and attempting to use SQLite, and having a bit of difficulty. That's understandable. This is not a tutorial on SQL / Mono / Entity or anything of the sort. This will get a barebones implementation of a server working with mono.

The Problem
The problem is that Mono comes with Mono.Data.Sqlite. Yet, if you're looking for information on using SQLite in C#, you will be directed to use System.Data.Sqlite, which is included in the nuget library. You can add this using Xamarin's tools successfully. Intellisense should work, and most functions in System.Data.Sqlite should work as well... except for one: SQLiteConnection, which is used to connect to the database.

I'm not 100% positive on the nature of the problem, as it stands, in mono right now. I can narrow it down to (at least in my case) some kerfuffle regarding sqlite.interop.dll not playing nicely with my architecture of choice (x86_64).

The Fix
The best fix for this is to... use Mono.Data.Sqlite. However, this has some downsides.
  • Using a Mono library breaks compatibility with .NET... ouch.
  • Mono.Data.Sqlite, for whatever reason, is not a drop-in replacement of System.Data.Sqlite.
with these things in mind, let's do it.

using System;
using Mono.Data.Sqlite;
namespace SQLITETEST {
  class MainClass {
    SqliteConnection db = new SqliteConnection("Data Source={filename.sqlite};Version=3;");
    SqliteDataReader reader = new SqliteCommand("SELECT x FROM y WHERE z = zz;", db).ExecuteReader();
    while (reader.Read()) { Console.WriteLine(reader.GetString(0));}

and there you go. This code will connect to a database {filename}, run a query, and return the results. If you have experience with System.Data.Sqlite, you should notice that the SYNTAX of Mono.Data.Sqlite doesn't differ from it too much... but the spelling does. System.Data.Sqlite prefers to use classes spelled as "SQLiteDataReader, SQLiteConnection", etc. while Mono uses "SqliteDataReader"... 

While this seemingly unnecessary difference is annoying, it's negligible. Enjoy kludging through Sqlite and Mono further!

Saturday, June 28, 2014

Rust note 6: Checking to see if a file exists in Rust

Today, I, a beginner who has used Rust for less than a week, patched a bug in the rust compiler. It had to do with overwriting existing files, and it lead to the creation of this function:

use std::path;
fn alreadyExists(items: Vec<Path>, quer: &str) -> bool {
    items.iter().any(|nms: &Path| -> (bool) {nms == &Path::new(quer)})

This searches over the items iterator, checking each path against a filename, and returns "true" if the file exists in the directory, or "false" otherwise.

Rust Note 5: Keyboard input in Rust

Rustlang is all about its functions. You barely have to run your program to make sure it works, and when you do, you write unit tests for them. But, what about good old days of taking keyboard input and faffing about without end in your program? Here's how to bring that back in Rust.

The Program
This program will take input and parrot it back to you. It's as simple as simple gets.

use std::io;

fn main(){
    print!("Input: ");
    println!("{}", io::stdin().read_line().unwrap());


io::stdin() returns a BufferedReader on stdio (the input stream). read_line() returns an IoResult (just used for handling some errors) that .unwrap()  turns into a normal string. That is then printed by the println! macro.

 Just be careful with .unwrap(). Part of Rust's power is being able to match against errors, and you lose that with .unwrap().