fuckyeahterminals

Making N-Volumes Behave like 1 Disk

So lets say you have a bunch of old hard-drives lying around that you’ve mounted on a rig you got and you want them to be 1 continuous disk cuz you wanna run something across the volumes. This is how you do that

First things first we gotta see which disks are the ones we are looking for
so you do something like this

sudo fdisk -l

and get some smaple output like this:

Disk /dev/xvda: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt


#         Start          End    Size  Type            Name
 1         4096     16777182      8G  Linux filesyste Linux
128         2048         4095      1M  BIOS boot parti BIOS Boot Partition

Disk /dev/xvdg: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdg1               1  2147483647  1073741823+  ee  GPT

Disk /dev/xvdf: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdf1               1    16777215     8388607+  ee  GPT

Alright cool I happen to to want to use these two 1TB disks. Now I tell my OS, hey I wanna use these two to make a single disk call it /dev/md0.

sudo mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/xvdf /dev/xvdg

Alight we gotta format this bitch.

mkfs.ext4 /dev/md0

Cool, congratulations you’ve done the hard part. Now we just mount it:

mkdir -p /srv/thedeorian
mount /dev/md0 /srv/thedelorian

and now you can use it. So the reason I say N-volumes is because if you happen to mount like 10 volumes a machine then you do mdadm to raid0 those volumes and the rest is the same.

How to fix Mac Terminal copying

So I don’t know about you guys but I fucking hate it when I’m trying to copy something from the terminal and Mac decides the Font and Color Attributes are something I want. No fuck you, I don’t want that. Why would anyone want that. I just want the text. This is how you fix that

    defaults write com.apple.Terminal CopyAttributesProfile com.apple.Terminal.no-attributes

dump this line on your terminal, no more shitty copying for you. My day got exponentially better. OR I’m pretty sure it’s in some settings bullshit where I have to click on some weird tab somewhere, ain’t no one got time for that shit.

Extending NSArray to Add Some Much Needed Functionality

So a lot of scripting languages will often times let you do something like this

array1 = [1,2,3] 
array2 = [3,4,6] 
... 
arrayN = [12,23,34] 
superarray = array1 + array2 + ... + arrayN 

And often times you might not need to do this in iOS but if for some reason you’re collecting data or working with many arrays and want to merge everything together, trying to go through each array individually to add it to some super array everything might be cumbersome.

Here’s how to get passed this:

NSArray+Utils.h

#import <Foundation/Foundation.h>

@interface NSArray (Utils)

+ (NSArray *) arrayFromArrays:(NSArray *)otherArrays,...;

@end

NSArray+Utils.m

#import "NSArray+Utils.h"

@implementation NSArray (Utils)

+ (NSArray *) arrayFromArrays:(NSArray *)otherArrays,... {
    NSMutableArray* result = [[NSMutableArray alloc] initWithArray:otherArrays];
    va_list args;
    va_start(args, otherArrays);
    NSArray *next;
    while((next = va_arg(args, NSArray*))) {
        [result addObjectsFromArray:next];
    }
    va_end(args);
    return result;
}

@end

Okay whats going on here. Well a couple things  but it’s simple I promise.

So basically we’re allowing to pass into the arguments n arguments that are nil terminated (given the while loop) and adding them to an array and using the  va_list, va_start, var_arg marcros (you can find what they do at cplusplus.com) to iterate through the array of pointer till we hit nill and then return the results.

Simple to do, and SUPER useful. You would use it like this:

    [NSArray arrayFromArrays:array1, array2, ..., arrayN, nil];

Instead of having to write a million addObjectFromArray on an NSMutableArray

Haskoin

It’s about time.

ask-stack

This should be plugin for all major IDE’s, this is forward thinking.

Pretty Slick

aspnet

Insane, I just thought it was all talk. I didn’t realize Microsoft had /actually/ posted their source code on github

count it off!