Vim and system clipboard in Arch

There’s something that has always anoyed me when using vim: I couldn’t seem to access to the system’s clipboard. Copy (or yank) would work great as long as I didn’t try to copy something outside of vim. This, of course, is a problem. After a long time of simply trying to ignore the problem after a few failed attempts to try to solve it, the solution basically came upon me. Someone on the Arch linux subreddit had the same problem I did.

Turns out vim doesn’t pack with +xterm_clipboard on Arch Linux. Why? Your guess is as good as mine. This option is necessary for accessing the system clipboard.  So you have two options: either you compile vim by yourself with +xterm_clipboard, or you can install gvim.

# pacman -S gvim

This will tell you vim and gvim are in conflict. This is intended behavior, just go ahead: you’ll still have vim (plus gvim, the graphical interface of vim) installed after pacman finishes.

Now you can edit your ~/.vimrc file and add a line that maps Ctrl+C in visual mode to “copy selection to the system clipboard”.

vmap <C-c> "+y

Restart vim and that should be it.

BTW, if when you copy something to vim the indentation gets all crazy, this plugin will fix it right away.


twitterImgBot: almost useful now

My twitter image bot has evolved a lot through the last couple of months. I’ve been mostly working on it through one-day coding sessions when I felt like it, but it has gone from a ultra simple script to a somewhat more robust solution for anyone who wishes to tweet a lot of images to an account.



Just a couple days ago I uploaded a new version to github. This will probably the last. I honestly don’t think there are more features to add at this point, or at least nothing I need for my pet project @gentelindaOK. Maybe (if I someday feel like it) will add the option to control the bot via direct messages. The problem with this is that twitter API is giving me an ‘access forbidden’ error no matter what I try, so for now that’s a no-no.

This is the feature list:

  • Separate config file. You don’t have to touch a line of code.
  • Commands: set up a ‘master account’ and ‘ban command’ and ban images so the bot deletes them from twitter and never posts them again.
  • Request: any user can request an image with a request_command. they can also request an image for another user as a gift.
  • Custom answers: a list of possible text answers to requests can be given.
  • No repeat: bot will not repeat images! you can set the tolerance in the allow_repeat_after setting in the config file.
  • Execution chance makes it possible to run the script every minute to check for requests and commands while not posting. This way the script doesn’t have to run on the background. Make it higher if you want your bot to tweet more often!
  • Ideal for setting up a bot at home: you don’t need a server; just python and a bunch of images in a folder.

Now, get the code and get your bot up and running.

twitterImgBot: a simple image twitter bot

I released the first version of my small image twitter bot some months ago. But it was still quite incomplete, and the code was pretty ugly. Some days ago, I improved on my creation. It is still not very complicated, but it can sure be useful: @gentelindaOK is still going strong only depending on this small script running on my computer. Compared to the previous version, the script now features:

  • Cleaner code! 
  • Random time interval between twitts! You can now set an execution chance for the script, which allows for more human-like behavior.
  • A separate config file where you can set you API tokens and keys, the source folder and the execution chance of the bot

You can find the new version on github.

I have also commited my modification of HoverHell’s RedditImageGrab so it can now take multireddits as an argument. HoverHell hasn’t accepted my pull request yet, but you can find it in my own repository. This is very helpful when you want to build your source folder: just suscribe to Reddit, browse around for some image-oriented subreddits, create a multireddit for them and command RedditImageGrab to fetch you the images posted.

As I had previously stated, ideally you should use a task scheduler (for Linux users cron works great) to set up the execution of the bot and the image fetcher. It is recommended to have a Duplicate Files remover too. You’ll also need Python and Tweepy installed.

Access your localhost even if your IP changes

Have you ever wanted to access your localhost from outside your local network but found it difficult because your ISP set you up with a dynamic IP? I have. my Couchpotato setup was working nice and swiftly on my local machine, but trying to access it from outside my local network was frustrating. Sure, I could check my public IP, write it down somewhere and everything would be fine… until it didn’t work.

Like most people, I have a dynamic IP. This is annoying because there’s no reliable way to access your computer from outside the local network if you don’t have an static IP. Unfortunately, there’s no way to fix this as it depends on our ISP.

But there’s a way to work around it. The bad news? You’ll need a server, or someone who can lend you some tiny space in one. You could also figure a way to have your IP sent to a service like pastebin, but it wouldn’t be as comfortable because you’d miss the redirection from one simple URL to your localhost Also, terrible news of this method: you’ll need to store your fpt password in plain text in a file in your local machine. This could be avoided using scp, but my hosting doesn’t allow for ssh use so I have to be happy with this.

Anyway. We first need a way to figure out or public IP and upload it to a server. Turns out this is pretty easy with a bash script. It uses a here document code block, which are pretty interesting so you should give that page a read. I took it from this Stackoverflow answer.

#!/usr/bin/env bash

baseIP=$(curl -s
echo "$baseIP":5050 > ./myIP

ftp -n *url* <<END
user *user* *password*
cd *folder*
put ./myIP

The script uses, which is very convienen cause it returns your IP without ads or even formatting, just plain text. Once it has your IP, it appends :5050 to the end of it and writes it to the myIP file. The :5050 is there because that’s the port Couchpotato uses.

It then open ftp to an url and gives the ftp program the input between <<END and END, line by line. That’s the already mentioned here document block.

Of course you should replace url, user, password and folder with your own.

Now, that’s very pretty but we haven’t achieved much. There’s one step missing that will make this very practical. You should have a little php file inside the folder where you upload the file with your IP that redirects the user to the desired IP. Turns out this is pretty simple.

$myIP = fgets(fopen("myIP", "r")) or die("Unable to open file!");
header("Location: http://$myIP");

And that’s it! You could set up redirection so you don’t actually have to write the URL to the php file but instead just to a folder for maximum convenience. But that’s about it.