Friday, August 16, 2013

Icinga bouncing menus


I got annoyed with the bouncing menues in icinga. Basically they added a 'on hover' to the links, that increases the padding.

You can remove it by deleting the jquery hover:

--- /usr/share/icinga/htdocs/js/menu.js
+++ /usr/share/icinga/htdocs/js/menu.js
@@ -18,13 +18,4 @@
         });

     });
-    // Links
-    $("div#menu ul li a").hover(function( e ) {
-        var speed = 200,
-            padding = 10,
-            mode = e.type === "mouseenter" ? "+=" : "-=";
-        $(this).parent("li").animate({
-            paddingLeft: mode+padding+'px'
-        }, speed );
-    });
 });


Saturday, July 6, 2013

Vanilla forums: Batch Decline participants

Our Forum in Kenya was spammed. I had decidd to use vanillaforums as the forum software (a choice I'm not so sure about anymore).

I decided to set the registration as "approval by moderator", which meant that the spam bots were filtered into a "Applicants queue". After ~2-3 weeks the applicant list was 5 thousand.

Clicking each one was not feasible. So I wrote this javascript:

if (typeof String.prototype.startsWith != 'function') {
    "use strict";
    String.prototype.startsWith = function (str){
        return this.slice(0, str.length) == str;
    };
}

var time_wait = 0,
    string_check = '[url=http://',
    action = 'decline',
    forum_url = 'domain.forum.com',
    pause_time = 10000;
$('[type=checkbox]').each(function () {
    "use strict";
    var curelem = $(this),
        parent_group = curelem.parent().parent().children(),
        request_text = $(parent_group[1]).children()[2].textContent,
        key = $($(parent_group[2]).children()[0]).attr("href").split("/").reverse()[0];

    var user_call = function (id, action, time, key) {
        console.log("val = " + id + ", time_wait = " + time);
        window.setTimeout(function () {
            $.ajax({
                url: 'http://' + forum_url + '/user/' + action + '/' + id + '/' + key,
                type: 'POST',
            });
        }, time);
    };

    if (request_text.startsWith(string_check)) {
        user_call(curelem.val(), action, time_wait, key);
        time_wait = time_wait + pause_time;
    }
});

This will go through and fire off an ajax call, which will decline each user. It does this in increments of 10 seconds.

It had to be 10 seconds, because with around 5 thousand applicants, the list was 3M. (I've used up ~2G on our host, just from trying to load this applicants page).

I've created a ticket about this issue:
https://github.com/vanillaforums/Garden/issues/1627

In the meantime if you dont' feel like waiting the 10 seconds, and want to edit php:
Open up 'applications/dashboard/controllers/class.usercontroller.php'
Find 'public function Decline'
The last line of the function is
$this->Applicants();
change this to
$Action = $this->Form->GetValue('Submit');

With this change, the calls took ~400ms, so I changed time (in the script) to 1000.

This worked for me in Vanilla Forums v2.0.18.8

Thursday, March 31, 2011

Using pppconfig with Mobile Broadband

The most stable way to connect to mobile broadband internet connections, is to use pppconfig. This is a brief tutorial on how to do that.

1) Open up a terminal
2) run sudo pppconfig
3) create a connection, and name it something distinctive

4) dns
If you know of good dns address, you can choose static and place them.
Otherwise, choose dynamic

5) Authentication Method
Choose "CHAP" unless you know which you should use.

6) Username and password
Enter the username and password provided with the modem

7) Modem Speed
Leave the modem speed the default that they give you

8) Pulse or Tone
Leave the Pulse or Tone setting, the one that they give you

9) Phone Number
For the phone number enter one of the two numbers below:
*99# if the modem is GSM
#777 if the modem is CDMA

10) Modem Port
For the Modem Port, you'll have to type it in manually:
/dev/ttyUSB0

11) Scroll to "Advanced options" and press "enter"

12) Scroll to "Persist" and press enter
13) Choose "Yes" to enable

