Matt — PRONETOFAIL

Author Archives: Matt

Multiple Dynamic Sidebars

0
Filed under code, geek
Tagged as , ,

Sidebar.php

<?
        ###
        # Get page slug
        ###
        $slug = split('/', get_permalink());
        ###
        # Example $slug http://somedomain.com/folder/subfolder/contact-us/
        # we want contact-us so we'll use $slug[5]
        # Array ( 
        #        [0] => http: 
        #        [1] => 
        #        [2] => somedomain.com 
        #        [3] => folder 
        #        [4] => subfolder 
        #        [5] => contact-us 
        #        [6] => )
        ###

        $slug = $slug[5]; ## Change the number to match the last part of the url, see example array above

        ###
        # Check for active sidebar matching page $slug and make sure its not the front page
        ###
        if ( is_active_sidebar( 'sidebar-'.$slug ) && !is_front_page() ) { ?>
            <div id="tertiary" class="widget-area" role="complementary"> 
                <?php dynamic_sidebar( 'sidebar-'.$slug ); ?>
            </div><!-- #tertiary .widget-area -->
        <? } else { ?>
            <div id="tertiary" class="widget-area" role="complementary">
                <?php dynamic_sidebar( 'sidebar-1' ); ?>
            </div><!-- #tertiary .widget-area -->
        <? } ?>

Functions.php

function toolbox_widgets_init() {
    register_sidebar( array(
        'name' => __( 'Sidebar 1', 'toolbox' ),
        'id' => 'sidebar-1',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => "</aside>",
        'before_title' => '<h1 class="widget-title">',
        'after_title' => '</h1>',
    ) );
 
    register_sidebar( array(
        'name' => __( 'News', 'toolbox' ),
        'id' => 'sidebar-news',
        'description' => __( 'An optional second sidebar area', 'toolbox' ),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => "</aside>",
        'before_title' => '<h1 class="widget-title">',
        'after_title' => '</h1>',
    ) );
}
add_action( 'widgets_init', 'toolbox_widgets_init' );

This script looks for a sidebar matching the page slug of the current viewed page. Add new sidebars to match the scheme sidebar-SLUG in toolbox_widgets_init then create a post/page with a matching slug. done.

Datatables: Reset sorting

0
Filed under code, geek
Tagged as ,

This took me forever to find. This button will reset the column sorts on your datatable.

The JS

var oTable = $('.sortable').dataTable(...)
 
      $('#resetsort').click( function () {
 
   		oTable.fnSort( [ [0,'asc'] ] );
  		oTable.fnDraw();
        } );

The HTML

<button href="#" id="resetsort">reset sort</button>

Dogs

0
Filed under Mobile Uploads

 

 

 

Bot (Terrier mix) and Sasha (Beagle mix)

Sunflower

0
Filed under Mobile Uploads
Tagged as ,

image

Google MP3 Index finder

0
Filed under code, geek, projects
Tagged as , ,

Heres another little function I’m using for the new Musotik. Don’t mind the sloppy code. It searches Google for mp3 indexes and returns the results in an array. Try it out here

function getindexes($q) {
	$api = "SET YOUR GOOGLE API KEY HERE";
        $cx = "SET YOUR GOOGLE CX VAR HERE";
	$q = '-inurl:htm -inurl:html -inurl:php -inurl:asp -inurl:doc -inurl:pdf -inurl:shtml -inurl:txt AND (“index of|"last modified"|"parent of") AND mp3 -ringtone -lyric -playlist  AND '.$q;
 
	$q=urlencode($q);
	$url="https://www.googleapis.com/customsearch/v1?key=$api&amp;cx=$cx&amp;q=$q&amp;alt=atom";
	$xml = new XMLReader(); 
	$xml-&gt;open($url); 
	$assoc = xml2assoc($xml); 
	$xml-&gt;close(); 
 
	$entries = array();    
	foreach($assoc[feed][0] as $node) {
 
		foreach($node[entry] as $entry) {
		   	$entries[link][] = $entry[value][id][0][value];
		   	$entries[title][] = $entry[value][title][0][value];
	    }
	}
	return $entries;
}

My return array is a little wonky here, but you can return it how ever you want. Below is a utility function used above taken from php.net

function xml2assoc($xml) {
	$assoc = null;
	while($xml-&gt;read()){
		switch ($xml-&gt;nodeType) {
			case XMLReader::END_ELEMENT: return $assoc;
			case XMLReader::ELEMENT:
				$assoc[$xml-&gt;name][] = array('value' =&gt; $xml-&gt;isEmptyElement ? '' : xml2assoc($xml));
				if($xml-&gt;hasAttributes){
					$el =&amp; $assoc[$xml-&gt;name][count($assoc[$xml-&gt;name]) - 1];
					while($xml-&gt;moveToNextAttribute()) $el['attributes'][$xml-&gt;name] = $xml-&gt;value;
				}
			break;
			case XMLReader::TEXT:
			case XMLReader::CDATA: $assoc .= $xml-&gt;value;
		}	
	}
	return $assoc;
}

Skreemr tool

0
Filed under code, geek, projects
Tagged as , ,

