Skip to main content

Posts

Linux on XPS 15 9550/9560 with TB16 Dock [Update:3/29]

Finally got a laptop to replace my fat tower at work - Dell XPS 15 9560. I was allowed to choose which one I wanted and chose the XPS for its Linux support since Dell ships developer edition XPS's running Ubuntu so I figured Linux support would be better than other manufacturers. At first they got me the model with the 4K screen but my monitors are 2K and multi-dpi support in Linux is virtually non-existent and even hi-dpi support on its own is pretty terrible. So I got it exchanged for the model with the regular 1080p screen (which happened to also be the updated 9560 model), which works much better. I'm very glad to report that pretty much everything works, including the TB16 desktop dock, with just a bit of settings tweaking. This post is to help anybody considering getting this setup or looking for help getting things working. For now, I am running Kubuntu 16.04 with KDE Neon installed. List of things I explicitly tested and work: WiFi, Bluetooth Thunderbolt charging ...

Animating objects in JavaScript

I needed a way to animate any property of an object in JavaScript (not necessarily even an element on the page). I did not find anything satisfactory (to me) online, so I decided to write my own. This is the result. It's a simple animation class, loosely modeled on the Android animations API (in fact, the built-in animation interpolators are simple translations from the Android source code). It is very flexible, and supports animating any  numeric property of any object. Animations run at 60 Hz to be fluid if UI elements are being animated. Features: Animate any numeric value Start/stop, pause/resume/restart Repeat - for a specified count or infinitely Reverse animation on repeat. Callbacks for start, stop, resume, end, repeat Custom interpolators NO dependencies Download the code here (includes documentation for all methods). A demo of the code is  available here . It simply animates a box moving to the right, but demonstrates how the class is used. Proto...

Super mkdir helper function for php

Here's a handy little function to force-create directories in PHP. If the directory does not exist, it will create it. If there is a file with such a name, it will delete that file and create the directory in its place. Params: same as  http://us.php.net/manual/en/function.mkdir.php Returns: true on success (the given path is now a directory), false on error function super_mkdir($file, $mode = 0777, $recursive = false) { if (!file_exists($file)) return mkdir($file, $mode, $recursive); if (is_dir($file)) return true; if (!unlink($file)) return false; if (!mkdir($file, $mode, $recursive)) return false; return true; } I will possibly have a better version later which would return error codes instead of just false...

Broadcom Bluetooth Driver: Installer or Virus??

My primary computer at the moment is an HP dv6 laptop (with Broadcom 2070 Bluetooth chip). Upon getting my laptop, I immediately wiped the hard drive and slapped on a fresh copy of Windows 7. Installed the drivers from HP, and everything was rolling along nicely... Fast-forward 4 months... Now I'm having some issues with Bluetooth communication between my phone (Android) and my laptop. So I reinstall the Bluetooth driver... The installation took a long  time, but eventually errored-out, and quit. Of course, I had left the computer unattended during this, and came back to an almost-empty hard drive (!!!!). Restored for backup, some minor data loss, no problem... I thought I had snagged a virus in the download (even though it was direct from HP's site). Redownload, scan with multiple scanners, run it ....... SAME RESULT!!! Giving up on the official installer, I just took the drivers that the installer unpacked, and manually installed them... That didn't solve my original pr...

JComboBox with Disabled Items

