How to split one flac album into tracks

If you download a one-file flac album, you can split it into tracks. Assuming that you also have the cue file (the file which has the tracks signatures), following commands will do the trick:

cuebreakpoints myAlbum.cue | shnsplit -o flac myAlbum.flac

Make sure that you download `cutetools` and shntool. Using brew, its easy:

brew install cuetools && brew install shntool

Audio Quality Assesment

After my crappy earphones stop working I decided to get myself a proper one. After countless hours of reading reviews and trying them on myself on shopping malls, I’ve decided to go for Sennheiser Momentum over-ear earphones.

But while I was comparing them, I noticed how little lossless audio I have. My collection mostly consists of 320kb/s mp3 files which OK since it is the most popular option on internet. But are they really OK? I wanted to have a quick comparison on the files I have.

I used Audacity, a free audio editor, to see the spectrograms of files. Spectrograms are frequency distributions of audio. Higher frequencies are instruments like cymbals and low frequencies are bass sounds. Human ear tends to hear between 20hz to 20khz, although in reality most of us don’t really hear more than 16k as the upper limit. See this wiki article for more info. Here are the results from Opeth – Eternal rain must come:

Screen Shot 2014-10-03 at 14.51.45Above picture is an 256 kb/ps mp3. As you can see it is clipped from 16k.

Screen Shot 2014-10-03 at 14.51.55

Above is the lossless version of the same file. Notice the difference? Compression doesn’t only clip but also normalise the sound that is makes it louder. Do you have headaches after hours of music listening, this is the most possible reason for it.

So if I ever download music, I download flac and convert it to Apple lossless audio. Here is how I convert it:

ffmpeg -i /path/to/myTrack.flac -y -vn -acodec alac /path/to/dest/myTrack.m4a

Or even better, use convert plugin of great tool beets. Here is how you do it:

beet convert -a AlbumName -d /path/to/

Make sure you added the album beforehand, because it actually queries the beets database. Then it will use ffmpeg behind the scenes to convert them.

Best movies that I’ve seen in 2012

This is a very difficult list to make since I’ve seen many movies this year. But I will update it when I remember others.

Marigold Hotel

El Clasico

Hobit

Life of Pi

Midnight in Paris

The words

Dark Knight Rises

Xcode run scripts

I found some useful scripts here and there. I collect them here.

Adding git commit count as the build version automatically

#
# Set the build number to the current git commit count.
# If we're using the Dev scheme, then we'll suffix the build
# number with the current branch name, to make collisions
# far less likely across feature branches.
# Based on: http://w3facility.info/question/how-do-i-force-xcode-to-rebuild-the-info-plist-file-in-my-project-every-time-i-build-the-project/
#
git=`sh /etc/profile; which git`
appBuild=`"$git" rev-list --all |wc -l`
if [ $CONFIGURATION = "Debug" ]; then
branchName=`"$git" rev-parse --abbrev-ref HEAD`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild-$branchName" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
else
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $appBuild" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
fi
echo "Updated ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"

Printing the total line of codes to logs