14) Once you're finished, scroll to "previous", press enter. Scroll to "Finished" and press enter.
Scroll to "quit" and press enter.


Adding more options to your connection to stablize it:
1) remember the name of your connection that you chose in step three of pppconfig.
2) Alt+f2 for the run prompt, and type:
gksudo gedit /etc/ppp/peers/
3) Add the following text at the end of the file:
==========
lock
lcp-echo-failure 100
lcp-echo-interval 36000
==========
(Don't put the "=" in the file, just what's in between)

4) Save the file and close


Running your connection
1) make sure that your modem is connected *after* the computer is turned on.
2) remember the name of your connection that you chose in step three of pppconfig
3) run "sudo pon " or if you left it default (providers) just run "sudo pon"

Tuesday, March 29, 2011

Installing Software and providing support

One of the big issues that we have as a group of two, running technical support for schools across Kenya is managing to find a way that we can help everyone while not actually being there.

Ok, so we haven't really had this problem too much yet, but I can only imagine how bad it will get.

To fix this problem we've decided that one of the best options is to teach the school how to install; that way if there's a major problem they can just wipe the computers and start over.
This means two things:
1) we have to make our content easily accessible
2) we have to use a distro that is very easy to install and set up.

We've decided that Linux Mint is the best option. Both Linux Mint 9 and 10 look very similar to Windows, and have a simple interface.

So then we just need to teach them how to install basic software after they do the installation from disk, which didn't turn out to be that bad.

Most of our communication is done on-line so that makes it easier also.

This means that the major issues that we might have are with the software that's supposed to save them bandwidth (apt-cacher-ng, and squid) as those are the two complex networking softwares that would be hardest to fix. So far we haven't heard of many examples where schools have had problems with them.

On the other hand of it, another technical guy from the area and I are working together to figure out how we can prepare for the year I won't be here. This involves teaching him quite a bit of linux, since his background is in Windows.
I've found a few resources, nothing amazing, but stuff that might be helpful if someone else was trying to pick it up. For the most part a combination of the Ubuntu manual and the Linux Mint manual have helped, though I'm still hoping to find a good, online, resource for learning Bash and general command prompt commands.

Tuesday, January 5, 2010

Eee PC with Ubuntu (update)

I've done a bit of research today, and got a bit of a better "battery saving" setup for my laptop.

Saving your SSD disk

The default settings for Ubuntu are built to work with a spinning disk. Since you really want your disk to last as long as possible, it's better to minimize the disk writes.
Edit your fstab so that specific directories are sent to memory instead of disk:
tmpfs      /var/log        tmpfs        defaults           0    0
tmpfs /tmp tmpfs defaults 0 0
tmpfs /var/tmp tmpfs defaults 0 0
tmpfs /var/log/apt tmpfs defaults 0 0
From help.ubuntu.com.
The one thing that is annoying though, is anytime you run aptitude, it throws an error about /var/log/apt which it can't make...
So I added "mkdir /var/log/apt" to a start script.

Then You can point different applications to /tmp, for example Firefox:

  • Go to the address 'about:config.'
  • Create a new value 'browser.cache.disk.parent_directory' as a string and set it to '/tmp'
At first I was afraid it would just dump everything there, but don't worry. It makes the folder "Cache" in /tmp

Other Hard Drive tweaks

Another minor fix with the disk is to switch to "deadline". Run:
cat /sys/block/sda/queue/scheduler
and you'll probably get something like:
noop anticipatory deadline [cfq]
Apparently deadline and noop are the options, but deadline is better. Set it to deadline with this:
echo deadline > /sys/block/sda/queue/scheduler
This will need to be a start script.

We can also add FIFO queuing by running the command:

echo 1 > /sys/block/sda/queue/iosched/fifo_batch
Again, this resets on boot, so you'll need to make a start script.

Disabling/Controlling Hardware features

