idimmu . net http://www.idimmu.net A web based memory replacement service. Tue, 12 Aug 2014 09:06:49 +0000 en-US hourly 1 Is This The Most Important Script You’ll Ever Write?http://www.idimmu.net/2014/08/11/is-this-the-most-important-script-youll-ever-write/ http://www.idimmu.net/2014/08/11/is-this-the-most-important-script-youll-ever-write/#comments Mon, 11 Aug 2014 15:42:50 +0000 http://www.idimmu.net/?p=891 Is This The Most Important Script You'll Ever Write? 1 Since my first IT job ever, I’ve taken part in a tradition started by the guy I was replacing. A tradition known to us as escape.pl, and something people in my local Linux Administrator community have kept with for well over a decade now.

The Most Important Script You’ll Ever Write?

The first time I saw it it was written in Perl, I’ve since written them in Bash, Java and now Javascript. I’ve just seen one written in AWK. Some are cleverer than others, some just do the bare minimum. Some are executed by hand, others are run each time a new terminal is opened thanks to .profile, .bashrc or whatever’s managing your shell environment.

Well What Does It Do?

Quite simply the most important script you’ll ever write calculates the difference between two dates. Today, and your last day of work. The day you escape.. Where to? Who knows, perhaps a new job, a new country, either way somewhere significant!

Mine is currently a node.js app, and it has a bug, it hasn’t taken in to account a bank holiday, but it does the job.

free:~ rus$ node escape.js
Escape in 18 days.
Working days left: 15

Another takes in to account even minutes so he knows how long he’s waiting!

16:03 < woduf> 004 days, 00 hours, 57 minutes

How complicated you want to make the most important script you’ll ever write is up to you, but the sentiment remains the same!

Examples Of The Most Important Script You’ll Ever Write

Node.JS

function workingDaysBetweenDates(startDate, endDate) {

// Validate input
if (endDate < startDate)
return 0;

// Calculate days between dates
var millisecondsPerDay = 86400 * 1000; // Day in milliseconds
startDate.setHours(0,0,0,1); // Start just after midnight
endDate.setHours(23,59,59,999); // End just before midnight
var diff = endDate - startDate; // Milliseconds between datetime objects
var days = Math.ceil(diff / millisecondsPerDay);

// Subtract two weekend days for every week in between
var weeks = Math.floor(days / 7);
var days = days - (weeks * 2);

// Handle special cases
var startDay = startDate.getDay();
var endDay = endDate.getDay();

// Remove weekend not previously removed.
if (startDay - endDay > 1)
days = days - 2;

// Remove start day if span starts on Sunday but ends before Saturday
if (startDay == 0 && endDay != 6)
days = days - 1

// Remove end day if span ends on Saturday but starts after Sunday
if (endDay == 6 && startDay != 0)
days = days - 1

return days;
}

var date1 = new Date();
var date2 = new Date("08/29/2014");
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
console.log("Escape in ", diffDays, " days.");

var workdays = workingDaysBetweenDates(date1, date2);
console.log("Working days left: ", workdays);

AWK

Thanks to woduf for the following awk snippet!
awk 'BEGIN { print strftime("%j days, %H hours, %M minutes", mktime("2014 08 15 17 00 00") - systime() - 89940) }'

HTML/JS

Thanks to xhae for the following HTML/JS combination!
<html>
<head>
<style type="text/css">
body {
background-color: #8c8;
font-size: 11em;
color: firebrick;
}
</style>
<title>^[</title>
<script>
var then = new Date(2013, 6, 5, 17, 0, 0);
(function loop() {
window.requestAnimationFrame(loop);
var now = new Date(),
s = Math.round((then - now)/1000).toString(),
DAY = 86400,
HOUR = 3600,
MINUTE = 60,
days = Math.floor(s / DAY),
hours = Math.floor((s % DAY) / HOUR),
minutes = Math.floor((s % HOUR) / MINUTE),
seconds = Math.floor(s % MINUTE);
document.body.innerHTML = "T-" + days + ":" + hours + ":" + minutes + ":" + seconds;
})();
</script>

Perl

Thanks Huw!
#!/usr/bin/perl -w

use strict;
use Date::Manip;

my $leave = "14th June 2013";
my $escape_date = ParseDate($leave);
my $day = ParseDate("today");
my $count = 0;

do {
$count++;
$day = DateCalc($day, "+ 1 day");
} while (Date_Cmp($day, $escape_date) < 0);

print "Only $count day",$count>1?"s":""," to go\n\n";

Bash

Thanks woduf. Note, this works fine on Linux/GNU but not so fine on Mac/BSD
d=$(($(date +%s -d '2013/09/27 17:00:00') - $(date +%s))); echo "Escape in $((d / 86400)) days, $((d % 86400 / 3600)) hours"

Have you ever written an escape.pl? Whether you love your job or hate it, changing job can be a significant life decision and it helps to add fun to the seriousness of it! Please send me examples of your most important script and I’ll add it to the list!

]]>
http://www.idimmu.net/2014/08/11/is-this-the-most-important-script-youll-ever-write/feed/ 0
yum error: Couldn’t fork Cannot allocate memoryhttp://www.idimmu.net/2014/07/23/yum-error-couldnt-fork-cannot-allocate-memory/ http://www.idimmu.net/2014/07/23/yum-error-couldnt-fork-cannot-allocate-memory/#comments Wed, 23 Jul 2014 10:07:54 +0000 http://www.idimmu.net/?p=880 Yum Couldn't Fork Cannot Allocate Memory I’ve been doing some awesome things to a new VM for work, namely installing CouchDB, Apache and running Node.JS apps along side a WordPress plugin using Angular.JS. It’s pretty cool. But computer’s are dicks so when it came down to installing Monit to ensure everything was lovely I got the following error: Couldn’t fork %pre(monit-5.5-1.el6.rf.x86_64): Cannot allocate memory. Bum.

