reload a file in emacs Apr
05
1
0

You can reload a file in emacs. I typically will come across this situation after I've done a pull.

M-x revert-buffer

comments

how to reload the .emacs file without restarting emacs Apr
05
1
0

If you've made edits to your .emacs file you can reload it without having to restart your emacs.

M-x load-file
~/.emacs

Alternatively you can highlight a region and execute the expression.

c-x c-e

comments

anchoring a footer to the bottom of the html page using css Apr
03
1
0

It's a common need to anchor a footer to the bottom of your web page. It's a tricky problem because you need to account for both large and small content. I've seen people suggest ass-backward ways of doing this with JavaScript. You can achieve this strictly with HTML and CSS with minimal bloat to your markup. All you need is a container div.

Set the height of html and body to 100%, insert a container div with min-height 100% and relative position, and nest the footer with position: absolute, bottom: 0;

/* css */
html, body {
    height: 100%;
}

#container {
    position: relative;
    min-height: 100%;
}

#footer {
    position: absolute;
    bottom: 0;
}


<!-- html -->
<html>
<head></head>

<body>
  <div id="container">
    <div id="footer"></div>
  </div>
</body>
</html>

You might want to add some padding to the bottom of the container so that your content won't run under the footer.

comments

extracting a class name from a python object Apr
01
1
0

You can dynamically extract an object's class name in Python like so:

my_object.__class__.__name__

comments

ssh sftp connection with public key authentication Mar
31
1
0

Depending on how your server is set up you might be required to log into it using a public key (for me I needed this for my Amazon instances). This is fine with SSH, you can just link to it directly when like so:

ssh user@example.com -i /path/to/example.pem

I had a problem with SFTP since it doesn't have the -i option. I got around this issue by associating the public key file to the ssh connection.

Create a <config> file in your .ssh folder, and write an entry similar to the following example:

host example.com
IdentityFile ~/.ssh/example.pem

You should then be able to log in through ssh and sftp without having to specify a public key file since it's automatically associated with the host.

comments

virtualenv pip cheatsheet Mar
31
1
0

Virtualenv and pip install typically go together so I'm combining their cheatsheets. These are the commands I use the most. This is pasted here for quick reference.

# create new virtual environment
virtualenv <name>
virtualenv <name> --no-site-packages

# activate and deactivate virtualenv 
source <name>/bin/activate
deactivate
# pip install
pip install PACKAGE
pip install PACKAGE==VERSON
pip install PACKAGE>=VERSION
pip install PACKAGE --upgrade
pip install -r /path/to/requirements.txt

# pip uninstall
pip uninstall PACKAGE

# pip freeze
pip freeze > requirements.txt

# pip install tar bundle
pip install http://example.com/path/to/tar/package.tgz

# git
pip install -e git://github.com/user/MyProject.git#egg=MyProject
pip install -e git+http://git.myproject.org/MyProject/#egg=MyProject
pip install -e git+ssh://git@myproject.org/MyProject/#egg=MyProject

pip install -e git://git.myproject.org/MyProject.git@master#egg=MyProject
pip install -e git://git.myproject.org/MyProject.git@v1.0#egg=MyProject
pip install -e git://git.myproject.org/MyProject.git@da39a3ee5e6b4b0d3255bfef95601890afd80709#egg=MyProject

# mercurial
pip install -e hg+http://hg.myproject.org/MyProject/#egg=MyProject
pip install -e hg+https://hg.myproject.org/MyProject/#egg=MyProject
pip install -e hg+ssh://hg@myproject.org/MyProject/#egg=MyProject

pip install -e hg+http://hg.myproject.org/MyProject/@da39a3ee5e6b#egg=MyProject
pip install -e hg+http://hg.myproject.org/MyProject/@2019#egg=MyProject
pip install -e hg+http://hg.myproject.org/MyProject/@v1.0#egg=MyProject
pip install -e hg+http://hg.myproject.org/MyProject/@special_feature#egg=MyProject

# subversion
pip install -e svn+http://svn.myproject.org/svn/MyProject/trunk@2019#egg=MyProject

# bazaar
pip install -e bzr+http://bzr.myproject.org/MyProject/trunk/#egg=MyProject
pip install -e bzr+sftp://user@myproject.org/MyProject/trunk/#egg=MyProject
pip install -e bzr+ssh://user@myproject.org/MyProject/trunk/#egg=MyProject
pip install -e bzr+ftp://user@myproject.org/MyProject/trunk/#egg=MyProject

pip install -e bzr+https://bzr.myproject.org/MyProject/trunk/@2019#egg=MyProject
pip install -e bzr+http://bzr.myproject.org/MyProject/trunk/@v1.0#egg=MyProject

comments

local python mail server patch Mar
31
1
0

Sometimes in development it's handy to run a local smtp mail server. This shell script will dump any smtp requests out to the terminal if you point your application to localhost with the correct port.

#!/usr/bin/env sh

python -m smtpd -n -c DebuggingServer localhost:1025

comments

how to type the look of disapproval Mar
30
1
0

Depending on which sites you frequent you might come across the common internet meme the "look of disapproval". I'm on Reddit quite a bit and I see it a couple times a day.

There are times where you might want to respond with the look of disapproval, but how do you type the damn thing?

I'm a long time copy-and-paster, but I've recently took the time to figure out how to make this on my own. Not surprisingly it's fairly straight forward. Of course it differs depending on which OS you're running.

Mac OSX: Option+0CA0
Windows: ALT+3232
Ubuntu: hold Ctrl+Shift U+0CA0

comments

magic file: hide a zip archive inside a jpeg image file Mar
30
1
0

I'm not an expert on file formats so I can't explain why this actually works, but it is possible to append zip files onto a jpeg image. I've been told this works because both .jpg and .zip interpreters are pretty hardy. Word on the street is they both have well defined headers that explicitly locate the relevant bits and ignores any extraneous information, but I can't verify this.

In any case, If you type something like this in the terminal:

cat picture.jpg program.zip > magicfile.jpg

you'll end up with what will look like an ordinary image file that will display just fine on your web page. However, if you change the extension on <magicfile.jpg> to <magicfile.zip> you get a file that you can then unzip; or if you're feeling frisky you can just go ahead and directly unzip the .jpg file.

You can use this to hide files, create unique distribution packages, or land that cute geeky chick in the corner that you've had a crush on all year. I don't know what you'd actually use this for, perhaps sneaking files past your email firewall, but it's nice to know it works.

So venture forth now that I've got you unzipping everyone's jpegs searching for porn archives and password files.

comments

recursively grep through an entire directory Mar
22
1
0

Sometimes it's really helpful if you're searching for a file that has a particular string to recursively grep through a directory.

grep -ir [pattern] [directory]

comments