First off, You should install eee-control. The version for Karmic just recently came out, and isn't quite the same now that the developer is declared missing, but it will still turn on and off most of the things you need.

The one thing to note, is that I still haven't figured out how to get wireless to work. It's easy to turn on, but crashes when you turn it off. However, if you turn it off on start up (ie before the gui loads), then somehow it doesn't crash.

In anycase, I like to turn everything off on startup, so I'm going to add the following to a start script:

# camera
echo 0 > /sys/devices/platform/eeepc/camera
# card reader
echo 0 > /sys/devices/platform/eeepc/cardr
# wireless
echo 0 > /sys/devices/platform/eeepc/rfkill/rfkill0/state
That way if I need it, I'll turn it on. If I don't, then it won't use up battery. And Eee-control-tray makes it very easy to enable features when I need them.

Power Management

Ubuntu has some built in things to extend laptop battery life, and still maintain full power while plugged in, but not nearly what it could be.
For example. What if we want to turn our computer's proc the whole way up while we're on AC, turn brightness the whole way up, increase disk writes, and have the screen dim after 10 minutes:
echo 0 > /proc/sys/vm/laptop_mode
# turn brightness up the whole way
echo 15 > /sys/devices/platform/eeepc/backlight/eeepc/brightness
echo 10 > /proc/sys/vm/dirty_ratio
echo 5 > /proc/sys/vm/dirty_background_ratio
echo 500 > /proc/sys/vm/dirty_writeback_centisecs
# screen off after 10 minutes
xset dpms 0 0 600
Well, then we want quite a bit different for when the laptop goes into battery mode.
Check this out:
#!/bin/bash
if on_ac_power; then
# Reset back to normal settings
echo 0 > /proc/sys/vm/laptop_mode
# turn brightness up the whole way
echo 15 > /sys/devices/platform/eeepc/backlight/eeepc/brightness
# disk
echo 10 > /proc/sys/vm/dirty_ratio
echo 5 > /proc/sys/vm/dirty_background_ratio
echo 500 > /proc/sys/vm/dirty_writeback_centisecs
# proccessor on performance
echo 0 > /sys/devices/platform/eeepc/cpufv
# screen off after 10 minutes
xset dpms 0 0 600
else
# Turn on aggressive power savings
echo 5 > /proc/sys/vm/laptop_mode
# turn brightness down the whole way
echo 0 > /sys/devices/platform/eeepc/backlight/eeepc/brightness
# disk
echo 40 > /proc/sys/vm/dirty_ratio
echo 10 > /proc/sys/vm/dirty_background_ratio
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
# proccessor on powersave
echo 2 > /sys/devices/platform/eeepc/cpufv
# screen off after 2 minutes
xset dpms 0 0 120
fi
It just so happens that "on_ac_power" returns true if it's on AC power, and false if it's not.

This should be a power script (/usr/lib/pm-utils/power.d/).

Note: on a clean install this should work, though there have been some issues. Make sure you don't link, but actually copy the script, and have the right permissions. Using the "install" tool is recommended.

Start scripts (and action scripts)

So since this post depends so much on action scripts, here's how to make them.

The folders for the ones we've found today are as follows:

 scripts run on startup:    /etc/rcS.d/
