Search posterous

Search all posts and users. Type a name, type a favorite song title, whatever! See what comes up.
  

More posterous blogs











More recommended blogs »

Here are posterous posts filed under script...

Tocki says...

Filed under: script

Tocki says...

Filed under: script

mlevit says...

Changelog:

  • Fixed: Changing the @include in v2.19 actually stopped the script from working anywhere but the homepage (i.e. all other months but the current one would no longer work).
  • Added: New showSearchAlias array. Some shows may show up different on TV Calendar than they do on ezRSS (TV Calendar displays Law & Order: SVU, ezRSS displays Law & Order: Special Victums Unit). This new array can hold the TV Calendar version of the show name and the ezRSS version of the show name. If some shows like the Law & Order: SVU have this difference, you can add them to the new showSearchAlias array.

Detailed Description:

A problem was pointed out by a user that existed with the ezRSS search link. There is a discrepancy between the show name displayed by Calendar for TV and ezRSS. Shows like Law & Order: SVU are actually displayed as Law & Order: Special Victims Unit on ezRSS. What this means is the ezRSS search link my script would produce would insert the show name Law & Order: SVU, which would yield no results on ezRSS. A secondary problem was also found where instead of the ampersand sign (&) the script would retrieve (&) which is the HTML code for the ampersand used in order for the actual symbol to be displayed on the webpage. For this and the problem before I came up with a few fixes.

To fix the ampersand symbol a new HTMLSymbol "class" was made consisting of two variables. html represented the HTML code (e.g. &) and symbol represented the actual symbol (e.g. &):

function HTMLSymbol ()
{
    this.html = "";
    this.symbol = "";
}

On startup a new array would be created of type HTMLSymbol and populated:

var htmlNameToSymbol = new Array();
htmlNameToSymbol[htmlNameToSymbol.length] = new HTMLSymbol();
htmlNameToSymbol[htmlNameToSymbol.length - 1].html = "&";
htmlNameToSymbol[htmlNameToSymbol.length - 1].symbol = "&";
 

From there just after the show name is retrieved a for loop would run and replace all HTML codes that should really be symbols:

for (k = 0; k < htmlNameToSymbol.length; k++)
{
    showName = showName.replace(htmlNameToSymbol[k].html, htmlNameToSymbol[k].symbol);
    episodeName = episodeName.replace(htmlNameToSymbol[k].html, htmlNameToSymbol[k].symbol);
}

To fix the first problem of different show names I used a very similar method to the above problem. Firstly I created a ShowSearchAlias "class" with two variables. tvCalendar which is the show named displayed by Calendar for TV and search which is the show name displayed by ezRSS:

function ShowSearchAlias ()
{
    this.tvCalendar = "";
    this.search = "";
}

Again on startup a new array is created of type ShowSearchAlias and populated with shows with name discrepancies:

var showSearchAlias = new Array()
showSearchAlias[showSearchAlias.length] = new ShowSearchAlias();
showSearchAlias[showSearchAlias.length - 1].tvCalendar = "Law & Order: SVU";
showSearchAlias[showSearchAlias.length - 1].search = "Law & Order: Special Victums Unit";
showSearchAlias[showSearchAlias.length] = new ShowSearchAlias();
showSearchAlias[showSearchAlias.length - 1].tvCalendar = "Law & Order: CI";
showSearchAlias[showSearchAlias.length - 1].search = "Law & Order: Criminal Intent";

Then it's a simple matter of running a for loop and replacing the show name from Calendar for TV with the show name for ezRSS:

for (var i = 0; i < showSearchAlias.length; i++)
{
    if (showSearchAlias[i].tvCalendar == showName)
    {
        showName = showSearchAlias[i].search;
        break;
    }
}

Thanks

TV Calendar Reloaded Now a multi tool for www.pogdesign.co.uk/cat. Cleans up the website removing links and text, adds torrent search links and formatted file names for each episode for easy copy and renaming.

Filed under: script

mlevit says...

Changelog:

  • Fixed: Some coding errors.
  • Updated: When the user searches the search button use to receive focus as a workaround for google.com. Instead of that and due to Google's new minimalistic homepage, instead of changing focus to another object other than the search box, the focus is just removed from the search box without being given to another object on the screen
Detailed Description:

Not too long ago a user encountered a defect with the script when running it on Google's new minimalistic homepage. This new homepage was one that had a Google logo and the search box but nothing else, not even the Google Search and I'm Feeling Lucky buttons. This is where the script crashed and burnt.