error: Couldn’t fork %pre(monit-5.5-1.el6.rf.x86_64): Cannot allocate memory

Seem’s simple enough, for whatever reason Yum cannot allocate memory, so lets take a peak

root@bridge opt]# free
total used free shared buffers cached
Mem: 1020376 832736 187640 0 3988 81256
-/+ buffers/cache: 747492 272884
Swap: 0 0 0

Man there’s totally enough memory there, 187MB of RAM is free, Quake took less than that and is way more complicated than some stupid RPMs.. maybe it’s something else!

Quite often this error is caused because the RPM database has duplicates or got corrupted in some way, so lets try and clean that up.

[root@bridge ~]# package-cleanup --cleandupes
Loaded plugins: fastestmirror, protectbase
Loading mirror speeds from cached hostfile
* base: mirror.checkdomain.de
* epel: mirrors.n-ix.net
* extras: mirror.checkdomain.de
* rpmforge: mirror1.hs-esslingen.de
* updates: mirror.checkdomain.de
1490 packages excluded due to repository protections
No duplicates to remove
[root@bridge ~]# rpm --rebuilddb

Well no duplicates and the RPM database is all cool, so lets try again ..

[root@bridge ~]# yum install monit
Loaded plugins: fastestmirror, protectbase

<snip>

Running Transaction
Error in PREIN scriptlet in rpm package monit-5.5-1.el6.rf.x86_64
error: Couldn't fork %pre(monit-5.5-1.el6.rf.x86_64): Cannot allocate memory
error: install: %pre scriptlet failed (2), skipping monit-5.5-1.el6.rf
Verifying : monit-5.5-1.el6.rf.x86_64 1/1

Failed:
monit.x86_64 0:5.5-1.el6.rf

Complete!

Man, haters gonna hate!

Solving error: Couldn’t fork %pre(monit-5.5-1.el6.rf.x86_64): Cannot allocate memory

Ok, lets step back a minute and assume the error is legit, lets turn some stuff off ..

[root@bridge ~]# /etc/init.d/couchdb stop
Stopping database server couchdb
[root@bridge ~]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]

And try again!

[root@bridge ~]# yum install monit
Loaded plugins: fastestmirror, protectbase

<snip>

Downloading Packages:
monit-5.5-1.el6.rf.x86_64.rpm | 267 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : monit-5.5-1.el6.rf.x86_64 1/1
Verifying : monit-5.5-1.el6.rf.x86_64 1/1

Installed:
monit.x86_64 0:5.5-1.el6.rf

Complete!

Sweet that did it. So it was a bonafide legit error and shutting some services down freed up enough memory to allow us to install RPMs again.

root@bridge ~]# free
total used free shared buffers cached
Mem: 1020376 510972 509404 0 11632 146780
-/+ buffers/cache: 352560 667816
Swap: 0 0 0

mmm 509MB free, thats a lot more.. I guess Yum actually needs a ton of RAM to actually do anything. Weird. If you guys get this problem, try turning some services off and on again ;)

]]>
http://www.idimmu.net/2014/07/23/yum-error-couldnt-fork-cannot-allocate-memory/feed/ 0
The Albert Burger – Best Burger in Brighton?http://www.idimmu.net/2014/04/09/the-albert-burger-best-burger-in-brighton/ http://www.idimmu.net/2014/04/09/the-albert-burger-best-burger-in-brighton/#comments Wed, 09 Apr 2014 11:16:23 +0000 http://www.idimmu.net/?p=839 Cheese and Bacon Burger at The Albert It’s rare that I’m genuinely in shock and awe of something, but that’s how I felt last night in The Albert, down under Brighton train station!

