Category: Computers

Quick and dirty bash script to apt-get update all OpenVZ containers

By , 2011-11-30 22:29

It’s a bit of a pain having to run upgrades on all servers. I could of course, set up unattended upgrades, but I always liked initiating the upgrade process myself. So I wrote a little bash script that will initiate apt-get update and apt-get upgrade on all running OpenVZ containers.

Note that this only works for Debian-based distros. So Debian, *buntu, Linux Mint and the like.

It’s very rough, no error-handling or safeguards, so use at your own risk. Works for me, but YMMV.

#!/bin/bash
#Delete temp file
rm /tmp/tmp-script.sh
#Get running VZ
CTIDS=$(vzlist | awk '{print $1}' | sed -e '/CTID/d' -e ':a;N;$!ba;s/\n/ /g' )
# Echo list of running IDs
echo "$CTIDS"
CTIDarray=($CTIDS)
for x in ${CTIDarray[@]}
do
    echo "#/bin/bash" > /tmp/tmp-script.sh
    chmod +x /tmp/tmp-script.sh
    echo vzctl exec $x "apt-get update &&;  apt-get -y upgrade" >> /tmp/tmp-script.sh
    screen -d -m /tmp/tmp-script.sh
done
#Delete temp file
rm /tmp/tmp-script.sh
#Show running screens
screen -x

First, we rm the /tmp/tmp-script.sh. Starting off with very bad form, I know, feeling lazy right now. Then I use awk and sed to get the IDs of running containers from the output of the vzlist command, and place them on a single line, separated by spaces. Those IDs are than put in an array, so that the update command can be called using a for loop.

For some reason, I couldn’t get screen to launch the

vzctl exec $x "apt-get update &&  apt-get -y upgrade"

command directly, hence the hideous use of a temp file. If anyone can fix/improve this, I would be glad to hear from you!

Screengrab for Firefox

By , 2011-11-23 23:04

Update: Here are a few alternatives that use Webkit:
http://derailer.org/paparazzi/
http://cutycapt.sourceforge.net/

Just discovered an old but good add-on for Firefox: Screengrab.

Unfortunately the author has discontinued development, citing that he was unable to keep up with the increased pace of Firefox development.

Fortunately, the extension still works great on Firefox 9.0 beta with the good ol’ install.rdf edit. I’ve attached it below, along with an example screenshot produced by Screengrab.

screengrab-0.96.3-maxVersionmod.xpi

(Right click and download or open image in new window/tab for full view)

Fix scrolling in GTK apps (Pidgin) on Windows

By , 2011-11-15 18:45

Synaptics makes great touch technology. Their performance and drivers have always been, in my experience, much better than their Alps counterparts.

Except in one specific situation: using the trackpad’s edge scrolling feature in Pidgin.

Turns out the problem is because the Synaptics touchpad enhancer app displays a custom cursor while scrolling in such a way that prevents GTK apps from reading the scrolling action. Not sure on what end the bug is, but the good news is there’s a simple registry fix:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Synaptics\SynTPEnh]
"UseScrollCursor"=dword:00000000

Either copy-paste the above into Notepad and save as “DisableSynTPCursor-FixScrollPidgin.reg” or something less complex, and import it into the registry. Or make the change manually.

Fix thanks to mindelirium88. http://developer.pidgin.im/ticket/10768

Letter to Apple re: Multi-monitor support in Lion

By , 2011-10-29 11:05

I would like to report that the multi-monitor support is very broken in Lion, specifically with full-screen apps.

Full-screen apps are great, it’s nice to have an immersive view of content, however the user needs to be able to choose which display the full-screen app appears on.

On my MacBook Pro, I like to keep the built-in display as primary, but sometimes would like to have Quicktime or iPhoto full screen on the external display. In Snow Leopard, this was possible, however in Lion there is no way to make apps full screen on the external display.

Another problem is that making any one app full screen makes all other connected displays useless. My Mac Pro has 3 displays connected. Lion makes it impossible to say, watch a video in Quicktime full-screen on one monitor while simultaneously checking mail or browsing the Web on another. I’ll admit, there is a solution to this problem: not using any Apple apps. VLC is able to go full screen on one monitor with Firefox full screen on another and leaving my other display available for use.

Apple, please fix this, or this Mac Pro will be my last, and it will be running Snow Leopard for the rest of its lifetime.

If you agree, please submit feedback to Apple at http://www.apple.com/feedback/macosx.html

Quick bash script to restore all OpenVZ dumps