My script looks for those buttons for two reasons. One so it can change their value to suit the site you've changed to (e.g. changing to search Wikipedia would make the buttons value Wikipedia Search) and two it was a simple workaround for google.com. There was a slight problem with google.com where for some reason hitting the ENTER key wouldn't actually search the site you have chosen but would still run Google's I'm Feeling Lucky search. My simple work around was when the user hit the ENTER key I would change the cursor focus to the search button.

searchButton.focus();

But because this new homepage removed the search button the script would crash firstly at trying to set the buttons value to match the search site but secondly after fixing that error in some of the previous 1.7 beta versions it would still search using Google's I'm Feeling Lucky. After some time I came up with a simple workaround. Instead of changing the focus to another object on the screen (I even tried setting it to the logo which didn't work) I simple removed the focus from the search box completely.

searchBox.blur();

It was simple and effective. The search box no longer had the focus and I didn't have to worry about the search button being present or not.

Thanks

Google Homepage Reloaded Modifies the Google homepage to imitate go.infinise.com giving the user the ability to click the Google logo or press the UP key and change the website they search (i.e. Bing, Wikipedia, Twitter and YouTube)

Filed under: script

mlevit says...

Changelog:

  • Fixed: Videos that are displayed as search results now have correct background colours (e.g. grey, white, grey, white)

Detailed Description:

This was a minor release with a simple fix to a problem I had found. Really it wasn't that big of a problem. Just when I removed videos from the list and left only the ones that matched the users search query sometimes you wouldn't have the same pattern of alternating colours that YouTube had in the first place (i.e. every even numbered video has a grey background, every odd numbered video has a white background).

The fix was a simple one. A variable was defined and set to the CSS class "video even" which gives the movie a grey background. Then every time a movie is a successful match to the search query its CSS class would be changed to either "video even" if the previous one was "video odd" or "video odd" if the previous line was "video even".

//Variable decleration
var videoCSSClass = "video even";

//more code here...

//Remaining code
videos[i].setAttribute("class", videoCSSClass);

if (videoCSSClass == "video even")
{ 
    videoCSSClass = "video odd";
}
else
{
    videoCSSClass = "video even";
}

Thanks

YouTube Favourites Search Allows users to search their favoured YouTube videos from the Favourites page

Filed under: script

Steven says...

The goal here is to set up a local cache to use with TangoGPS or other apps like that. I don't have 3G neither WiMax (and there isn't a great coverage anyway...) so I like to grab my tiles before a trip.

Here is a little bash script which help doing this. You just have to know the coordinates of the first tile you want to get.

Example for the Finistère (France, Brittany)

You get it with a right click on the wanted tile, and "show picture", then you get :

Here this is the path from the URL which we are interested in : 8/124/88.

  • 8 stands for the zoom level.
  • 124 si the x coordinate
  • 88 is the y one.


There is a little algorithm to do a recursive download. I tried to sketch it by a small sample based on Brest Area.

Now you know how to use it, open the dl.sh and modify HOME, MAPHOME and EDITED variables. Execute it with "sh dl.sh args".
To finish, don't abuse on it...  If you need a huge area, or very often the same one,  this will be far better to render by yourself the tiles. For that, have a look to Osmarender ot Mapnik on the OpenStreetMap Wiki.

 

 

Click here to download:
dl.sh (1 KB)

Filed under: script

mlevit says...

Yesterday I was a little bored so I decided to finally make a script to obtain a feature I had wanted on YouTube for some time now. So I made my own Greasemonkey script that allows users to search their YouTube Favourites.

I've been looking around for something like this and haven't found anything, but I know this feature is one that people are looking for. If you use favourite videos on YouTube then you'd appreciate this script.

Enjoy: YouTube Favourites Search

Thanks

Filed under: script

Jon Spriggs says...

I recently wrote a document on http://jon.spriggs.org.uk/blog explaining how to monitor the interface of a McAfee sidewinder to see when it failed over. I don't know why I didn't write it on Posterous, but if you're following me on Posterous, and you think that you might want to know how to use Perl to repeatedly loop over the same command, and show the results with a date stamp underneath it (a bit like the watch command) then you'll find this page really useful. In the mean time, I've also written the same script for the CSH shell, which is used, amongst other places, on Nokia Firewalls.

Introduction

One of our requirements with one of our customers is to perform regular and routine failover tests. As the interface is not responsive to providing information about when service has failed from Primary to Secondary and back again, I re-wrote the script I adjusted for McAfee Sidewinders to run on the SECONDARY NODE to show the interface address of one NIC every 5 seconds. I'll also show how to slightly modify the script with different time delays and interface names. Please note, there may be much better ways of doing this. I needed something in a hurry, and this gave me what I needed. If you've got any better ideas, please drop me a note at jon@spriggs.org.uk or note below how to do it :)

