#!/bin/bash
osascript << EOT
tell application "System Events"
sleep
end
EOT
Tuesday, March 29, 2011
HIbernate mac from cli
Control apple network profile from the command line
Thursday, March 3, 2011
New zsh Prompt
function cnprompt { set -A colours red green yellow blue magenta cyan #black white local col=${colours[$(hostname | cksum | cut -c2-6) % 6]} [[ -n "$SSH_CLIENT" ]] && local sig="%#%#" || local sig="%#" # i am thick at times; i need more warnings :P PS1="%B%(!.%F{red}root@.)%F{$col}%m%f%(?.. %??)%(1j. %j&.):%b %2~%B%(!.%F{red}.%F{yellow})$sig%f%b" }Quick rundown:
- first line sets up an array with the colours that make sense
- second line computes an index into the colours array and sets col accordingly
- I check for whether I am on a local machine or logged in via ssh and double up the last sign
- The main line sets a bold, coloured hostname preceded by a red root@. Then i print the exit code of the last command followed by number of backgrounded processes if any, both of which are a lot more helpful than i first thought. The whole thing ends with the last two dirs in pwd and the var set up in line 3
for host in list; do $((1+$(echo $host | cksum| cut -c1-2) % 6)); doneto find the number combination that would cause the least overlap and gave the colours I preferred to the hosts I use most. I also tried using md5 instead or in addition to cksum but the spectrum it created seemed narrower.
Wednesday, February 16, 2011
Explode (Part One)
When thinking about it I decided to factor out multiple occurrences of the separator instead of inserting Null Strings, which may or may not be desired. One could improve this in several ways like several possible separator chars, a separator of more than one char, a limiting argument,... of course, none of which i need right now. I am planning to write up a couple of other possible implementations over the course of time and discuss their respective merits and benchmark them.
char **explode(const char * source, char sep){
int i =0, j =0;
const char * runner=NULL, *oldrunner=NULL;
int length = strlen(source)+1;
int rlength=0;
char ** resArr = NULL;
char * finalArr = NULL;
if (!(*source)){
return NULL;
}
if (! (resArr = malloc(sizeof(char *) * length)) )
return NULL;
memset(resArr,'\0', length*sizeof(char*));
runner = oldrunner = source;
while (*runner){
if (*runner == sep){
if ( (length = runner - oldrunner) ){
rlength+=length+1;
resArr[i++] = (char *) oldrunner;
}
oldrunner = runner+1;
}
runner++;
}
resArr[i++] = (char *) oldrunner;
rlength += runner - oldrunner+1;
/* this part would be optional if i malloc'ed and strcpy'ed
* above but that way the user only needs to free once*/
if ( !(finalArr = realloc(resArr, sizeof(char *)*(i+1) + rlength)) ){
free (resArr);
return NULL;
}
resArr = (char **) finalArr;
finalArr = (char *) (resArr + ((i+1)*sizeof(char *)));
j = i;
for (i=0; i
/* this of course only works because they are contigous */
length = resArr[i+1] - resArr[i]-1;
strncpy( finalArr, resArr[i], length);
finalArr[length] = '\0';
resArr[i] = finalArr;
finalArr += length+1;
}
strcpy(finalArr, resArr[j-1]);
resArr[j-1] = finalArr;
return resArr;
}
Tuesday, February 15, 2011
Shine a little light
Compassion filled me and I was trying to remember when i had last seen as much grandeur in my own life, let alone on myself. I was moved and wanted to help, but what could a simple person like me do? Still I moved on seeing I was not worthy staying in its presence about it.
To my surprise it was still fighting the next time I came to this place two days later and I could all but stop and wonder. It's pride and endurance were beyond my mental grasp i must say. I wished it well, moved on thinking about it for a very long time.
The next time i got there it was replaced by a younger recruit so it must have died in the meantime, but i am sure it was with honour. I thus vowed to pay my respects to it by trying to take it as an example and I encourage everybody to do the same!
Tuesday, February 8, 2011
Setting the MacOSX volume really low
I then quickly found out about option-shift-
#!/bin/sh
osascript -e "set Volume 0.01"
Wednesday, February 2, 2011
ipv4 exhaustion
As you are hopefully aware IPv4 is on its way out and we reached a major milestone yesterday. Up until monday IANA had seven /8 subnets(that's a a bit under 17 million adresses each) left. On Tuesday APNIC requested another two, which let the number drop to the treshold agreed upon in advance on which the remaining five subnets will be distributed, one to each of the RIR's(Regional Internet Registries). That means yesterday every RIR got one last /8 Block, APNIC got three and that's it. Every IPv4 address that willl be requested once these blocks have been used up will have to come from some previous allotment.
How long will this last on the RIR level?
First you have to look at the rate with which the addresses were given out until now. As you can see the rate was about 10 /8's per year, of which only a neglegible amount was used by AFRINIC(Africa) and LACNIC(South America) (overestimate with 10%). On average RIPE(Europe) and ARIN(North America) use about equal amounts and together about as much as APNIC(Asia and Pacific) does. So that means APNIC, RIPE and ARIN will need about 4.5, 2.25 and 2.25 /8 networks over the course of next year if demand stays exactly the same.
Given that the good is becoming rarer this is unlikely as consumers will probably start hoarding. So given this increase in demand and estimating RIPE and ARIN to have a spare of about 1 /8 left over that would mean APNIC will be the first RIR to run out for good until September at the latest, shortly followed by RIPE and ARIN. LACNIC will likely run out early 2012 and AFRINIC probably will last longest given their low local demand.
What happens then?
Most likely it will be an ugly patchwork of a routing mess and a rather small bazaar for the unused parts of previous allocation that were simply to big for the organization getting them to be used up sensibly. I don't think this will scale to very small subnets since this will put too much demand on the routing infrastructure, so this market is a lot smaller than a lot of people estimate right now, although it will surely be amusing.
Apart from that there will be a rush to get IPv6 out to the public which will fail in a lot of entertaining ways and i am certain will be blamed on the short time frame that this had to be done in (a ludicrous claim that will be uttered for sure). A minor number of people will sit in the dark and wonder why a few websites won't work but overall won't notice anything wrong.
What does it mean?
PARTY! The dog days are over. Well at least to some degree I hope. I am really looking forward to what will hopefully be a global shared address space with hopefully less routing issues, NATing, masquerading and all that other fun stuff. I am sure someone will come up with some unbelievable abomination to ruin the fun but let's enjoy utopia while it lasts
If now my dorm and my work place (a scientific institution) would consider running ipv6 I'll be overjoyed.