nginx 403 on osx

I’ve got nginx up and running (trying to replace my mamp stack with it) and I kept running into a 403 error regardless of configuration. Turns out this was due to a config error. In OSX, you need to specify a user:group in the nginx config file that match a user that has access to the files you want to serve.

For example, my computer’s user is mengel and my group is staff. My config file is as follows:

user mengel staff;
 
events {
    worker_connections 1024;
}
 
http {
    server {
        listen 80;
        server_name localhost;
        root    /Users/mengel/Documents/Workspace/localhost;
        location /{ 
           autoindex on;
           autoindex_exact_size off;
        }
    }
}

Setting Size on wx.TextEntryDialog in Python WXWidgets

The process of showing a dialog is easy, but making a text prompt for the user that’s more than one line and in which you’re able to see more than one line is a more tricky thing. Here’s the syntax that worked for me.

dlg_msg = 'Hey user! Enter your text below:'
dlg_title = 'This is a title'
dlg_default_style = "{}"
dlg = wx.TextEntryDialog(parent=self.view, message=dlg_msg, caption=dlg_title, defaultValue=dlg_default_style, style=wx.OK | wx.CANCEL | wx.TE_MULTILINE)
dlg.SetValue("default value\non two lines")
if dlg.ShowModal() == wx.ID_OK:
    print(dlg.GetValue())

The vars above the declaration are just for readability. Please note that dlg_default_style is a string, not a dict.

Please note that the default style, though empty, is necessary for the multiline entry to be picked up (at least on OSX)

PHP, Python, GoLang, and Node.js all served by Apache port 80

I dabble in node.js, php, python, and more. Often, these services will produce webservers, and I’d like to try them out in my browser. I also would like to be able to test redirects for things like oauth. In order to get a proper passback from somewhere like Facebook, I need to simulate a full website url without port. It also would be nice to do this without having to shut down one, adjust settings, and restart the other.

The concept:
/etc/hosts or Windows/system32/drivers/hosts will handle incoming request handling to a url

  • Apache handles all requests from port 80
  • Apache uses VirtualHosts to redirect traffic from port 80 to various ports
  • Node/Python/Go/Etc. Will handle requests from specific ports.

An example:
/etc/hosts:

127.0.0.1   local.simplestexplanation.com

This tells your computer that every program that requests data from local.simplestexplanation.com should be forwarded to your computer. This is true for all protocols, http, https, ftp, etc.

httpd.conf:

<VirtualHost *:80>
    ServerName local.simplestexplanation.com
    ProxyPass / http://127.0.0.1:3000/ retry=0
</VirtualHost>

We’ve told apache to create a VirtualHost on port 80. The servername matches the entry in /etc/hosts. The proxypass indicates to where we should forward this request, in this case, to local port 3000. retry=0 tells apache not to cache the results and to always try to serve the page (even if node was down last time)

app.js:

https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(3000);

This is a basic node server using port 3000. If we receive a request to http://local.simplestexplanation.com we should see it handled by node.

Similar servers can be set up in Python, GoLang, etc. And as long as they don’t steal port 80 from Apache, they can handle requests as normal. I’ve found this very useful.

ssh_askpass missing on osx

I recently installed tower on my system and tried to connect to a git repo I use. I don’t have my default password set in git (I like typing passwords), so when it tried to prompt me, I didn’t have a means of telling Tower what my password was. This is an oversight in OSX, but hey, we can fix that. This is the error I received
ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
Permission denied, please try again.

And here’s the language to fix it. Place this code into a file at /usr/libexec/ssh-askpass and make it executable chmod +x /usr/libexec/ssh-askpass and you should be good to go. Tower will prompt you for passwords using a handy dialog.

#! /bin/sh

#
# An SSH_ASKPASS command for MacOS X
#
# Author: Joseph Mocker, Sun Microsystems

#
# To use this script:
# setenv SSH_ASKPASS "macos-askpass"
# setenv DISPLAY ":0"
#

TITLE=${MACOS_ASKPASS_TITLE:-"SSH"}

DIALOG="display dialog \"$@\" default answer \"\" with title \"$TITLE\""
DIALOG="$DIALOG with icon caution with hidden answer"