scripts on power (on/off): /usr/lib/pm-utils/power.d
The job is pretty easy. What you need to do is write the script, copy it to the folder, and then set it to be executable (the last two actions can be done with one command: the "install" tool.

First, write the script. In this case I have three start scripts:

S95make_tmp_folders

 # apt log
mkdir /var/log/apt\

S96disk_editing

 # Deadline
echo deadline > /sys/block/sda/queue/scheduler
# FIFO
echo 1 > /sys/block/sda/queue/iosched/fifo_batch

S97turn_off_hardware

 # camera
echo 0 > /sys/devices/platform/eeepc/camera
# card reader
echo 0 > /sys/devices/platform/eeepc/cardr

After each file is written, simple run:

install {filename} /etc/rcS.d/
and the file will be installed to this folder.

In the case of our power script we want it to be run on start up, power flux. So we'll run:


install 99power_save /usr/lib/pm-utils/power.d
install 99power_save /etc/rcS.d
Where 99power_save is the name of the script that we wrote above.

Wednesday, December 16, 2009

Tale of Three Music Players

Once upon a time I used Amarok. Those were the good days. MySql Databases with statistics, etc. Then Amarok 2 came along. I figured out a way to go back to my former love, with the capabilities instead of cheesy looks.
But this didn't last forever, for then I got a Eee PC, and due to my laziness, I didn't install amarok1.4 (the good one). Instead, since I had lost my database, I tested Rhythmbox.

Rhythmbox was good to me for a while. We played many a piece of music together. Then a friend encouraged me to test out Banshee. Banshee did scores just like Amarok did! So I tried it out.

Banshee had everything I would want in a music player. It had scores (though not nearly as good as I had remembered amarok), it handled libraries for videos, and even though I couldn't embed my tags in the videos, it tagged the videos. What Rhythmbox didn't have was a good library organization, and Banshee handled that too! (kinda... it sorta did it while it was going instead of all at once like I would have wanted... leaving half my music sorted and the other half messy in the same folder).

But Banshee was still new, and so didn't have a good relationship with mp3s. In fact, my poor flash drive was being read/written the whole time the song was playing, so I decided that this was reason enough to go back to Rhythmbox. After all, it's the tried and true that keep us going. Besides, Rhythmbox could handle me dropping new files into the folder right away.

Soon, I bought a CD. Without proper CD ripping equipment, I was forced to copy the *.wav files off the CD, and then encode to mp3. But the mp3s were tagless.
So I tagged them in Rhythmbox.
But Rhythmbox couldn't sort them. Instead I had to deal with "Track 1.mp3" files. Which was unacceptable. If I do this with another CD, the files would get replaced!

Then I discovered a program. EasyTag. EasyTag easily tags the mp3s and sorts them.

So I ran it. The mp3s was now organized.

But my playcounts!! They were gone! Rhythmbox couldn't handle the files being in a new location!


So then I remembered my former love. Even without MySql Amarok is superior in all functionality.


Amarok:
  • Score and Playcounts (which happen to be smarter then Banshee)

  • Scripts/Plugins

  • Lyric support (you know... for my Swahili/Kikuyu music)

  • Last.fm Support (+ queuing if offline)

  • Smart Playlists

  • Good Random tool for Playlist

  • Organize Mode

  • Album Cover Organizer

  • (+ A lot of other options.. in 1.4)


Rhythmbox:
  • Playcount

  • Hot Scanning

  • Very stable

  • Random tool for Now Playing

  • Lyric searching

  • Last.fm support (+ Queuing if offline)

  • Easy to add covers to CURRENTLY playing song


Banshee:
  • Playcount/Score (inferior)

  • Lyric support

  • Unstable

  • Last.fm

  • No organize mode, but it organizes...kinda

  • Video Library!

Tuesday, November 24, 2009

Eee PC (Ubuntu)

The Eee PC is quite a effective, and small unit. It's lasted three months in my hands, which is probably a good sign (realizing how I've screwed up the keyboard with soapy-wet hands)

Ubuntu Netbook remix made a big leap in the latest release, also.
Maximus seems more stable, and the layout is quite a bit better.



The main problem is when you switch to Ubuntu there are certain features, like disabling:
- Camera
- Card Reader
- Wireless
That you can't fully control. Sure you can disable the "wireless" in Ubuntu, but the actual wireless card is still on unless you disable it in bios.

eee-control fixes this though.
The version in Jaunty is quite effective. It controls wireless, camera, card reader, brightness, processor and fan speeds, and probably some other things I forgot.

If you like the newest version of Ubuntu (9.10), then you're out of luck. Building eee-control fails.
Rumor has it that the karmic build will be available soon.