echo "Total lines of code:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -and \( -path "${SRCROOT}/Pods/*" -prune -o -print0 \) | xargs -0 cat | wc -l

You should see it on logs (View->Navigator->Show Log Navigator)

Moving TODOs and FIXMEs to warnings

So it will bug you forever until you fix them.

KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"

 

iOS debugging tips

  • Use Instruments to see memory leaks, core data fetches or auto layout workflow.
  • Debugging console: pausing and investigate the variables by commands like po or p. Full list is here.
  • See device logs and read StackTrace, if any
  • Activate NSZombieEnabled flag at scheme settings. This will provide a warning when you try to access a variable which is already deallocated.
  • Use `exception breakpoints`, which will stop when there is an exception threw.
  • Use breakpoints to log messages instead of NSLog. Edit breakpoint for it.
  • Use `conditional breakpoints`.
  • Use  `symbolic breakpoints`, when you want the execution stop if a certain message sent. It is particularly useful when you don’t have access to the source.

Pro tip for debugging auto-layout

Here is a neat protip. While running your app in iOS simulator, hit ‘pause’, and run following command `po [[UIWindow keyWindow] _autoLayoutTrace]`. This will give you the trace of the autolayout.

Disk usage is a bitch

I, with my 128gb main hdd, struggle a lot.

I list the big files in a folder like this (or folders changing the -type switch to d)

find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

Or I use mac apps like `DiskDiag` or `OmniSwipe` to visually analyze what’s eating my space.

I even wrote a small script to delete iOS simulator’s unneeded data.

Lately I discovered a great tool called `ncdu`. Using shell, it displays the information about your hdd usage. and it’s very fast. Get it from here or do this `brew install ncdu`.

Following are similar tools that I copied from the website:

gt5 – Quite similar to ncdu, but a different approach.
tdu – Another small ncurses-based disk usage visualization utility.
TreeSize – GTK, using a treeview.
Baobab – GTK, using pie-charts, a treeview and a treemap. Comes with GNOME.
GdMap – GTK, with a treemap display.
Filelight – KDE, using pie-charts.
KDirStat – KDE, with a treemap display.
QDiskUsage – Qt, using pie-charts.
xdiskusage – FLTK, with a treemap display.
fsv – 3D visualization.
Philesight – Web-based clone of Filelight.

Goz hastane ucretleri

Birilerine faydali olmasi umidiyle:

Medical park goz muayene ucretleri:
SGK yok: 130TL (normal) 200TL (prof)
SGK var: 80TL (normal) 200TL (prof)
Emekli icin de ayni fiyatlar gecerli.

Dunyagoz ucretleri
SGK Var: 90+12TL
SGK Yok: 250

Yedikule surp pirgic hastanesi ucretleri
SGK Yok: 70TL
SGK Var (emekli): 22TL
SGK Var (calisan): 34TL

Model inheritance with node.js and mongoose

I am disappointed that mongoose documentation didn’t mention inheritance of models. To follow object-oriented principles, it is inevitable that you’ll want to have some inheritance in your models. Here is how:

First things first, let’s include mongoose and connect to db. It’s obvious that you should have a working mongodb instance. Run `mongod` in terminal.

  var util = require('util');
  var mongoose = require('mongoose');
  mongoose.connect('mongodb://localhost/test');
  var db = mongoose.connection; 
  var Schema = mongoose.Schema;

  db.on('error', console.error.bind(console, 'connection error:'));   
  db.once('open', function callback () {                              
    console.log("mongodb is opened");                               
  });                                                                 

Now, here is the fun part. I will create an abstract animal class that will hold the base structure of our model. All our animals will have a name.

function AbstractAnimalSchema() {           
    Schema.apply(this, arguments);          
                                            
    this.add({                              
        name: String
    });                                     
};                                          
                                            
util.inherits(AbstractAnimalSchema, Schema);

`util.inherits` is the key part here. This is the javascript way of inheritance. Basically you’re saying, I want to extend `Schema` with `AbstractAnimalSchema`.

var AnimalSchema = new AbstractAnimalSchema();  
                                                
var KittySchema = new AbstractAnimalSchema({    
    tail_type: String                           
});                                             

var DogSchema = new AbstractAnimalSchema({                
    leg_type: String                                      
});                                                       
                                       
var Animal = mongoose.model('Animal', AnimalSchema); // our base model   
var Dog = Animal.discriminator('Dog', DogSchema); // our derived model (see discriminator)
var Kitten = Animal.discriminator('Kitten', KittySchema); // our derived model (see discriminator)

Now, we defined `Animal` model which is the base model of all animals. And 2 derived model `Kitten` and `Dog`. Let’s add some data to db.

var mycat = new Kitten({ name: "My Kitten", tail_type: "Long" });   
mycat.save(function(err, mycat) {                                   
    console.log("kitten is saved"); // no error checking, we're so cool.
});                                                                 
                                                                                                                                     
var mydog = new Dog({ name: "My dog", leg_type: "Short Legged" });  
mydog.save(function(err, mydog) {
    console.log("dog is saved");
});

Now, fetch all animals

Animal.find(function(err, animals) {
    console.log("all animals: ");
    console.log(animals);
});

The result should be something like this:

[ { name: 'My Kitten',
    _id: 53049e22d1c2380000d3fb3f,
    __v: 0,
    __t: 'Kitten' },
  { name: 'My dog',
    _id: 53049e22d1c2380000d3fb40,
    __v: 0,
    __t: 'Dog' } ]

I learned all these things from here

First thoughts of node.js, expressjs and mongoose

I am very new to node.js (in fact, I wrote my first program in node just an hour ago). It is cool, really cool environment. I like it very much but it still seems a bit raw. Expressjs documentation for instance, is not comprehensive. There is a concept called “middlewares”, and expressjs documentation believes that people already know it by heart, so why bother with definitions (luckly, I can tell thanks to my experience with django).

Another problem I see is that the 3rd party apps aren’t in their stable versions yet (most of them). In comparison with `django`, it is not then reliable imo.

Another comparison with `django`: express doesn’t come with a model layer, but you can use mongoose, or any other orm that I am not aware. Also, django comes with lots of out-of-the-box solutions like authentication/authorization, admin panel, etc. expressjs doesn’t.

On the other hand, having to develop non-blocking web apps is amazing, it changes the whole way of programming web. I think node.js and its apps will be way more mature in the near future that will be inevitable for anyone to switch. For now I stick with django for relatively big projects because it’s a great and mature framework and I do things reaaaaaly fast. But I can say that I am in a slow transition to node.