result=`osascript -e 'tell application "Finder"' -e "activate" -e "$DIALOG" -e 'end tell'`

if [ "$result" = "" ]; then
exit 1
else
echo "$result" | sed -e 's/^text returned://' -e 's/, button returned:.*$//'
exit 0
fi

Add PWD to Bash Default

I grew up with DOS, so call me a throwback user, but when I open Bash on my Mac, I’d really like to know where the heck I am. By default, the prompt shows your computer’s name, then the name of the directory you’re in. This works fine if you never have duplicate directory names, but when I’m doing dev work, I often have multiple windows open for staging/prod/dev work, and they all have the same name as they’re supposed to. This script goes into your ~/.profile file and will change bash to show something like

~/Documents/Workspace/
>

Here’s the code you put into your ~/.profile file (create one if you need to):

PS1="\[\033[0;32m\]\w/\n\[\033[0;0m\]>"

Cannot Trace using Debugger on OSX

Oh good lord, all I wanted to do was trace the output of my flash debug player, yet there was nothing in the usual location. Typically I just run

tail -f ~/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt

in the Terminal and it spits out everything Flash does. The file didn’t exist on my system, so I couldn’t tail it. The solution turned out to be a missing mm.cfg file.
in ~/Library/Application\ Support/, produce a mm.cfg file with the following content:

TraceOutputFileEnable=1
ErrorReportingEnable=1

This, along with a correct debugger, should produce traces.

fl.browseForFileURL won’t work across hard drives

In JSFL, when you use fl.browseForFileURL it returns a URI pointing to the file or folder you’ve chosen. On OX, however, the reference is wrong when you choose a file on a hard drive other than your primary.

Example: I have a hard drive on my mac named HD2. If I browse to a file on there, the URI returned will be

file:///HD2/myFile.txt

If you then immediately try a

FLfile.exists('file:///HD2/myFile.txt')

it returns false. This is due to OSX’s referencing system. the correct location is

file:///Volumes/HD2/myFile.txt

so all we have to do is add the word “Volumes/” to the string and the reference will be correct.

public static function browseForFileURI( title:String = "", type:String = "open" ):String
{
   var ar:Array = MMExecute( "fl.browseForFileURL('" + type + "','" + title + "');" ).split("/");
   ar[2] = "/Volumes";
   return ar.join("/");
}

JSFL 2: Making a Panel

Making a panel in Flash is rather easy, once you find the little bit of information you need. Panels in Flash are just swfs that happen to be in a specific directory.

Windows® 2000 or Windows® XP:
boot drive\Documents and Settings\user\Local Settings\Application Data\Adobe\Flash CS3\language\Configuration\WindowSWF

Mac OS® X:
Macintosh HD/Users/userName/Library/Application Support/Adobe/Flash CS3/language/Configuration/WindowSWF

drop your swf in there, and it should be available in the Windows>Other Panels menu.

Building AS3 Using ANT Scripts

I spent a good chunk of time finding the simplest ANT build script I could and using it to compile my simple AS3 project. This is a simple as it gets:

<project name="build" default="compile">
	<property file="${ant.home}/path.properties"/>
	<taskdef resource="flexTasks.tasks" />
	<target name="compile">
		<mxmlc file="src/AntTest.as" output="bin-debug/AntTest.swf"/>
	</target>
</project>

The project name attribute is up to you.
The default is the target to be run if you just type “ant”
The first property sets basic ANT properties
The taskdef includes Flex-specific information
The target name allows you to reference this action elsewhere in the build file
The mxmlc file is the source for the compiler
The mxmlc output is the output for the compiler
Just replace the as file and swf file with your specific filenames, open up the terminal, browse to the project dir, and type ant
it should produce a swf for you.

Creating a Flash Projector on OSX Bug

I spent a good chunk of time trying to make a projector on OSX from a swf. I opened the swf in Flash Player and went to File and the “Create Projector option was greyed out. I closed it, re-downloaded, nothing I did seemed to work.

Turns out OSX needs a second to think before projectors are an option. Give it a moment and hopefully it’ll turn on.