Mockacino a lightweight ruby/sinatra API Mocking script

Hi Guys, so i’ve been working on a new app recently for a client of mine, currently there is no API… so in the meantime I decided to knock up a quick few lines of ruby to get a mocking api up and running… to explain this better, I need not do more than paste my README.md here.. Enjoy 🙂

Mockacino

A very simple and easy to use MOCK API server that serves static JSON written in ruby/sinatra.


NOTE: This is a super simple, super fragile MOCKING SERVER Intended so you can test routes and mock an API with static jso whilst you’re still building the real production API. DO NOT EVER use this in production… Seriously. It breaks a lot and will if you try… DONT. Absolutely 0 effort went into it, therefor 0 Warranty. Use if you dare.

DOCS:

Folder structure defines API calls…. return.json is what gets served.

site_root ->;
    [ http method ] ->; [ api call route ] ->; [ json response contents of call return.json ] 

e.g.

site_root ->;
    GET ->; users ->; return.json
    POST ->; users ->; create ->; return.json

If you have static assets you wanna reference in the json, plonk them in the ASSETS folder

e.g.

site_root ->; file.jpg

You can call http://yourhost:port/ASSETS/file.jpg

Here’s the directory structure of the sample project included here

mockacino.rb  
./site_root/ASSETS
./site_root/GET
./site_root/POST
./site_root/GET/sheep
./site_root/GET/sheep/create
./site_root/GET/sheep/return.json
./site_root/GET/sheep/create/return.json

Which supports calls like…

http://localhost:4567/sheep
http://localhost:4567/sheep/create

And gives responses from the static result.json file like…

{
    "sheep": [
        {
            "id": "1234",
            "name": "Dolly Two",
            "url": "http://mike.kz/sheep1234",
            "assets": {
                "small_image": "http://cloned.sheep.com/ASSETS/small.jpg",
                "large_image": "http://cloned.sheep.com/ASSETS/large.jpg"
            }
        }
    ]
}

Usage:

gem install sinatra
ruby mockacino.rb
 

How to setup Ruby on Rails on Ubuntu Linux

There are a lot of guides that do exactly the same as what i’m about to write about… the reason for this quick blog post is mostly a brain dump for myself.. but also because I always struggle to find up to date info for all of this in one place… and there are always gaps… So here goes! by the end of this short tutorial, you should have not only a working rails and ruby installation, running as a user, but also a ruby on rails hello world! whaaaaaat. … 

 

Reading Linux extfs (ext2/3/4) in Mac OS X

I have a collection of both Mac OS X and Linux servers dotted around the place… Sometimes I need to read ext4 formatted drives on my Mac’s… this always proves an annoying problem where I have to mount them inside a Virtual Machine and copy things across…. Pain and Slow!

I searched the interweb for a solution to this… and most  guides are about 3 years out of date, so here’s one from 2013 that works on Lion / Mountain Lion and even Mavericks DP1/2.

Download and Install : OSXFUSE-2.5.4.dmg (this took off where MacFuse left off and even has compatibility for old MacFuse plugins).

Download and Install : fuse-ext2-0.0.7.dmg

Plug in your ext fs formatted drive… Voila! I wouldn’t rely on this in a production environment mind you… but its decent if you just need to grab some files from a USB drive quickly for example.

 

Instantly gain insight on someone else’s iOS App Architecture with MADebugTools

Just a quick post to say i’ve posted my first piece of code in over 5 years to GitHub. Its a clever little Objective-C iOS Category on UIViewController that seemlessly overlays a UILabel on every single view controller managed view with the class, nib or storyboard name that is used. Great for debugging old or inherited projects with minefield architectures. It uses some cool libobjc runtime techniques to accomplish this, but implementing the category is a case of dropping it into your project and Build+Go!

Category in Action

Grab the source code here as usual, follow me @italoarmstrong on twitter 🙂

 

 

Manage your KVM Hypervisor Remotely on your iPhone / iPad

Recently I began experimenting with KVM virtualisation in the Linux Kernel. Its a great technology that if your CPU supports VT-x / AMDV offers almost (really, almost) bare metal level performance inside Virtual Machines. It works on most Linux flavours and has a couple of handy management tools such as virsh and virt-manager. However, one thing I thought was always lacking and annoying me was of course, the ability to manage my Hypervisor from my iPhone / iPad when on the move! Time for an experiment I thought; then out came “KVM Remote”

