Stay.app’s “Restore All Windows” command from Applescript

If you want to use applescript to run cordlessdog.com‘s Stay.app command “Restore All Windows” command from Applescript, here is how to do it:

tell application "Stay"
    set resultBoolean to restore all windows
end tell

Stay.app’s “Restore All Windows” command from Applescript

Stay.app supports 5 applescript commands which are:

  • restore active application windows
  • restore all windows
  • store active application windows
  • store active window
  • store all windows
Posted in Mac, Tech Tips | Leave a comment

Ruby’s RVM, Shebang, dotfiles, and cron

When attempting to run cron files, and files remotely via SSH there were some issues. My default shell is zsh and the rvm setup is pretty standard too. ( Assuming that you already have rvm installed )

From the documentation page there is this note:

There are five startup files that zsh will read commands from:

$ZDOTDIR/.zshenv
$ZDOTDIR/.zprofile
$ZDOTDIR/.zshrc
$ZDOTDIR/.zlogin
$ZDOTDIR/.zlogout

If ZDOTDIR is not set, then the value of HOME is used; this is the usual case.

In the /etc/zsh/zprofile file there was a line that did this:

test -f /etc/profile.d/rvm.sh && source /etc/profile.d/rvm.sh

I commented that line out, which is loaded for interactive shells, and moved it instead to /etc/zsh/zshenv which is loaded for both interactive and non-interactive shells.

This allows us to add the shebang #!/usr/bin/env ruby to the top of my .rb files, do a chmod +x and then run them directly ( eg: $ ./my-script.rb )

I don’t know if that is the most “proper” way of getting my scripts to work but it seems to work well for me.

For cron jobs ( in the file edited by crontab -e ) you may want to add something like this as your first line:

SHELL="/usr/bin/zsh"

That would basically change the default shell for cron jobs. Again, your milage may vary and this probably won’t work on shared hosting platforms.

You can also check your setup to make sure that rvm is installed correctly by typing rvm info – if it gives you any errors search for solutions and fix them. If that command is not found then you probably need to install rvm again ( or perhaps try logging out and logging in again )

Posted in Uncategorized | Leave a comment

Chrome Breaks Custom Search Engines – version 37.0.2062.94

Google Chrome version 37.0.2062.94 breaks custom search engines. Yep, that’s right. If you had added custom search engines ( and custom shortcuts ) in your Chrome preferences they will not work in incognito mode with this version of Chrome, at least on Mac OS X. This has been an issue even with this version of chrome was in BETA mode, but now it is also affecting the “stable” version.

It may be worth it to downgrade to an older version of Chrome. If you do this you may get the message about “Your profile is from a newer version of Google Chrome” but that can easily be remedied. ( just search for the message )

Posted in Mac | Leave a comment

Install mitmproxy from source on Ubuntu

If you want to live on the dangerous side, you can install mitmproxy from its master branch. If you encounter any bugs, please do us the favor and report them on the Github issue tracker briefly.

Install from source using PIP

pip uninstall mitmproxy netlib
pip install git+https://github.com/mitmproxy/netlib.git@master
pip install git+https://github.com/mitmproxy/mitmproxy.git@master

Install from source on Ubuntu

Installing mitmproxy master from sources on stock Ubuntu – first uninstall using:

pip uninstall mitmproxy netlib

Now install the required tools:

$ sudo apt-get install -y build-essential libssl-dev libffi-dev python-dev python-pip libxml2-dev libxslt-dev git

Now install with sudo:

$ sudo pip install git+https://github.com/mitmproxy/netlib.git@master
$ sudo pip install git+https://github.com/mitmproxy/mitmproxy.git@master

Now start up a python console and paste in these two commands – this is a workaround for issue 32 :

$ sudo python  #
>>> from netlib import certffi
>>> exit()

Source: github gist

Posted in Linux | Tagged , , | Leave a comment

Install syslinux 3.86 on Ubuntu

Get the syslinux 3.86 download from here, maybe the syslinux-3.86.tar.gz file

To build syslinux-3.86 on Ubuntu, Debian, and similar:

apt-get install build-essential nasm
cd /tmp
wget "https://www.kernel.org/pub/linux/utils/boot/syslinux/3.xx/syslinux-3.86.tar.gz"
tar -xf syslinux-3.86.tar.gz
cd /tmp/syslinux-3.86
make

you will most likely get some errors about building for windows, but when this process finishes you will have the 3.86 version of syslinux working.

Execute the main program by running:

/tmp/syslinux-3.86/linux/syslinux

You can also do a make install but that may conflict with other versions of syslinux you have installed ( if you have already tried apt-get install syslinux, for example)

Another note, you can run apt-get install syslinux-legacy to get a version of syslinux that is around 3.63 to 3.82:

Check all of the versions by doing something like this:

$ which syslinux
/usr/bin/syslinux
$ strings /usr/bin/syslinux | grep SYSLINUX
SYSLINUX
SYSLINUX 4.05
SYSLINUX 4.05 20140113
$ which syslinux-legacy
/usr/bin/syslinux-legacy
$ strings /usr/bin/syslinux-legacy | grep SYSLINUX
SYSLINUX
SYSLINUX 3.63 Debian-2012-04-16
$ strings /tmp/syslinux-3.86/linux/syslinux | grep SYSLINUX
SYSLINUX
SYSLINUX 3.86 0x53e5a115
Posted in Server Admin | Leave a comment

ThinkCentre M83 (10AK) Linux Network Driver

The IBM ThinkCentre M83 ( types 10AG, 10AK, 10AL, and 10BE) have the Intel I217 / L217LM Clarkville according to their spec sheet

Their driver download page does not have a linux network driver.

However, the Intel Download Center provides a driver that should work for these machines.

Posted in Uncategorized | Leave a comment

Fail2ban: Block CIDR IP Address Ranges (aka wildcard)

It has been requested to have the ability in fail2ban to block whole IP address ranges.

Yaroslav Halchenko replied, saying

we are working on the features which would occur in some 0.9.x release which would make it configurable out-of-the-box, but meanwhile you can just easily create an augmented action file where you would have customized iptables call with /XX to ban whatever big subnet you like

Well, at the time of this writing the current version is Fail2Ban v0.8.6 – and it seems to not have CIDR capabilities out of the box. However, you can still have fail2ban block an IP address by using a command like this:

fail2ban-client -vvv set apache banip 1.2.3.0/24

Your fail2ban log file ( maybe /var/log/fail2ban.log ) should have information about the rule you just added. Also, the -vvv flag tells the command to be verbose.

For the rule to take effect, you may need to wait until one of the other files fail2ban is monitoring has a change. So check out your /etc/fail2ban/jail.local file, see what is enabled, and then run touch /path/to/file on a logfile you are watching with fail2ban

Posted in Server Admin | Leave a comment

How to use http_get_request_headers with PECL_HTTP version 2

If you’re using the version 2 pecl_http (possibly version 2.0.6?) on your webserver, perhaps Ubuntu or CentOS, with PHP5, maybe 5.3, 5.4, or 5.5, you may have noticed that after getting it all installed and adding this to your php.ini file:

extension=raphf.so
extension=propro.so
extension=http.so

But then when you try and use the function get_request_headers() you end up getting:

PHP Fatal error: Call to undefined function http_get_request_headers()

Well, when this extension switched to pecl/http v2 it changed a lot of things, and global functions was one of them. It now uses namespaces, and so instead of using http_get_request_headers() you’ll need to use something like this:

$headers = \http\Env::getRequestHeader();
print_r($headers);

The check out the docs for more details on how to use the new function, basically you’ll see

getRequestHeader: Retrieve one or all headers of the current HTTP request.

Parameters:

Optional string $header_name

The key of a header to retrieve.

Returns:

  • NULL, if $header_name was not found
  • string, the compound header when $header_name was found
  • array of all headers if $header_name was not specified
Posted in Web Development | Tagged , | Leave a comment

How to install pecl pecl_http with homebrew php54 / php55

You may be tempted to try and run pecl install pecl_http if you’re using homebrew on Mac OS X in order to be able to access functions like http_get_request_headers – but there’s a better way. Instead, try using the command brew install php54-http or brew install php55-http ( depending on if you are using php 5.4 or php 5.5 with homebrew )

You can get more info about pecl_http with homebrew by using brew info php54-http or brew info php55-http ( again depending on your PHP version ).

If you have already tried pecl install pecl_http you may want to run pecl uninstall pecl_http before running the other commands.

If you have previously used something like brew install php54-http and now it doesn’t seem to be loading, check your configuration file in /usr/local/etc/php/5.4/conf.d or try doing:

brew remove php54-http

And then running:

brew install php54-http
Posted in Tech Tips | Tagged , | Leave a comment

zshell: rsync hostname completion with zsh

If you use ssh a lot with zsh and have a lot of entries in your hostsfile (/etc/hosts) you might find it convenient to disable completion from these hosts by using:

zstyle ':completion:*' hosts off

However, this may give you adverse affects, and your hostnames may stop auto-completing with rsync – in order to fix this try also adding this in to your .zshrc

zstyle -s ':completion:*:hosts' hosts _ssh_config
[[ -r ~/.ssh/config ]] && _ssh_config+=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p'))
zstyle ':completion:*:hosts' hosts $_ssh_config

If you also use oh-my-zsh and are still having trouble, trying adding those lines after this line:

source $ZSH/oh-my-zsh.sh
Posted in Tech Tips | Tagged , | Leave a comment