Friday, September 13, 2013

Downloading and trimming clips

There are two ways to download the clips, and get them the converted for Mythtv (the right times, etc)

1) twitchtv:
# youtube-dl "http://www.twitch.tv/riotgamesoceania/b/457578762"
downloads many parts
# for i in *.flv; do echo "file '$i'"; done > inputs.txt
# ffmpeg -f concat -i inputs.txt -c copy output.mp4

Youtube doesn't need this, because they show up as one file. However, they do still need to be trimmed. If you need to trim it then, mark the times.

For example:
'input.webm' start: 5:27:00 end: 8:28:28
Then you can convert the file with ffmpeg:
# ffmpeg -y -ss 5:27:00 -t 3:01:28 -i 'input.webm' -c copy 'output.webm'

Monday, September 2, 2013

Django logging

Django has a pretty configurable logging facility.

The other day I had to customize error emails in django.

I did this by copying django's AdminEmailHandler, to a local file, and then pointing the logging utility to this.

The django guide has a large configuration that you can strip. Let's strip it down to this:

LOGGING = {
    'version': 1,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
    },
}
 
Note the default configuration for the class. This is also where you copied the AdminEmailHandler. Point it to the new location that you saved it. I wasn't sure of a good place so I saved it in 'project/middleware/custom_email.py' and referenced it: "project.middleware.custom_email.AdminEmailHandler"

Now all you need to do is change the email handler to return emails the way you want. I stripped out the file so that it was just the classs and the required dependancies, because I didn't want to override other things that I didn't need to.

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.