Steps to perform
  1. SSH to the Secondary node.
  2. Check you're not already primary with the command ifconfig eth-s1p1c0 | grep inet this should return one line showing something like inet mtu 1500 1.2.3.4/24 broadcast 1.2.3.255
  3. Type this
    while (-e /bin/csh)
    ifconfig eth-s1p1c0 | grep inet
    date
    sleep 5
    end
  4. Perform your action to provoke fail-over, which may be to unplug an interface attached to the primary firewall, reboot the firewall or unplug a switch directly attached to the firewall. In response (and after approx 1 minute, based on your HA configuration) you should now see in the script's output, it now shows two lines (or maybe three) - as follows:

    inet mtu 1500
    inet 1.2.3.4/24 broadcast 1.2.3.255
    inet 1.2.3.5/24 broadcast 1.2.3.255
    vrrpmac 0:0:aa:bb:cc:dd
  5. Perform your failback and after 1 minute or so, it should revert to just the single line - 1.2.3.4 or equivelent for your network.
Tweaks

In the bold section above, replace the interface name identified (here it's eth-s1p1c0) with an interface you know will fail over, you can also make bigger or smaller the sleep command - here it's 5 seconds, but there's probably no reason why it couldn't be 1 or 10.

Filed under: Script

niels says...

A little while ago I was tasked with migrating about hundred Trac instances from SQLite to MySQL. Unfortunately SQLites schema definitions is not compatible with MySQL. So I had to write some scripts to handle it. After a little bit of experimenting everything worked perfectly.

The Strategy I employed was like this:

  1. Make a dump of a default MySQL Trac db schema.
  2. Make a dump of the Trac SQLite database
  3. Remove db schema definitions from the SQLite dump
  4. Concatenate the MySQL and SQLite dumps
  5. Load data into MySQL
  6. Edit Trac's database settings to use MySQL
  7. Do a trac-admin upgrade

Here is the shell script I made:



MYSQL_USER=username
MYSQL_PSWD=password

SQLITECMD=sqlite3
TRACBASE=/path/to/tracreps


# loop through all trac instances in tracreps
for d in $( ls $TRACBASE )
do
if [ -d "$TRACBASE/$d" ]; then
echo $d
TRACNAME=$d

# create database in mysql
echo "creating database for $TRACNAME..."
mysqladmin --user $MYSQL_USER -p$MYSQL_PSWD create $TRACNAME

# dump sqlite db structure + data
echo "dumping data from sqlite..."
$SQLITECMD $TRACBASE/$TRACNAME/db/trac.db .dump > trac.sqlite.sql

# remove database definitions from dump using a custom python script
echo "cleaning database definition from dump..."
`./cleansql.py < trac.sqlite.sql > trac.sqlite.sql.dataonly`

# concatenate mysql database definitions and sqlite data
cat trac.mysql.sql trac.sqlite.sql.dataonly > trac.sql

echo "loading data into mysql..."
mysql --user $MYSQL_USER -p$MYSQL_PSWD --default_character_set utf8 $TRACNAME < trac.sql

# edit database connection string in trac.ini
sed -i "s?sqlite:db/trac.db?mysql://$MYSQL_USER:$MYSQL_PSWD@localhost:3306/$TRACNAME?" $TRACBASE/$TRACNAME/conf/trac.ini

echo "upgrading mysql database..."
trac-admin $TRACBASE/$TRACNAME upgrade --no-backup


To remove schema definitions from the sqlite dump and fix some incompatibilities I made this python script referenced above as cleansql.py:



#!/usr/bin/env python

import sys
import re

file = sys.stdin.read()
file = re.sub(r'(CREATE (TABLE|INDEX)[^;]*|COMMIT|BEGIN TRANSACTION);', '', file)
file = re.sub(r'INSERT INTO "([^"]+)"', lambda m: 'INSERT INTO `%s`' % m.groups(1), file)
# fix sql for reports
file = re.sub(r'CAST\((.+) AS int\)', lambda m: 'CAST(%s AS signed)' % m.groups(1), file)

sys.stdout.write(file)


And that's it. I hope this will benefit someone tasked with the same job.

Filed under: script

maelcum says...

Click here to download:
ineptkey.pyw (7 KB)

Click here to download:
ineptepub.pyw (12 KB)

Click here to download:
ineptpdf.pyw (49 KB)

Filed under: Script