By , 2011-10-05 22:57

This script will read the container ID from the file name, and use it to restore the tgz dump to the same ID on the new OpenVZ/Proxmox server.

Note that this only works if the default name for the vzdumps is kept, and it only works for the next 89 years, because I’m lazy.

Thanks to
http://www.cyberciti.biz/faq/bash-loop-over-file/ and http://bashcurescancer.com/10-steps-to-beautiful-shell-scripts.html

#!/bin/bash
VZDUMPS=/path/to/backups/*.tgz
for f in $VZDUMPS
 
do
        f2=${f#*openvz-}
        VEID=${f2%-20*}
        echo "Restoring $f to $VEID"
        vzrestore $f $VEID
done

Add Google search provider to IE or Firefox

By , 2011-10-02 15:08

Use this link to add the default Google search provider to IE or Firefox. Useful for IE, or Firefox on Linux Mint.
For Firefox:Google.xml

For IE: MS-Google.xml

CNet Download.com hosting adware/malware

By , 2011-09-23 12:29

I had noticed this a little while ago, but it seems they’re stepping it up.

Seriously, does CBS have no better revenue generation method than to install crapware on people’s computers?

See for example Pidgin Portable: http://download.cnet.com/Pidgin-Portable/3000-2150_4-10834880.html?tag=mncol;3

and this post on UltraVNC forums

https://forum.ultravnc.net/viewtopic.php?f=6&t=28692

Modified photo.html.php for widewind gallery3 theme

By , 2011-09-20 23:49

This enables dynamic resizing of the photo displayed, and enables the pseudo-lightbox popup to view the “full” resized image for users that can’t view the true full image.

< ?php defined("SYSPATH") or die("No direct script access.") ?>
 
<!-- Use javascript to show the full size as an overlay on the current page -->
<script type="text/javascript">
  $(document).ready(function() {
    full_dims = [< ?= $theme->item()->width ?>, < ?= $theme->item()->height ?>];
    $(".g-fullsize-link").click(function() {
      $.gallery_show_full_size(< ?= html::js_string($theme->item()->file_url()) ?>, full_dims[0], full_dims[1]);
      return false;
    });
    resize_dims = [< ?= $theme->item()->resize_width ?>, < ?= $theme->item()->resize_height ?>];
    $(".g-resized-link").click(function() {
      $.gallery_show_full_size(< ?= html::js_string($theme->item()->resize_url()) ?>, resize_dims[0], resize_dims[1]);
      return false;
    });
    // After the image is rotated or replaced we have to reload the image dimensions
    // so that the full size view isn't distorted.
    $("#g-photo").bind("gallery.change", function() {
      $.ajax({
        url: "< ?= url::site("items/dimensions/" . $theme->item()->id) ?>",
        dataType: "json",
        success: function(data, textStatus) {
          full_dims = data.full;
        }
      });
    });
  });
</script>
<style>
img.g-resize {
        width: 100%;
        height: auto;
}
</style>
<div id="g-item">
  < ?= $theme->photo_top() ?>
 
  < ?= $theme->paginator() ?>
 
  <div id="g-photo">
    < ?= $theme->resize_top($item) ?>
    < ? if (access::can("view_full", $item)): ?>
    <a href="<?= $item->file_url() ?>" title="< ?= t("View full size")->for_html_attr() ?>">
    < ? else: ?>
        </a><a href="<?= $item->resize_url() ?>" title="< ?= t("View full size")->for_html_attr() ?>">
    < ? endif; ?>
    < ?= $item->resize_img(array("id" => "g-item-id-{$item->id}", "class" => "g-resize")) ?>
        </a>
    < ?= $theme->resize_bottom($item) ?>
  </div>
 
  <div id="g-info">
    <h1>< ?= html::purify($item->title) ?></h1>
    <div>< ?= nl2br(html::purify($item->description)) ?></div>
  </div>
 
  < ?= $theme->photo_bottom() ?>
</div>

How to dynamically resize an image using CSS

By , 2011-09-20 23:03
 <style> 
img.g-resize { 
        width: 100%;
        height: auto;
}
</style>

Where g-resize is the class assigned to the img you want to have dynamically resized.

Thanks to http://michelf.com/weblog/2005/liquid-image/

How to recursively delete files matching a pattern

By , 2011-09-13 09:45

cd to the folder, run :

$ find . -name '*attach*' | xargs rm

where attach is the keyword present in all filenames to delete.

Custom theme by me. Based on Panorama by Themocracy