KVM Remote on the iPad and 3 Different Remote Hypervisors

Its universal so works on both the iPhone and iPad and is extremely bleeding edge right now, but works! and is incidentally the first App i’ve made that doesn’t have selfish fiscal intentions, so theres another great reason to download it from the AppStore now!

P.S. i’ll be updating it regularly adding more features as requests come in.

 

Overclocking & Optimising the Raspberry PI

My Raspberry PI

Out the box the Raspberry PI comes with a ARM1176JZFS Core (armv6 with hard float aka armhf arch) running at 700 Mhz as part of the Broadcom SoC. Additionally the memory frequency is also limited. In recent firmwares however… tinkerers have had the ability to “overclock” the Raspberry PI to squeeze some extra juice out of it. Mine’s currently running at 1Ghz at a solid 48C temperature when under load. So the first question that springs to mind is… why doesn’t everyone overclock their Raspberry PI? Well… there have been (well founded) reports of SD card corruption, heat/power issues and instability. The idea of this post is to show the user how to safety squeeze every last bit, cycle and IOP out of their PI safely’ish and without being an astrophysicist. Read on for the know-how. … 

 

Installing Linux on a Late 2012 Mac Mini

So in the last post I discussed why the Mac Mini is the perfect machine for Linux and for Datacenters in general! One frustration some readers may be finding is that the networking chipset used by Ivy Bridge platform in Late 2012 Mac Mini’s doesn’t have native support in the Linux Kernel (as of now anyway). So its required to install a kernel module from the manufacturer/vendor (broadcom).

On their website they provide the “tg3” drivers for Linux kernels, however these are only good if you are running a Linux kernel < 3.5.x. If you take Ubuntu for example, 12.04 uses the 3.2.x stream, whereas 12.10 uses the 3.5.x stream and isn’t immediately compatible with the drivers on the broadcom page. This is due to the deprecation in 3.x and removal in 3.5.x of the asm/system.h header.

Read on for the fix, more and downloads. … 

 

Bye Bye FreeNAS hello NexentaStor

Well, i’ve used FreeNAS for around 2 years+ now, and all has been good, however, in that time demand for large quantities of storage has now been joined by demand for high speed storage; Once I had replaced all of my drives with 2tb 7200rpm drives I realised that FreeNAS wasn’t giving me the performance on each drive that i’d like.

Welcome NexentaStor… a storage appliance natively supporting ZFS as its based on OpenSolaris! NexentaStor offers many of the same features of FreeNAS, however at a greater level of performance. This comes at a cost though, the free Community edition is limited to a some what large 18tb, whereas the paid version will cost you.

Also NexentaStor is a pure storage appliance, although it supports CIFS/iSCSI/NFS and the likes, it does not have all the bells and whistles of FreeNAS… but for me, there is no use having all these features if I can’t have the speed.

I’m installing NexentaStor now as we speak, after which I’ll be posting a review / tutorial on NexentaStor after i’ve got it up and running and configured to my liking 🙂 I hope you enjoy it!

 

Amazon Support Store

Hi everyone! I keep getting lots of emails from people asking where they can buy xyz to complete the tutorials and try out some of the things listed on CaptainGeek, well after I kept emailing people the same links i had a thought, why not setup an amazon affiliate store. Basically, i’ve setup a small amazon site with a small selection of products (only those used for the tutorials on this site + related ones), purchases and payments are handled by amazon, however a small percentage of the sale goes to helping fund the server this website is hosted on AT NO EXTRA COST TO YOU 🙂 so its a win win situation, please use the links whenever you can.

Our Amazon Store

 

Sharing iTunes Libraries over the Internet, Bypassing Bonjour Restrictions

Ever wanted to be able to access the shared libraries from your home… when you are away from home? I do, since I started to use FreeNAS with Firefly iTunes/DAAP media server this is exactly what i want… I’m often away from home, and always wanting to access my media library from within iTunes…

Bonjour (mDNS) is what the iTunes / Firefly DAAP server uses to advertise a “beacon” of your iTunes shared library to your local subnet (LAN), however this is restricted (due to industry pressure (RIAA)) to local area only, and not wide area (the Internet) as it once was… However its still easy to circumvent and work around this issue so you can listen to your shared libraries on the go!

This tutorial is aimed at Mac users, but the concept is possible on every OS using the appropriate tools…

Tools needed:

Once you have all of these it becomes easy, this is the general process of how it works …