Sunday, July 09, 2017

When resources unavail

Every so often my Linux system starts feeling poorly. Firefox will hang and won't let me close its window. So I ALT-TAB over to my terminal window to kill it.

$ ps -fewww | grep -v grep | grep firefox
bash: fork: retry: Resource temporarily unavailable
bash: fork: retry: Resource temporarily unavailable
bash: fork: retry: Resource temporarily unavailable
bash: fork: retry: Resource temporarily unavailable
bash: fork: Resource temporarily unavailable

When this first happened, I figured I would reboot and that, of course, would fix it. But I couldn't even run shutdown! That's when I thought of this extremely inelegant but useful solution:

$ cd /proc
$ kill *

And that freed up enough of whatever that I could get on with the reboot and then with my life.

When it happened today, I googled around and saw saw solutions suggesting...
  • su root and (WRONG: can't su)
  • ps blah blah and (WRONG: can't ps)
  • ulimit (hmmm... OK I'll try that.)
This particular solution suggests setting NPROC (max user processes) using ulimit -u like so:

$ ulimit -a
...

max user processes              (-u) 2047
...

$ ulimit -u 2100

Upping that value allowed me to kill and restart Firefox without rebooting!!

Thanks, IBM!!

Friday, March 24, 2017

Mac + Virtualbox/Linux ALT=CMD

By default it seems that when you run Linux in Virtualbox on a Mac, ALT will be mapped to the OPTION key and SUPER will be mapped to CMD.

It's much more natural to swap these, i.e. to map ALT to CMD.

And here's how you do it:

Create ~/.Xmodmap containing...

clear mod1
clear mod4

keycode 133 = Alt_L NoSymbol Alt_L
keycode 64 = Super_L NoSymbol Super_L

add mod1 = Alt_L
add mod4 = Super_L


And then

$ xmodmap ~/.Xmodmap

Enjoy!

Monday, January 23, 2017

VNC + Mac OS + Option Key = WINNING!!

I love my Macs, but sometimes through no real fault of their own, they can be a bit of a pain in the butt.

Take the Option Key. Very helpful if you're using the Finder.


Ever try using the Option Key when you're connected remotely to your Mac Desktop using VNC? It just doesn't work. VNC settings, nothing.

But I have discovered a solution. Simply turn on Sticky Keys and use the Keyboard Viewer. Now you can use your mouse to press the Option Key - not ideal, but in a pinch, it's better than nothing!

Here are the step-by-step instructions for setting this up:

1. Open up the Preferences


2. Choose Accessibility


3. Turn on Sticky Keys



4. Go back to Preferences and choose Keyboard


5. Turn on "Shoe keyboard and emoji viewers in menu bar"



6. Open up the Keyboard Viewer


7. Now whenever you need to hold down the Option Key, tap it in the Keyboard Viewer


8. If you didn't have Sticky Keys turned on, you'd have to keep it held down in the viewer, but you can just tap it the once. Tapping it again puts it into some other state. Tapping it a third time turns it off. So whenever I want Option, I double click it in the viewer. Then I do whatever it was that needed the Option Key in the first place. And then I tap it again to turn it off.

I hope you find this helpful!

Saturday, December 24, 2016

#selector vs Selector

TLDR: In Swift 3, use #selector instead of Selector (see here).

The warning (No method declared with Objective-C selector 'swipedLeft:') should be your first clue that there's a problem...



If you use this code in Swift 3, the left-swipe will result in an error like this:

2016-12-24 08:15:12.645 SpriteSimpleGame[65853:2987246] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SpriteSimpleGame.GameScene swipedLeft:]: unrecognized selector sent to instance 0x7fb99e4101f0'

Worst of all, examples like this are all over the place because leaving out the colon results in a similar error.

Thanks to this answer I learned that what you want instead is this:

let swipeLeft = UISwipeGestureRecognizer(
    target: self,
    action: #selector(swipedLeft(sender:))
)

Thanks, internets!!

Friday, September 09, 2016

VNC black screen of sadness

Did you connect to your VNC server only to be greeted by a black screen of sadness? 

It happened to me not long ago and I don't know what made me try this, but here's what fixed it:

$ vncpasswd

As always, you're welcome.

Monday, June 20, 2016

Old code, new Xcode

When you download some old code from the Interwebs with such like:

[self.window addSubview:self.viewController.view];

and it runs just fine... and later you update Xcode and start getting runtime errors:

Applications are expected to have a root view controller at the end of application launch

Fortunately the fix is easy:

[self.window setRootViewController:self.viewController];

Thanks, Interwebs!!

Saturday, April 23, 2016

LED Dice!

They cost me all of my diamonds, but I think it was worth it!