Recently, I was working on a project in Java and needed to have a combo box, but with certain items in the list disabled (e.g. gray and non-selectable). At first, I simply set a custom renderer for the combo box which checked if the item was disabled. That, however, did not prevent the items from being selected. Thus, I set about to find a viable solution. There are plenty of solutions out there, but none seemed to work exactly the way I wanted. In the end, I ended up subclassing JComboBox to provide the functionality of disabling individual items. Here is my result, in under 100 lines: import java.awt.Component; import java.util.ArrayList; import javax.swing.JComboBox; import javax.swing.JList; import javax.swing.plaf.basic.BasicComboBoxRenderer; public class PartialDisableComboBox extends JComboBox { private static final long serialVersionUID = -1690671707274328126L; private ArrayList<boolean> itemsState = new ArrayList<boolean>(); public PartialDisableComboBox...

Listening for Window Resize events with Prototype

Recently, I came across an issue I had with full-screen (more specifically, full-viewport) canvas drawing. It all worked fine, except that the canvas dimensions must be specified in pixels, as opposed to percentages. This means you can't just set the canvas' width and height to "100%" and be done with it... The dimensions were automatically set when the page loaded, but if the user resized the browser window after that, the canvas would stay the same size, and would be either too big or too small. Thus, the canvas must be resized every time the browser window is resized. Prototype makes all of this easy. All that's necessary is to attach a listener to the onresize event of the window object, and then use document.viewport.getDimensions() to determine the new width and height. Here's some sample code: Event.observe(window, "resize", function() { var width = document.viewport.getWidth(); var height = document.viewport.getHeight(); ...

Converting single-touch events to mouse events

Many times, there are various interactions that take place in a web app based on mouse movement, clicking, dragging, etc. With a mouse, this is fairly simple, as there is a single point, and events like mousedown, mouseup, and mousemove can be used to discover the state of the mouse at any given time. On mobile browsers, however, it's a different story. Most phones support at least some kind of multi-touch, and the mousedown and mouseup events are not fired (there is, after all, no button). In addition, mousemove will only be applicable when dragging. Instead, mobile browsers dispatch touchstart, touchmove, and touchend events. Moreover, these events keep track of all touch points, not just the first or last one, and as such make handling them a bit more difficult. For the purposes of an application that only requires tracking clicks and drags, it is more convenient to translate these touch events into mouse events without having code duplication. This can be accomplished quick...

Drawing Dashed Lines on an HTML5 Canvas

The canvas element in HTML is great, but has one strange shortcoming: it cannot draw dashed lines (natively). However, dashed lines seem like a pretty common thing to draw, which only highlights the problem. Looking around, I've noticed several solutions to this problem. Some use trig, and others use their own libraries that must be imported. So in the end, I decided to create my own method. This code will add the function to all canvas elements, both those already on the page, and any that are dynamically added later. Here is the code: CanvasRenderingContext2D.prototype.dashedLine = function(x1, y1, x2, y2, dashLen) { if (dashLen == undefined) dashLen = 2; this.beginPath(); this.moveTo(x1, y1); var dX = x2 - x1; var dY = y2 - y1; var dashes = Math.floor(Math.sqrt(dX * dX + dY * dY) / dashLen); var dashX = dX / dashes; var dashY = dY / dashes; var q = 0; while (q++ < dashes) { x1 += dashX; y1 += dashY; ...

What Google's Relationship with Vendors Should be like in Regards to Android

I've been watching Android since it was first released, and got myself a Nexus One about half a year ago. The potential this platform has is very nice, and not just for smartphones. I would really like to see the tablets that will come with Android. But this isn't about me discussing Android itself. It's about the vendors who sell Android handsets and tablets, and their relationship with Google. Android is great for its customizability. Unfortunately, vendors have taken this too far and made a perversion of the platform with forced apps, home screens, missing features, etc. Forced Apps If I don't use/want an app on my phone, I should be able to remove it at will, unless it is a system app (e.g. removing the Dialer app would be plain stupid). But carriers and manufacturers insist on putting apps on the users' phones that cannot be removed unless the user roots their phone (which will void the warranty). Why? If the app really is good, I will keep it, use it, an...

My Views on Code Indentation

I have read many, many articles about the whole tab vs. space indentation thing. Personally, I don't necessarily agree with most of them. They will require the coder to use a specific indentation size and stick with it, even forcing that on other coders. First off, let me outline my method for indenting code. Then I will explain the reasons and advantages/disadvantages. When I indent code, I will use tabs, but only at the beginning of a line. To align something in the rest of the line, I will use spaces. If a line spills to the next line(s), I will indent that line two tabs further. Rationale: Tabs Why tabs? First off, they're compact in the file (1 byte each). This is really insignificant with current disk sizes, but still. If you indent in spaces, then your file will be larger (unless you indent with one space). Another advantage of tabs is that a tab is a tab. It doesn't specify by how many spaces the code is indented, but rather by how many tabs it is indente...

Generating PDFs in Rails with Prawn and Prawnto

There are several different PDF generation libraries available for Rails apps. Some of these are PDF::Writer, Prawn, Ruport, RGhost, and FlyingSaucer (for JRuby). First off, Ruport is basically a higher-level API for PDF::Writer. FlyingSaucer is only for JRuby (because JRuby allows for loading of Java classes). Not having any experience with RGhost, I can't exactly write a guide for using it. So now it's basically between Prawn and PDF::Writer, unless there's another library I haven't hear of. However, to my dismay, there is not UTF-8 support in PDF::Writer. So Prawn ends up being the PDF generation library of choice. One thing to keep in mind is that Prawn and Prawnto are beta-stage (sometimes even alpha) libraries, so some code hacking is going to be necessary. Also note the Prawnto is not maintained or tested by the Prawn developers, so there's no guarantee that it'll work with future versions (especially since Prawnto's developer has been "below t...

Ruby on Rails vs PHP

In my past experience with Web Apps, I have worked with PHP (with MySQL). Now I'm working on my website and using PHP again. At work, however, we are using Ruby on Rails (RoR), with Oracle. This makes me want to do a comparison of the two. Obviously, I will compare RoR and PHP, but both using a MySQL database. Keep in mind that this is based on my impressions, not necessarily the best technical aspects of each language. RoR Advantages: RubyGems - It's extremely simple to install extra features (calendar date select, etc). Yeah, you can have libraries in PHP, but it's not as simple and polished as RoR. You can even define gem dependencies your app has in environment.rb and then use "rake gems:install" to install all gems your project requires. Layouts and Partials - Let's face it: having a "standard.html.erb" layout (or template, if you will) and then having "" in it is just beautiful . Whatever content you create will automatically (or au...

Is Apple becoming another Microsoft?

You know what pissed off Linux/Unix folk about Microsoft and Windows? My best guess is that it wasn't Open-Source. Thus, their suggestions weren't taken into consideration as much as they should have. Microsoft was controlling its own software too much for its own good. Now Apple is doing the same thing. Let me explain with the example of iPods. If we take a look at any iPod model before the iPod touch, we notice that (internally in the filesystem) it's pretty simple. You have your music files and your song/other stuff database. The database(s) were plain-text and their structure could be examined and mimicked. This allowed for syncronization with software other than Apple's iTunes. Now welcome the iPod touch... No more simplicity. iPhone OS keeps its databases hashed. Yes, you can put music files on there with non-iTunes, but they won't show up in your lists. It's like the files are orphaned. The only program you can sync the iPod touch with is iTunes. Oh, and ...