Anyone who hasn't updated libao on the mac to 1.1. yet do so now! It fixes those two really annoying bugs concerning playback stopping when hibernating,suspending or (un-)plugging an audio connector.
By the way if you don't know why open source is useful, i think i have yet to find a text that expresses my views on this better than http://www.xiph.org/about/
Wednesday, April 13, 2011
Tuesday, March 29, 2011
HIbernate mac from cli
I forgot to turn off my mac and left the house, so what's a guy to do? Right log in via ssh (having dyndns working is a real plus here) and hibernate it. To do this use the following snippet in a script.
#!/bin/bash
osascript << EOT
tell application "System Events"
sleep
end
EOT
Control apple network profile from the command line
I have to change between a network with a fixed address setup and some others with dhcp quite often, so i was really glad i found out about networksetup. The following snippet switches from the static to the dhcp profile, both of which i defined earlier in the network settings.
networksetup -setnetworkserviceenabled static off
networksetup -setnetworkserviceenabled DHCP on
This is a real time and sanity saver!
Thursday, March 3, 2011
New zsh Prompt
Spring's coming and it's time for a change. I have always liked the idea of colours in the prompt to make you aware of what kind of platform you are working on. Stumbling upon this post inspired me and now here is my version for the zsh:
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)
I have always been a fan of PHP's explode (quite opposed to a lot of other parts of that language) which made me want to recreate it in C. Thinking about the problem i came with a non-equivalent function that i liked better which i thought i should share. It takes a string and a separator on which to split the string up on. The function returns an array of strings that can (and has to be freed) with a single free. This is achieved by reorganizing the array in front of the resulting strings as one continous piece.
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;
}
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
It stood there all alone in the dark. Freezing cold as it was I could not help but emphasize with the poor thing. Of course it was a rather daunting atmosphere; a new moon had just begun its course and the stars were rather dim, the air was cold, the wind was stiff. So there it stood trying to hold its ground alone in the darkness. First I wasn't sure what the flickering light meant but then I came closer. The bulb was starting to show it's age, long hours of service had made it weary and it was gathering the last bit of life in it in a futile attempt to fulfill its duty. It was close to dying but still mustered the strength to try everything and perform honourably during its last fight.
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!
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 just realized it took me insanely long to figure this out and never put it up here in case someone else had the same problem. I have this theory after using original Apple earphones once that they use a preresistor that is just way to big and once you plug something decent in then you just go deaf even on the lowest level of the volume slider.
I then quickly found out about option-shift- but that only gets you down to 2.5% of the volume which is still quite loud in a quiet place. The lowest i have found out how to get to is 1% (and even that is too loud in the library sometimes) and this is how you do it:
#!/bin/sh
osascript -e "set Volume 0.01"
I then quickly found out about option-shift-
#!/bin/sh
osascript -e "set Volume 0.01"
Subscribe to:
Posts (Atom)