The menu came with a crazy amount of options, so for the burger I added bacon and cheese and for the chips, thick cut rather than skinny and chilli and cheese. Not chilli cheese mind, as that was a separate option, as were the beef brisket, hash browns, onion rings, guacamole etc etc etc TOO MANY CHOICES! The entire thing came to £10 on the nose.

I’m actually feeling bad writing this up, as the photos don’t do the burger justice. They don’t show the perfectly cooked centre of the meat, the delicious crisp of the chips and the amazing tenderness of the brisket (at least I think it was brisket, the menu just said ‘chilli’…)! I should probably do one of those Internet courses on food blogging and photo taking or something :(

Cheese and Bacon Burger at The Albert

The burger came with real bacon, the kind of bacon you’d be proud of, and the chilli on the chips? Not the minced beef and stewed kidney bean chilli I was expecting, rather a phenomenal slow cooked beef brisket flavoured with a deliciously spicey concoction.

The entire thing was awesome. Could this be the best burger in Brighton? It’s definitely the best one, hands down, that I’ve had in 2014.

]]>
http://www.idimmu.net/2014/04/09/the-albert-burger-best-burger-in-brighton/feed/ 0
Adsense 2014 April Foolshttp://www.idimmu.net/2014/04/01/adsense-2014-april-fools/ http://www.idimmu.net/2014/04/01/adsense-2014-april-fools/#comments Tue, 01 Apr 2014 11:19:24 +0000 http://www.idimmu.net/?p=814 It’s nice to see that idimmu.net doesn’t just have a global audience but a solar system wide audience too!

Adsense 2014 April Fools

62.% of my site’s earnings come from Europa, thanks for the heads up, Google and happy April fools to you guys too :)

]]>
http://www.idimmu.net/2014/04/01/adsense-2014-april-fools/feed/ 0
Speeding Up MDADM RAID Rebuildshttp://www.idimmu.net/2014/03/26/speeding-up-mdadm-raid-rebuilds/ http://www.idimmu.net/2014/03/26/speeding-up-mdadm-raid-rebuilds/#comments Wed, 26 Mar 2014 16:48:52 +0000 http://www.idimmu.net/?p=807 Speeding Up MDADM RAID Rebuilds I’m slowly migrating a bunch of awesome things from a really old server, it’s still running Ubuntu 10.04.. to a really nice and shiny one. Which has 2 new 3TB HDDs in RAID 1, which are syncing..

cat /proc/mdstat
md3 : active raid1 sda4[0] sdb4[1]
1847478528 blocks super 1.2 [2/2] [UU]
[>....................] resync = 0.1% (2061952/1847478528) finish=28857.9min speed=1065K/sec

That’s like 40 days of syncing.. surely we can do better than that? Can’t we speed up this MDADM RAID 1 rebuild?

Speeding Up MDADM RAID Rebuilds

Sure we can, we’re awesome, I’m awesome, you’re awesome, can I get a hell yeah? HELL YEAH!

Likes lots of things that are tuneable, we have to do NASTY things to /proc. This bit sets the minimum speed we want mdadm to go at.

cat /proc/sys/dev/raid/speed_limit_min
1000

We’re greedy though and in the words of Tim Tool Time Taylor, MORE POWER. As root..

echo 50000 > /proc/sys/dev/raid/speed_limit_min

We’ve just made mdadm run FIFTY TIMES faster. FOR FREE. We didn’t even swap out the SATA disks for SAS SSDs, we just changed a number ..

md3 : active raid1 sda4[0] sdb4[1]
1847478528 blocks super 1.2 [2/2] [UU]
[=====>...............] resync = 26.0% (480866560/1847478528) finish=141.9min speed=160501K/sec

Now 10 minutes later we’re already over 1/4 the way through, 2 hours left baby. Hell yeah.

]]>
http://www.idimmu.net/2014/03/26/speeding-up-mdadm-raid-rebuilds/feed/ 0
authorized_keys vs authorized_keys2http://www.idimmu.net/2014/03/26/authorized_keys-vs-authorized_keys2/ http://www.idimmu.net/2014/03/26/authorized_keys-vs-authorized_keys2/#comments Wed, 26 Mar 2014 14:28:18 +0000 http://www.idimmu.net/?p=803 authorized_keys vs authorized_keys2 Earlier today I was setting up a brand new server for a migration and just as I was typing scp .ssh/authorized_keys2 my brain went and asked a question..