Heres a bit of a larger project I’m working on that will give you the first 10 skreemr mp3 links for a search.

<?php
$q = urlencode($_GET['q']);
$skreemr="http://skreemr.com/results.jsp?q=$q";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $skreemr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
$output = curl_exec($ch);
curl_close($ch);
$re1='.*?';	# Non-greedy match on filler
$re2='((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))';	# HTTP URL 1
if ($c=preg_match_all ("/".$re1.$re2."/is", $output, $matches))  {
  foreach ($matches[1] as $url) {
    if (preg_match('/mp3/', $url)) {
      echo "&lt;a href=\" $url\" target=new&gt;$url&lt;/a&gt;&lt;br /&gt;";
    }
  }
}
?>

Stl

0
Filed under Uncategorized

image

WikiRebels – The WikiLeaks Documentary

0
Filed under current events
Tagged as , , ,

Democracy without transparency is no democracy. It’s just an empty word.

From the description: “Exclusive rough-cut of first in-depth documentary on WikiLeaks and the people behind it! From summer 2010 until now, Swedish Television has been following the secretive media network WikiLeaks and its enigmatic Editor-in-Chief Julian Assange. Reporters Jesper Huor and Bosse Lindquist have traveled to key countries where WikiLeaks operates, interviewing top members, such as Assange, new Spokesperson Kristinn Hrafnsson, as well as people like Daniel Domscheit-Berg who now is starting his own version – Openleaks.org! Where is the secretive organization heading? Stronger than ever, or broken by the US? Who is Assange: champion of freedom, spy or rapist? What are his objectives? What are the consequences for the internet?”











http://www.youtube.com/user/zerwas2ky#grid/user/6D8EE2E0B836F096

Cluster, Sphider, Musotik

0
Filed under geek, music, projects
Tagged as , , ,

So I’ve decided that I’m going to write/find a web crawler to find mp3s/ogg etc.. Then rewrite Musotik from scratch. It’ll also crawl torrent sites. I’m working with Sphider right now. It may become the base of my crawler.

After I get the spider wrote, I’ll run it on 3 of the cluster boxes, updating 1 mysql db. The other box will be the main webserver and database server.

  • 12/13/10 2am – Started ripping apart the Sphider script.
  • 12/13/10 2:30am – 3 nodes are indexing to the same DB. Testing with Digg, PirateBay, and Drawgasmic
  • 12/13/10 3:45am – Going to let it index.. here what I have so far:
  • —-Currently in database: 16 sites, 4964 links, 0 categories and 103853 keywords.
  • 12/13/10 4pm – let it run all night/day.
  • —-Currently in database: 16 sites, 32603 links, 0 categories and 278085 keywords.

So its pretty slow with Sphider. I also don’t need everything that Sphider does. I’m trying to decide whether I should write something from scratch or modify Sphider.

My next post will be about that, and probably heavy with PHP code.

Cluster project: Day 1

0
Filed under geek, projects
Tagged as , , , ,

So I came into possession of 4 p4 1.5-1.7Ghz Dell boxes. Each machine has 256Megs of ram, a cd-writer and a floppy drive. Here is a break down of how I try to turn them into a cluster, and what I decide to do with this said monster. ;)

  • 12/9/10 6pm – The computers arrive at our apartment and I’m excited they’re all the same size and almost the same specs. We go to dinner. I think about them during the entire meal.
  • 12/9/10 10pm – I come home and boot one up. It boots into XP just fine, the cdrom may be jacked up on this one. I try to install extra memory I have laying around. No go. We’re stuck at 256Megs. I start reading about clustering with Ubuntu on the webz.
  • 12/9/10 11pm – Started downloading Ubuntu server 10.10 and configuring the router DNS for the 4 nodes. I’ll be using the IP block of 192.168.2.100-105. Still very unsure of how this all works. Back to reading while this cd downloads and burns.
  • 12/10/10 12am – Started install Ubuntu Server 10.10 on the first node. One of the 1.7Ghz.
  • 12/10/10 12:30am – Burnt a DVD… The cluster nodes only have CDs. Burning a CDR.
  • 12/10/10 12:45am – Trying to burn a CDR with one of the node machines, but it appears to be locked up at 12%. Canceling and trying again. Copying the ISO to the local machine to burn instead of over the network.
  • 12/10/10 2am – Burn and install successful, but I installed Ubuntu with the eucalyptus and landscape only to find out they’re intense on the poor lil P4 CPU. Reinstalling… meh.
  • 12/10/10 4:45am – Installed Ubuntu Server on 2 machines. The cd-rom in the one 1.7Ghz machine is definitely bad. I’ll have to swap out one from the another machine to install. No biggie. So I haven’t even started on the clustering part. But I’ll try something out once I get both the machines configured the same. And updated.
  • 12/10/10 6:30am – Got Folding@home running on the first 2 nodes, installing Ubuntu on the 3rd. I’m using https://help.ubuntu.com/community/MpichCluster as a guide.
  • 12/10/10 10:00pm – Went remote and made the mistake of trying to edit the network. Took all 4 machines down somehow. Now I have to wait till tonight to fix it locally. meh.

So I managed to get fold@home running on three nodes in about 12 hours. More to come in the next post.