<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>andreas.goelzer.de &#187; snippet</title>
	<atom:link href="http://andreas.goelzer.de/tag/snippet/feed" rel="self" type="application/rss+xml" />
	<link>http://andreas.goelzer.de</link>
	<description>Electronics and small programs and other stuff</description>
	<lastBuildDate>Tue, 29 Nov 2011 21:08:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Play or open newest file from the linux command line</title>
		<link>http://andreas.goelzer.de/play-or-open-newest-file-from-the-linux-command-line</link>
		<comments>http://andreas.goelzer.de/play-or-open-newest-file-from-the-linux-command-line#comments</comments>
		<pubDate>Sun, 23 Oct 2011 14:01:21 +0000</pubDate>
		<dc:creator>Andreas Goelzer</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://andreas.goelzer.de/?p=214</guid>
		<description><![CDATA[In some cases it is convenient to have a shortcut to open the newest file in a directory. Maybe the last show your dvr recorded, or the last file you bought from amazon. For these cases I found this little &#8230; <a href="http://andreas.goelzer.de/play-or-open-newest-file-from-the-linux-command-line">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In some cases it is convenient to have a shortcut to open the newest file in a directory.  Maybe the last show your dvr recorded, or the last file you bought from amazon.</p>
<p>For these cases I found this little bash snippet useful:</p>
<pre>ls -tr | tail -n 1 | xargs -I FILE kde-open "FILE"</pre>
<p><span id="more-214"></span></p>
<p>Instead of <i>kde-open</i>, which opens any file with the associated program, you can use any program, gnome-users might want <i>gnome-open</i>, people with other window managers can use <i>xdg-open</i> from xdg-utils.  Or you can just insert <i>mplayer</i>, if you are only interested in music and videos. </p>
<p>I prefer it installed somewhere in the path, and then one can add a command-line parameter, the number of files to be played:<br />
<pre lang="python" line="1">#!/bin/sh
ls -tr | tail -n ${1:-1} | xargs -I FF kde-open &quot;FF&quot;
</pre><hr /><a href='http://andreas.goelzer.de/download/playlast'><img src="http://andreas.goelzer.de/wp-content/plugins/kfile/fileicons/file-generic.png" width="16" height="16" alt="filetype" class="icon16" /> playlast</a> (63 B, 2011-10-23)<br/><hr /></p>
]]></content:encoded>
			<wfw:commentRss>http://andreas.goelzer.de/play-or-open-newest-file-from-the-linux-command-line/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ytplay &#8211; wrapper for youtube-dl.py</title>
		<link>http://andreas.goelzer.de/ytplay-wrapper-for-youtube-dl-py</link>
		<comments>http://andreas.goelzer.de/ytplay-wrapper-for-youtube-dl-py#comments</comments>
		<pubDate>Wed, 17 Feb 2010 22:55:59 +0000</pubDate>
		<dc:creator>Andreas Goelzer</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://andreas.goelzer.de/?p=148</guid>
		<description><![CDATA[Due to my slightly outdated computer flash is a huge problem. So, for viewing youtube videos, youtube-dl.py is a great solution. However, I wanted something more comfortable. ytplay wraps around youtube-dl.py, it searches for a video, orders youtube-dl to get &#8230; <a href="http://andreas.goelzer.de/ytplay-wrapper-for-youtube-dl-py">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Due to my slightly outdated computer flash is a huge problem. So, for viewing youtube videos, <a href="http://bitbucket.org/rg3/youtube-dl/wiki/Home">youtube-dl.py</a> is a great solution. However, I wanted something more comfortable.</p>
<p>ytplay wraps around youtube-dl.py, it searches for a video, orders youtube-dl to get it, and starts playing it in vlc.</p>
<p>Usage is simple:<br />
> ytplay foobar<br />
will search youtube for videos about foobar and play the first one found.</p>
<p>The code is still quite dirty, especially the subprocess part. However, it should work, have fun!<br />
<span id="more-148"></span><br />
<pre lang="python" line="1">#!/usr/bin/python
# -*- coding: utf-8 -*-
#		parser.add_option('-P', '--play', action='store_true',
#				dest='play', help='play in vlc', default=False)

from optparse import OptionParser
from subprocess import Popen, PIPE
from urllib2 import urlopen 
from urllib import quote_plus
from re import search, match
from os import system

parser = OptionParser(version='2010.02.13')

parser.add_option('-p', '--player',
dest='player', metavar='PROGRAM', help='media player to use', default='vlc')

(opts, args) = parser.parse_args()

if match(&quot;http://&quot;,args[0]):
	videopageurl = args[0]
else:
	searchargs = '+'.join(args)
	searchurl = &quot;http://www.youtube.com/results?search_type=&amp;aq=f&amp;oq=&amp;search_query=&quot; + quote_plus(searchargs)
	searchresult = urlopen(searchurl).read()
	p=search(r'(watch\?[^&quot;]*)',searchresult)
	if p==None:
		print &quot;No Videos found&quot;
		exit()
	videopageurl=&quot;http://www.youtube.com/&quot; + p.group(1)
	

print &quot;Starting youtube-dl for &quot; + videopageurl
ytdl = Popen(&quot;youtube-dl.py -t -b &quot; + videopageurl,shell=True,stdout=PIPE)

while not ytdl.stdout.closed:
	line = ytdl.stdout.readline()
	print line,
	if line == '': exit()
	p = search(r'\[download\] Destination: (\S*)',line)
	if p != None:
		print &quot;Starting player: &quot; + opts.player + &quot; &quot; + p.group(1)
		system(opts.player + &quot; &quot; + p.group(1) + &quot; &amp;&quot;)

</pre><hr /><a href='http://andreas.goelzer.de/download/ytplay'><img src="http://andreas.goelzer.de/wp-content/plugins/kfile/fileicons/file-generic.png" width="16" height="16" alt="filetype" class="icon16" /> ytplay</a> (1.28 kiB, 2010-02-14)<br/><hr /></p>
]]></content:encoded>
			<wfw:commentRss>http://andreas.goelzer.de/ytplay-wrapper-for-youtube-dl-py/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deleting multiple tables with a common prefix</title>
		<link>http://andreas.goelzer.de/deleting-multiple-tables-with-a-common-prefix</link>
		<comments>http://andreas.goelzer.de/deleting-multiple-tables-with-a-common-prefix#comments</comments>
		<pubDate>Tue, 04 Mar 2008 22:20:19 +0000</pubDate>
		<dc:creator>Andreas Goelzer</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.goelzer.de/andreas/wordpress/?p=8</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 &#60;?php //Connect to the database server and select our database $link = mysql_connect&#40;'rdbms.strato.de', 'UXXXX', 'epsilon eridani'&#41; or die&#40;'Could not connect: ' &#8230; <a href="http://andreas.goelzer.de/deleting-multiple-tables-with-a-common-prefix">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//Connect to the database server and select our database</span>
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rdbms.strato.de'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UXXXX'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'epsilon eridani'</span><span style="color: #009900;">&#41;</span> 
	or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not connect: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DBXXXX'</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not select database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//get table list</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SHOW TABLES&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//kill tables</span>
<span style="color: #000088;">$tokillprefix</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jos_&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tokillprefix</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$tokillprefix</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	 	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;killing <span style="color: #006699; font-weight: bold;">$row[0]</span> &lt;br&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DROP TABLE <span style="color: #006699; font-weight: bold;">$row[0]</span>&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>done</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://andreas.goelzer.de/deleting-multiple-tables-with-a-common-prefix/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/9 queries in 0.285 seconds using disk: basic
Object Caching 314/326 objects using disk: basic

Served from: andreas.goelzer.de @ 2012-02-05 05:42:46 -->