What is the difference between authorized_keys and authorized_keys2?

I’ve been working with Linux for well over a decade and some of my practices stem from things I learned in the ’90s that still work, putting all my public keys in ~/.ssh/authorized_keys2 is one of those things.

authorized_keys vs authorized_keys2

In OpenSSH releases earlier than 3, the sshd man page said:

The $HOME/.ssh/authorized_keys file lists the RSA keys that are permitted for RSA authentication in SSH protocols 1.3 and 1.5 Similarly, the $HOME/.ssh/authorized_keys2 file lists the DSA and RSA keys that are permitted for public key authentication (PubkeyAuthentication) in SSH protocol 2.0.

Which is pretty self explanatory, so that’s what the key difference in the files were originally, authorized_keys for RSA in SSH 1.3 and 1.5 and authorized_keys2 for 2.0

What is the difference between authorized_keys and authorized_keys2?

However, that’s from releases of OpenSSH earlier than 3.0, which was released in 2001, a long time ago.. looking back at the OpenSSH 3.0 release announcement authorized_keys2 is now actually deprecated. We should all just be using authorized_keys instead from now (er, 2001..) onwards!

]]>
http://www.idimmu.net/2014/03/26/authorized_keys-vs-authorized_keys2/feed/ 0
do-release-upgrade Checking for a new Ubuntu release No new release foundhttp://www.idimmu.net/2013/11/23/release-upgrade-checking-new-ubuntu-release-new-release-found/ http://www.idimmu.net/2013/11/23/release-upgrade-checking-new-ubuntu-release-new-release-found/#comments Sat, 23 Nov 2013 20:08:02 +0000 http://www.idimmu.net/?p=795 My HTPC is almost appliance like, in the way I never upgrade it, i.e. this morning it was still running Ubuntu 11.04 Natty Narwhal… It’s also not very appliance like in that it’s also full of random development stuff that probably shouldn’t be on it as well as several different types of databases, my backup infrastructure and tons of other things you really don’t care for.

But not today. Today I was bored and decided the best use of my time was to replace MythTV with XBMC. Not only that, I figured I should probably upgrade from

      Ubuntu 11.04 (Natty Narwhal)
      Ubuntu 11.10 (Oneiric Ocelot)
      Ubuntu 12.04 LTS (Precise Pangolin)
      Ubuntu 12.10 (Quantal Quetzal)
      Ubuntu 13.04 (Raring Ringtail)
      Ubuntu 13.10 (Saucy Salamander)

That’s a lot of upgrading. It would have probably been better for me to just install 13.10 ..

But when I got to Pangolin, the 12.04 LTS EVERYTHING WENT WRONG!

rus@relax:~$ sudo do-release-upgrade -p
Checking for a new Ubuntu release
No new release found

OMG I hear you cry, much like I did. WHAT IS THIS??? I tried everything, apt-get update, turning it on and off again, throwing things at the TV, I even went outside and bought a coffee. None of the above worked. This was because I was stupid.

do-release-upgrade Checking for a new Ubuntu release No new release found

The reason for the error was because I’d arrive at an LTS release. And the do-release-upgrade configuration had changed to now *stick* to LTS releases and not upgrade any more. So as the new 14.04 LTS isn’t out yet (as we’re not in the future, dummy) it couldn’t find anything to upgrade to.

The fix is to tell the computer to just upgrade to the next release and not be so stubborn by editing /etc/update-manager/release-upgrades

# Default behavior for the release upgrader.

[DEFAULT]
# Default prompting behavior, valid options:
#
# never - Never check for a new release.
# normal - Check to see if a new release is available. If more than one new
# release is found, the release upgrader will attempt to upgrade to
# the release that immediately succeeds the currently-running
# release.
# lts - Check to see if a new LTS release is available. The upgrader
# will attempt to upgrade to the first LTS release available after
# the currently-running one. Note that this option should not be
# used if the currently-running release is not itself an LTS
# release, since in that case the upgrader won't be able to
# determine if a newer release is available.
Prompt=lts

See how it says Prompt=lts? THATS JUST RUBBISH! Change it from lts to normal then rerun do-release-upgrade. Theres a good boy!

]]>
http://www.idimmu.net/2013/11/23/release-upgrade-checking-new-ubuntu-release-new-release-found/feed/ 0
Honey Beer Breadhttp://www.idimmu.net/2013/10/27/honey-beer-bread/ http://www.idimmu.net/2013/10/27/honey-beer-bread/#comments Sun, 27 Oct 2013 18:01:36 +0000 http://www.idimmu.net/?p=786 Beer Bread Recipe I gave up drinking 3 months ago, but still have a fridge full of beer which I didn’t want to pour down the sink, so I decided to make something with it. I found My Fridge Food, which is an awesome little site that will take the contents of your fridge and cupboards and suggest recipes! A lot of the recipes were rubbish, poached eggs,

