Tag Archives: web

Blocking some DIV ad boxes with Privoxy

If you want to block one of those shiny-ass ads (think workplace sanitation), here’s a few simple one-liners. (Everything’s in /etc/privoxy.)

user.filter:
FILTER: div-ads DIV ad blocks.
s/<div id="banner_box"/<div id="crap" style="display:none;"/g

user.action:
{ +filter{div-ads} }
.

Don’t forget to uncomment that actionsfile user.action from your config file.

Info lifted from here.

Advertisements

Tor on per-tab basis

I have just had this idea: since uzbl_tabbed.py in fact reads the config file for every new tab (i.e. every new uzbl instance), it should be very easy to allow tor be enabled on a per-tab basis, something I wanted badly for Firefox. Nais!

uzbl_tabbed.py: commands to FIFO

The list is on line 782 (ATM) of uzbl_tabbed.py. The FIFO location is determined by your settings (top of file for defaults, possibly overridden from config). It’s like this:

782     def parse_command(self, cmd):
783         '''Parse instructions from uzbl child processes.'''
784
785         # Commands ( [] = optional, {} = required )
786         # new [uri]
787         #   open new tab and head to optional uri.
788         # close [tab-num]
789         #   close current tab or close via tab id.
790         # next [n-tabs]
791         #   open next tab or n tabs down. Supports negative indexing.
...

So, to open a new tab in uzbl_tabbed from newsbeuter, you need a script like newtab.sh:

#!/bin/sh
echo "new $1" > `ls -1 /tmp/uzbltabbed_*`

Then call it from newsbeuter – put this in ~.newsbeuter/config:

browser "~/.local/share/uzbl/scripts/newtab.sh %u"

PHP: Fatal error: call to undefined function iconv()

Make sure it’s enabled in php.ini. 🙂

I also had to restart Apache.

RDF to iCal converter (PHP script)

…which can easily be adapted to, say, RSS or shit.

I wrote this with a particular RDF feed in mind, so you might have to tweak it, if you want to use it.

Also, see the TODOs.

<?php

// GPLv3.
// Parsing part copied over from PHP manual.
// Also used RFC2445: http://www.ietf.org/rfc/rfc2445.txt
// Distributed under fuck you license.

class RDFItem {
	var $link;		//
	var $title;		//
	var $description;	//
	var $date;		//
//	var $dc:date;		// hell knows what this is

    function RDFItem ($link)
    {
        foreach ( $link as $k => $v )
            $this->$k = $link[$k];
    }
}

function readRDF( $filename )
{
    // read the RDF
    $data = implode("", file($filename));
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $data, $values, $tags);
    xml_parser_free($parser);

    // loop through the file structures
    foreach ($tags as $key=>$val) {
        if ($key == 'item') {
            $itemranges = $val;

            // each contiguous pair of array entries are the
            // lower and upper range for each RDF feed item
            // (what?..)

            for ($i=0; $i < count($itemranges); $i+=2) {
                $offset = $itemranges[$i] + 1;
                $len = $itemranges[$i + 1] - $offset;
                $tdb[] = parseItem( array_slice($values, $offset, $len) );
            }
        } else {
            continue;
        }
    }

    return $tdb;
}

function parseItem($subElements)
{
	for ( $i = 0; $i \n/", "", $desc, 1 );

	// Make sure all lines except the 1st have a space up front.
	$desc = str_replace( "\n", "", $desc );
	$desc = str_replace( "<br />", "\\n\n ", $desc );
	$desc = str_replace( "<br/>", "\\n\n ", $desc );

	// Manage links.
	$desc = preg_replace( "/<a href=\"(.*?)\">/s", " [$1] ", $desc );
	$desc = str_replace( "</a>", "", $desc );

	// Manage all other HTML tags.
//	$desc = preg_replace( "/<(?:.*?)>/s", "", $desc );

	// TODO: check that lines are folded at 75 octet.

	return $desc;
}


$db = readRDF( 'hardcore.rdf' );

/*
echo "<pre>";
print_r($db);
echo "</pre>";
*/




// Now for the dirty punk solution.
// Create the calendar.
$cal  = "BEGIN:VCALENDAR\nVERSION:2.0\n";
$cal .= "X-WR-CALNAME:Vilnius Hardcore Events | [TODO: date]\n";
$cal .= "PRODID:-//YOURNAME//TOOLNAME//EN\n";

foreach ( $db as $info )
{
	$info->date = fix_date($info->date);
	$info->description = fix_description($info->description);

	$cal .= "BEGIN:VEVENT\n";
	$cal .= "DTSTART;VALUE=DATE-TIME:".$info->date."\n";
	$cal .= "DTEND;VALUE=DATE-TIME:".$info->date."\n";
	$cal .= "SUMMARY:".$info->title."\n";
	$cal .= "DESCRIPTION:".$info->description."\n";
	$cal .= "URL:http://url.com/TODO\n";
	$cal .= "UID:".$info->link."\n";
	$cal .= "END:VEVENT\n";
}

$cal .= "END:VCALENDAR\n";

//echo $cal;
echo file_put_contents ( "hardcore.ics", $cal );

?>