utorak, 11. veljače 2014.

The Perfect .gitignore for Rails, RubyMine and OSX (thx Github et al)

*.rbc *.sassc .sass-cache capybara-*.html .rspec /log /tmp /db/*.sqlite3 /public/system /coverage/ /spec/tmp **.orig rerun.txt pickle-email-*.html config/initializers/secret_token.rb config/secrets.yml ## Environment normalisation: /.bundle /vendor/bundle # these should all be checked in to normalise the environment: # Gemfile.lock, .ruby-version, .ruby-gemset # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode ## Directory-based project format .idea/ # if you remove the above rule, at least ignore user-specific stuff: # .idea/workspace.xml # .idea/tasks.xml # and these sensitive or high-churn files: # .idea/dataSources.ids # .idea/dataSources.xml # .idea/sqlDataSources.xml # .idea/dynamic.xml ## File-based project format *.ipr *.iws *.iml ## Additional for IntelliJ out/ # generated by mpeltonen/sbt-idea plugin .idea_modules/ # generated by JIRA plugin atlassian-ide-plugin.xml .DS_Store .AppleDouble .LSOverride # Icon must ends with two \r. Icon # Thumbnails ._* # Files that might appear on external disk .Spotlight-V100 .Trashes

srijeda, 24. listopada 2012.

A common SSD problem - or - How I Stopped Giving A Fuck

Reactant

So, while I was reading on the forums about the hot new SSDs, I have created an opinion on my own. Mostly from what I've seen, people are experiencing problems similar to first world problem image here:
Problem officer?
These people obviously have issues.

From a user's perspective, adding a SSD will improve random access times and data transfer speeds to a very noticeable point. But it being the most noticeable benefit from adding the solid state drive, it still doesn't even NEARLY saturate a single SATA 2 (3 Gbps) port, let alone a SATA 3 (6 Gbps) port.

However, as far as sequential read and write speeds go... well yes, it is a good thing to have a more modern SATA standard to connect your SSD to. But calling it "slow" is not fair for something that makes your computer do a multiple-generation jump from when you have bought it without SSD to when it has been upgraded with the SSD.

All in all, it's a good benefit and exactly there where it matters most.

! BONUS ! BONUS ! BONUS !

So I created a meme of my own. Check this out:

Somehow Picard doesn't give a fuck for your problems.
I have an aftermarket SSD in my corporate Macbook Pro connected to a SATA 3 port and I don't give a fuck about your problems.

ponedjeljak, 22. listopada 2012.

Lossless compression with modern multi-core computers

Preface

If you recently bought a computer or a modern smartphone, you have probably heard of a certain kind of technobabble called "Dual Core", "Hyperthreading", "Quad-Core", "Simultaneous Multi Threading", "Multi CPU". Basically because all modern computers (laptops, tablets, desktop PCs, smartphones) do come with more then one CPU. I assume that The Kind Reader knows what a CPU is, so I don't have to explain a lot here.

A Multi-Core World

A smartphone, A FUCKING PHONE has more than one CPU lately. So what is up with that? Marketing? Featureset? Multimedia? All of it actually, so you can have and use more features on your phone that wasn't possible before because of limited CPU and computational power. So you can do more with your phone, and not just make calls or send messages. 3D games perhaps? Why not :)

The method to build multi-core CPUs is very complicated, so you need to plan the architecture, create the die, manufacture the die in a semiconductor foundry, test every die, package it and depending on test results, brand them with a model name and a suggested price.

An Intel Ivy Bridge CPU die. Just look at those numbers !!!!
If you have a modern computer (laptop, desktop, tablet...) chances are you have more than one CPU core in your CPU - my corporate laptop has 4 cores. So it's only understandable that I try to figure out how to give all of them a nice amount of computational load. It's only fair since they're at my disposal :)

You can create applications and do calculations in parallel on each core, so the time needed to complete some calculation shrinks depending on how parallel the task is (see Amdahl's Law here) and how many cores/CPUs you have. So you can accelerate stuff like encoding videos, compressing music (every music file on each core OR one file on many cores), mathematical calculations, multitasking... the list increases with time.

But it's difficult to create programs for parallelism, because not every task can be made parallel.

For example, you cannot parallel the drawing of the image on the screen, but you can parallel the compression of an image (create a checkered field of image sections and process them in parallel).

You can also use all cores for data compression. And that's what we're cover here.

And a small tutorial, finally

There are numerous ways to do data compression in parallel. So,
  • On Windows-based systems, you can use the application called 7-Zip to do data compression and decompression in Windows. You don't need to setup anything, just install 7-Zip and compress some files! It will distribute the calculation workload across all CPU cores
  • On Linux-based computers, things are a little more complicated. You first must compress files to a package, and then apply a compression mechanism. The default tools use only one CPU core by default and additional hacking must be done for parallel data compression.
  • On Mac OS X based systems, I don't care. Not because they're fast and you don't need to do squat, but because it thinks it's smarter than you and it wants you do stuff their way. I want to do stuff my way, so from religious and lifestyle reasons, I don't give a fuck how OS X compresses files in parallel.

Compress & Decompress files in Linux

You need the tar archiver and a compress/decompress application. For the sake of this blog post, I will pick the gzip compress/decompress program.

So you have a folder called foo. So,

[root@atomsk ~]# tar cpvaf foo foo.tar.gz

That command will compress the folder/file foo to the file called foo.tar.gz. Tar means Tape ARchiver, because magnetic tape storage was used and is still being used to create backup archives of sensitive files for... whatever happens :). 

OK, so tar is a tape archiver program, but what does "cpvaf" means

"cpvaf" are the argument switches that order the program what to do. You will either read the manual somewhere else OR continue reading :)
  • "c" - means that the tar program will (c)reate a new .tar file
  • "p" - means that the file access permissions will be (p)reserved. If the file is read-only and belongs to the user called linuxuser, after decompressing the file will return as read-only and belonging to the user linuxuser.
  • "v" - will just display which file it's packaging. It's short for (v)erbose.
  • "a" - will tell tar that it (a)utomatically figures out the compression method based on the result file extension. In our case, that's .gz which is gzip.
  • "f" - means that the output will select a (f)ile or (f)older for archiving or unarchiving. In our case, the "f" argument packages a folder called foo.
But sadly, the compression will only use one CPU core for compression. You can also avoid compression and just package the files (avoid the .gz extension on the target file), so computational power is not really needed, but just IO performance of the computer doing the packaging.

MULTICORE COMPRESSION BABY!!!!

You need an application that can do file compression in multiple threads. The OS will then distribute the threads across multiple cores and will greatly improve the compression performance!!!

For gzip, there's a program called pigz, which stands for parallel implementation of gzip - and it's not pronounced like "pigs" but like "pig-zee" or "pig-zed" if you're British or want to pronounce stuff the right way :).

But I'm afraid the things become a little more complicated to use because you need to know a little more about the UNIX shell and a concept calld piping.

[root@atomsk ~]# tar cpvaf foo - | pigz --fast > foo.tar.gz

A pipe in shell scripting means that the result of the program will not be saved on a file or displayed on the screen (standard output), but the process result will be saved to memory. That will give you the option to redirect the output of one application to the input of another application using the pipe operator "|". 

And... let's GO!!!!
In our example, the output of our tar program will be piped to the input of the multithreaded implementation of gzip that will compress the tar file in parallel and save it to foo.tar.gz. The "--fast" switch means that it will use the fastest algorithm that results in the least compression.

And to decompress....

Also we need to use piping. So we need first to decompress the file and then give the result to tar to unpack the archive. In a nutshell, if we need to decompress we need to reverse the action order compared to compression. Since we compressed last, we need to decompress first and then unpack the archive since we first packed the folder.

[root@atomsk ~]# pigz -d < foo.tar.gz | tar xvf -

And that's it. The "-d" switch mens that pigz will (d)ecompress the target file foo.tar.gz and will pipe the output to the input of tar program with switches x - e(x)tract, v - (v)erbose and f - (f)ile as a input argument. The "-" at the end means that the file will be grabbed from the pipe.

And the end

Since you bought many cores, it's only reasonable to use them at their 100% where available. The speed of compression now depends solely on the CPU performance since hard drives, and especially SSD are more than IO capable to feed the modern CPU with data to compress.

BONUS QUESTION

Can someone explain how to use multithreaded compression on Mac OS X? When I created disk images with Disk Utility, it did compress with all threads. So it's possible BUT HOW?

petak, 28. rujna 2012.

The Macbook Pro hackfest

Intro

For some time now, I'm using a Macbook Pro (Model 8,2, Late 2011, 15 inch) and it's a very boring device most of the time. You cannot tweak it, improve it, tinker with it and change a lot of stuff because it's quite a limited ecosystem - it's basically designed to run Mac OS X and integrate with it in a best possible way found. Also it has been designed to work best with Apple branded extensions, accessories and peripherals. In a way, it's walled garden of functionality and efficiency conceived and designed by Apple's prime engineers.

To a standard, run-of-the-mill engineer, that may look a little boring because nothing can go wrong. And then you connect a Logitech mouse or a Dell display.

And everything goes wrong :)

Why hack?

I try to dive deeper into all computers I own because I like to do so and to push the hardware and software to its limits, even beyond Apple's specification or Apple's vision of consuming the device they sold you. Those laptops are designed to be consumer devices in the hands of a standard user, a productivity device in the hands of a power user, and a workstation for a developer/designer/video editor, etc - so it's a versatile device. It's only difficult to play games because it has substandard GPUs for that price, but playing on a laptop is a silly notion by itself as far as I'm concerned.

Since evolution of technology doesn't end, you can try replacing components to improve stuff - add more memory or replace a hard drive (if you buy it with one) with an SSD. That are performance improvements, and big ones, but does that change the functionality of the device? Of course not.

So what are my options?

Hack the laptop!

What the Hack!! So, what can I do?

Whatever you want.

That's a lot of stuff to do then. My choice is:

  • Do stuff with the bootloader - EFI hackfest
  • Do stuff with Windows
  • Do stuff with Linux
  • Play with virtual machines
  • Use esoteric/obscure features in OSX that only 0.1% of people use
  • Defy Apple by doing things differently from what they designed - faster but with more effort.
  • Nonstandard peripherals.
Some of those things are very interesting, for example EFI (Extensible Firmware Interface), that is very much hidden from the user (because of the "walled garden" motto) but very very useful to know. As one of the more obscure features, Internet sharing is also pretty useful as it will turn your MBP to a access point in one of two ways depending on what connects to the network. Actually I like to call this stuff Network Connection Sharing, since you can connect other devices to the network shared by the MBP.

But my favorite is a native, non-BIOS emulated mode of installing Windows 7/8 via EFI. So far I've failed in doing that but new stuff is learned with every day. That taught me to do backups of drives, migrate installations, tinker with EFI executables and scripts and with Windows setup mode through EFI. With linux, it's easier to set-up but still very hard if you don't know what you're doing.

After a while, that stuff becomes more interesting than actually using the Mac. In the following posts, I'll make a few guides on how to hack specific parts of your Mac.

Endgame

Just don't listen to Apple on how to use it's computers. You can have a moderately good experience by using it but it will become boring just to stare in it, surf the web, chat, edit images, develop for iOS... it's a IT nightmare to have and advanced device and be limited by Apple's best practice.

Remember: someone else's (Apple's) best practice might not be your best practice. Explore and find what works best for you.

petak, 4. svibnja 2012.

On Quad Core Jerkoffness

So, the latest Samsung flagship smartphone, that the media calls "superphone" has been announced and demo'd. And what do people think?

Why Should You Get a Galaxy S 3 (its III, but I HATE roman numerals)
  • You have a lot of money
  • You have a VERY crappy phone like the early 2000s phone.
  • You like to brag with your latest gadgetry
  • You like to play with your phone (either games, or custom roms... or whatever) 
Why You Should Not Get a Galaxy S 3
  • You can already surf the web easily
  • You can make phone calls. Yes it's a phone!!!!
  • You can write SMS, MMS, mail, etc.
  • You can consume multimedia (youtube, videos, music)
  • You don't need to charge the phone often. Once every 2 days is great :)
So Samsung Galaxy S III in my opinion... meh, will not buy.

 

Quad Core to drain your battery...


There is an increasing trend of MOAR COARS. And MOAR SCREEN. And MOAR RAM. This, in my opinion is absolute and complete bullshit. I remember using a phone, and it was good. Then I needed to get rid of it - because I needed another phone for development. So I gave it to my sister. The phone is the 1st revision HTC Desire, one that had the AMOLED screen and somewhat bad vibration motors.

And I'm a professional. I know my way around silicone shit. I can type and click and respond with types and clicks to error messages. I can fix stuff.

But I really cannot understand why are they putting MOAR COARS in these latest phones. Must it run Crysis? Must it fold@home? Must it keep your palms warm when do watch a video? Force you to use the charger more often? Something?

The "community", which are mostly consumers and semi-enthusiasts want MOAR COARS. So generally speaking, someone is forcing Samsung and other hardware and phone designers and manufacturers to add more cores. The phone now should be faster - yeah, to call somebody and then run out of battery. Or start typing a message and overheat your phone.

The only thing it makes sense is to replace a home PC for consumers, that consume content from the Interwebz. So you make a simple and intuitive interface that simplifies web browsing, music and movies, and you got yourself a winner.

... or replace your PC-like device.


So they are building phones to replace personal computers. A colleague of mine thinks that in the future, you will have just one device, and carry it around. It will act as your computer, Internet device, multimedia hub, etc. But when you plug it in to a specialized dock, you will use it as a personal computer with a large screen, keyboard and a touchpad/mouse. Sweeet :)

That's actually a good idea. But for someone that doesn't think that a personal computer is a fun consumer device, but a productiviy workstation, that sucks. And today's phones, as fast as they may be as a phone, cannot replace a full featured personal computer. There was a phone called Motorola Atrix, that had a notebook-like dock. Good idea, but it failed - because of extra costs and awful performance. It just won't work. At least not yet.

And with all these Sandy/Ivy Bridge chips...

... I would shoot myself in the foot if I replace it with a phone. Yes, the PC needs a hundred times MOAR POWAH, but It's a thousand times faster and million times more flexible. And for me, that's important.

IBM makes ownage HPC-s. Intel makes kickass consumer and server CPU-s. ATI/nvidia makes kickass video cards. Sony/Microsoft makes kickass consoles. So why should I get a generally weaker device that will get me crappy experience instead of having different, but highly specialized devices that offer maximum performance and user experience?

TL;DR


I don't need a modern super-smartphone, I only need a smartphone. Every other phone, go fuck yourself, I'm keeping my PC,

četvrtak, 3. svibnja 2012.

A dream to come true.

Rub three times...

... and a Djinn leaves the lamp. Sanity today is a very rare commodity, something that I learn every day. People are given endless choices about everything. Really, everything. So if a certain individual doesn't get it's choices right, might end up frustrated or stressed. Not a pretty sight.
In time the frustration will become an addiction, and you will never ever pick anything right. You'll be dissapointed with this or that and eventually turn paranoid, but at the end of the day... do you really need all that?

The answer is a big fat NO.

 

Wishful thinking

Calling a Djinn from the lamp, you are usually given three wishes (with a few disclamers, hehe). One of my wishes is at least to be more straightforward with picking things that I don't really need. Surely, I can pick the things that I need with no problem, but what if you don't need something but want it anyways? Chances are, you'll spend money for it. The harder you earn it, you'll be less eager to spend it. Easy come - easy go. Just like the three wishes. Generally, you don't know what to do with a given opportunity, you just waste it and take it for granted.
A small example from life: since we're visiting a same caffe bar (it's in our office neighbourhood) on and on and time and time again, one morning we were given free drinks, compliments of the manager-slash-owner. And what did we pick? Instead of picking something fun, like beer, scotch or a coctail, we took aromatized sparkling water. Which is cheap. Pretty cheap. I cannot emphasize enough - very cheap. One should now think that the manager is using this philosophy to attract more customers by giving them rewards or bonuses, and using the surprise-effect and easy-come-easy-go mentality, to get away with, let's admit it, cheap advertizing.

What angers me most is that I fell for it. Dumbass.

That really insulted my intelligence.

 

How to use the wishes

First thing to do when given an opportunity is to think about it, and think real hard. Try to cover all the bases, have an exit strategy and work hard to get all the right stuff with near-perfect benefit for oneself. When presented with a choice, you don't just rush into it. Like falling for offers with cut prices for an already cheap commodity or wasting good scotch on the manager's tab. In some situations there's no room for mistakes. Especially since you don't live forever. That's why, for example, you are not given the benefit of asking Djinn for more wishes. Because then, you'll go against the shortcut-taking human psychology - which rushes into things. And it goes against the law of things - which is the conservation of energy.
Disney's Genie, voiced by Robin Willams
You cannot get something for nothing. The wishes are free, but we cannot really use them. You can only get away if you pay with Sanity and Wisdom, which people don't really posses in tandem. That's why a superinteligent person is never "sane". That why a "wise" person has no desire to gain.

Common sense is slowly losing it's meaning and followers. But the process is accelerating.

 

FAIL?

...

ponedjeljak, 2. travnja 2012.

Season premiere!

Just a normal day for this blog writer
So, I somehow gave up from writing on this blog. But worry not, some goodies are coming!!!

ISDK (the 's' is for 'still') how to make people read this - perhaps threaten them, ^^^^^^ :)

Crash course what's coming (not in this order, fkors):

  • Apple OS X rants (haha, notice the lack of Mac)
  • Solid State Drives, theory and minute experience with them :)
  • The ultimate user experience computer building
  • Why gaming is bad for you... mostly for your wallet, heh
  • Bike, run, swim - summer is comin' peopleeee :DDD
  • Horizons... of cross platform and cross device development. Crosseyed.
Stay in touch, you might be or you might not be disappointed. If you don't agree, feel free to rage and troll the blog.

Trolling boosts ratings, hehe :)

CYA soon, then :)