Beer Bread Recipe

I found this honey beer bread recipe from Michelle’s awesome Brown Eyed Baker blog, and armed with a bottle of Desperado totally destroyed my kitchen.

Beer Bread Recipe

Like, completely destroyed it. Flour, everywhere. Mostly on me. But an hour later, I took out of the oven some delicious beer and honey crack.

]]>
http://www.idimmu.net/2013/10/27/honey-beer-bread/feed/ 0
Google Is Becoming Less Relevanthttp://www.idimmu.net/2013/10/15/google-becoming-less-relevant/ http://www.idimmu.net/2013/10/15/google-becoming-less-relevant/#comments Tue, 15 Oct 2013 10:22:14 +0000 http://www.idimmu.net/?p=780 Google Is Becoming Less Relevant Back in September Google released it’s new Hummingbird algorithm, apparently affecting 90% of search queries, as it strives for greater accuracy and more relevant results. Aimed at ‘conversational searches’, like what is the best cake? rather than simple terms such as best cake. (when is the last time you made a search request like that?)

Then on the 4th October they released Penguin 2.1, aimed at reducing the quality of spammy backlinks, I assume the theory is that better sites have better backlinks, (as they have been around longer?) and newer sites, (trying to use spammy backlinks to gain traction?) can’t be as good or as relevant. Fairly naive thinking, though I guess it might help in ‘cleaning up the web’?

Quality Of Results

If Google’s main aim is to provide better quality results. Then lets look in an honest search query that I’ve just made! nginx sip proxy! At work we need to find out if we can proxy SIP through Nginx using web sockets, so this kind of query is the kind of thing I’d use to start my information search!

Google Results

Google Results

The first result from Google, is from the Nginx documentation, but that page doesn’t have the word SIP on it anywhere, so how can it be useful to me? Sure, it’s very authoritative (although actually out of date) about Nginx and HTTP proxies, but it’s the least helpful result ever.

Bing Results

Bing Results

The first result from Bing is more relevant, a topic on the Nginx forums asking about exactly what I’m after.. using Nginx as a SIP proxy. The results after that are also a lot more relevant, other people discussing using Nginx as a SIP proxy!

Google Are Making The Internet Worse

In all likely hood, Google will probably start ranking this page for nginx sip proxy by the end of the day, if they do I will tag everything I learn on to it to make it actually helpful! Google seem to be on a quest to create a really high barrier to entry for new web developers, preferring to return old, out of date information, whilst at the same time dumbing down their search results and losing sight of what made them great in the first place:

  • Clean no frills website
  • Relevant, meaningful content
  • Being a search engine, not a web portal
]]>
http://www.idimmu.net/2013/10/15/google-becoming-less-relevant/feed/ 5
How To Take Control Of Another Computerhttp://www.idimmu.net/2013/10/06/take-control-another-computer/ http://www.idimmu.net/2013/10/06/take-control-another-computer/#comments Sun, 06 Oct 2013 09:37:54 +0000 http://www.idimmu.net/?p=774 how to take control of another computer There are several things to think about when taking control of another computer, the Operating System running on it, the speed of your network connection and the tools you have at your disposal.

How To Take Control Of Another Computer

Operating System

There are 3 main choices of Operating system that the computer you want to take control of might be running, Windows, Mac OS X and Linux. Fortunately Mac OS X is based on BSD so the tools you would use to take control of it are the same as you would for Linux, simplifying things some what!

Network Speed

If you have a fast network it’s possible to use remote desktop tools, such as Windows Remote Desktop, Virtual Network Computing (VNC) or on a Mac or Linux server you can do X over SSH.

How To Take Control Of Another Computer

Windows

To enable Windows Remote Desktop, click the Start button, click All Programs or Programs, and then click Accessories.

Mac / Linux

How To Tunnel X Over SSH

If you want to know how to take control of another computer that has X Windows on it, e.g. a Mac or a Linux machine, but even really old Solaris or other styles of Unix, then you need to make sure the machine you want to take control of has in it’s sshd_config file

X11Forwarding yes

You can then connect to the remote machine with

ssh -X hostname

Then any GUI applications you run via the command line will magically appear locally on your machine.

]]>
http://www.idimmu.net/2013/10/06/take-control-another-computer/feed/ 0