<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Linux-Tricks/Oneliner on OiePoie!</title>
    <link>https://www.oiepoie.nl/categories/linux-tricks/oneliner/</link>
    <description>Recent content in Linux-Tricks/Oneliner on OiePoie!</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Sat, 12 Jan 2008 16:58:01 +0100</lastBuildDate><atom:link href="https://www.oiepoie.nl/categories/linux-tricks/oneliner/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Oneliner to remove duplicates while maintaining the original order</title>
      <link>https://www.oiepoie.nl/2008/01/12/oneliner-to-remove-duplicates-while-maintaining-the-original-order/</link>
      <pubDate>Sat, 12 Jan 2008 16:58:01 +0100</pubDate>
      
      <guid>https://www.oiepoie.nl/2008/01/12/oneliner-to-remove-duplicates-while-maintaining-the-original-order/</guid>
      <description>&lt;p&gt;If you have got a list like this:&lt;/p&gt;
&lt;pre&gt;
one
two
one
three
one
two
four
&lt;/pre&gt;
&lt;p&gt;and you want to remove the duplicates from the list, chances are that you will end up with this result:&lt;/p&gt;
&lt;pre&gt;
four
one
three
two
&lt;/pre&gt;
&lt;p&gt;Because you are using a command like:&lt;/p&gt;
&lt;pre&gt;
sort -u &amp;lt; list.txt
&lt;/pre&gt;
&lt;p&gt;or the longer form:&lt;/p&gt;
&lt;pre&gt;
cat list.txt | sort | uniq
&lt;/pre&gt;
&lt;p&gt;There is an easy way to keep the original order of the list and remove the duplicates in an oneliner.&lt;br/&gt;
For this you need to number the entries in the list with this command:&lt;/p&gt;
&lt;pre&gt;
nl list.txt
&lt;/pre&gt;
&lt;p&gt;If you don&#39;t have &lt;strong&gt;nl&lt;/strong&gt; on your system, you can use &lt;strong&gt;cat -n&lt;/strong&gt; or whatever tickles your fancy.&lt;br/&gt;
This will give you the list:&lt;/p&gt;
&lt;pre&gt;
     1  one
     2  two
     3  one
     4  three
     5  one
     6  two
     7  four
&lt;/pre&gt;
&lt;p&gt;We will use the numbering to restore the original order when we are done removing the duplicates.&lt;br/&gt;
Next thing is to sort the list on the second field:&lt;/p&gt;
&lt;pre&gt;
nl list.txt | sort -k2
&lt;/pre&gt;
&lt;pre&gt;
     7  four
     1  one
     3  one
     5  one
     4  three
     2  two
     6  two
&lt;/pre&gt;
&lt;p&gt;and tell sort to remove the lines with duplicate fields:&lt;/p&gt;
&lt;pre&gt;
nl list.txt | sort -k2 -u
&lt;/pre&gt;
&lt;pre&gt;
     7  four
     1  one
     4  three
     2  two
&lt;/pre&gt;
&lt;p&gt;All that is left is to restore the original order:&lt;/p&gt;
&lt;pre&gt;
nl list.txt | sort -k2 -u | sort -n
&lt;/pre&gt;
&lt;pre&gt;
     1  one
     2  two
     4  three
     7  four
&lt;/pre&gt;
&lt;p&gt;and get rid of our inserted numbering:&lt;/p&gt;
&lt;pre&gt;
nl list.txt | sort -k2 -u | sort -n | cut -f2-
&lt;/pre&gt;
&lt;pre&gt;
one
two
three
four
&lt;/pre&gt;
&lt;p&gt;Imagine trying to do this on a Windows box, I wouldn&#39;t know where to start 😉&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Sniffing Google’s blacklist for firefox</title>
      <link>https://www.oiepoie.nl/2007/11/25/sniffing-googles-blacklist-for-firefox/</link>
      <pubDate>Sun, 25 Nov 2007 16:40:05 +0100</pubDate>
      
      <guid>https://www.oiepoie.nl/2007/11/25/sniffing-googles-blacklist-for-firefox/</guid>
      <description>&lt;p&gt;Firefox 2 has a new security feature which protects you from entering private data on &lt;a class=&#34;extlink&#34; href=&#34;http://en.wikipedia.org/wiki/Phishing&#34; target=&#34;_blank&#34;&gt;phishing&lt;/a&gt; websites or getting infected with malware on a website which promises you heaven and earth.&lt;br/&gt;
Protection is done by comparing the website address (&lt;a class=&#34;extlink&#34; href=&#34;http://en.wikipedia.org/wiki/Url&#34; target=&#34;_blank&#34;&gt;URL&lt;/a&gt;against a so called &lt;a extlink=&#34;&#34; href=&#34;http://en.wikipedia.org/wiki/Blacklist#Computing&#34; target=&#34;_blank class=&#34;&gt;blacklist&lt;/a&gt;. The blacklist is maintained by the good folks at Google, they take care of updating the blacklist regulary and firefox automagically downloads new versions.&lt;br/&gt;
Curious by nature, i wanted to know which websites were in the blacklist, so i took a peek in my .mozilla/firefox/… directory where all the users stuff is stored. The blacklist itself is easy identified by it’s name: &lt;strong&gt;urlclassifier2.sqlite&lt;/strong&gt; and the extension betrays what kind of system is used to store the bad sites: &lt;strong&gt;sqlite&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;a class=&#34;extlink&#34; href=&#34;http://en.wikipedia.org/wiki/Sqlite&#34; target=&#34;_blank&#34;&gt;SQLite&lt;/a&gt; is actually a database program, but in it’s simplest form. You don’t need to run a database engine and setup permissions, etc. But the complete database is stored into a file. So this is the &lt;strong&gt;KIS&lt;/strong&gt; principle to the max, and it works great as long as the database doesn’t grow to large or to complex.&lt;/p&gt;
&lt;p&gt;Next thing to do is fire up sqlite and have a look at the structure of the database:&lt;/p&gt;
&lt;pre&gt;
$ sqlite3  urlclassifier2.sqlite
SQLite version 3.4.2
Enter &#34;.help&#34; for instructions
sqlite&amp;gt; .tables
goog_black_enchash goog_black_url goog_white_domain goog_white_url
sqlite&amp;gt; .schema
CREATE TABLE &#39;goog_black_enchash&#39; (key TEXT PRIMARY KEY, value TEXT);
CREATE TABLE &#39;goog_black_url&#39; (key TEXT PRIMARY KEY, value TEXT);
CREATE TABLE &#39;goog_white_domain&#39; (key TEXT PRIMARY KEY, value TEXT);
CREATE TABLE &#39;goog_white_url&#39; (key TEXT PRIMARY KEY, value TEXT);
&lt;/pre&gt;
&lt;p&gt;Looks simple enough, the bad sites are probably in: goog_blac_url&lt;/p&gt;
&lt;pre class=&#34;noscroll&#34;&gt;
qlite&amp;gt; select * from goog_black_url LIMIT 3;
uggc://ybtva.zlfcnpr.psz.shfrnpgvba.hfre.fcynfu.ubzr.zlgbxra.76701n2644n8605.pn0qpor.pbz/vaqrk.cuc|c
uggc://ealfcnprv.pbz/vaqrk.pszshfrnpgvba=ybtva.cebprff&amp;amp;ZlGbxra-wrrqk4r1ssn-s3kg3k2ns0-4r3-sfs3n421-s7goskks3ks231.ugz|c
uggc://eeaelfcnpr.pbz/vaqrk.psz-shfrnpgvba657Qybtva.cebprff8526ZlGbxraf79843964886883084155.ugz|c
sqlite&amp;gt; .quit
&lt;/pre&gt;
&lt;p&gt;Hmm, it &lt;a class=&#34;extlink&#34; href=&#34;http://wiki.mozilla.org/Safe_Browsing:_Design_Documentation&#34; target=&#34;_blank&#34;&gt;turns out&lt;/a&gt; that the content is encoded through the famous &lt;a class=&#34;extlink&#34; href=&#34;http://en.wikipedia.org/wiki/Rot13&#34; target=&#34;_blank&#34;&gt;ROT13&lt;/a&gt; methode. The reason being that the file otherwise might be flagged as harmfull by locally running antivirus software.&lt;/p&gt;
&lt;p&gt;So we need a ROT13 decoder, this is easilly done with the unix utility &lt;strong&gt;tr&lt;/strong&gt; and the complete construct snugly fits into a oneliner:&lt;/p&gt;
&lt;pre class=&#34;noscroll&#34;&gt;
echo &#34;SELECT * FROM goog_black_url LIMIT 3;&#34; | sqlite3 \
urlclassifier2.sqlite | tr N-ZA-Mn-za-m A-Za-z
&lt;/pre&gt;
&lt;p&gt;Which will output something like:&lt;/p&gt;
&lt;pre class=&#34;noscroll&#34;&gt;
http://login.myspace.cfm.fuseaction.user.splash.home.mytoken.76701a2644a8605.ca0dcbe.com/index.php|p
http://rnyspacei.com/index.cfmfuseaction=login.process&amp;amp;ZyGoken-jeedx4e1ffa-f3xt3x2af0-4e3-fsf3a421-f7tbfxxf3xf231.htm|p
http://rrnryspace.com/index.cfm-fuseaction657Qlogin.process8526ZyGokens79843964886883084155.htm|p
&lt;/pre&gt;
&lt;p&gt;If you’re brave, you might cut ‘n paste one of the URL’s in your firefox browser and see what happens 😉&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Radio 1 nieuws luisteren met Linux</title>
      <link>https://www.oiepoie.nl/2006/07/26/radio-1-nieuws-luisteren-met-linux/</link>
      <pubDate>Wed, 26 Jul 2006 14:23:15 +0200</pubDate>
      
      <guid>https://www.oiepoie.nl/2006/07/26/radio-1-nieuws-luisteren-met-linux/</guid>
      <description>&lt;p&gt;Ik wil zelf graag op de hoogte blijven van het nieuws maar als ik op de klok kijk of het tijd is voor het journaal is het altijd te vroeg of te laat. Zelfs als de radio aan is ben ik vaak druk met andere dingen bezig zodat ik het journaal niet bewust hoor.&lt;br/&gt;
De oplossing is natuurlijk het journaal laten afspelen op het moment dat je de tijd wilt nemen om te luisteren. Met een beetje debuggen op de website vindt je de eigenlijke URL waar de stream met het journaal is verstopt. Vervolgens kan je die makkelijk vanaf de commandline afspelen met:&lt;/p&gt;
&lt;pre&gt;
mms://cachemedia.omroep.nl/rambo01/0/nos/radio1nieuws/NOS_Nieuws.wma
&lt;/pre&gt;
&lt;p&gt;Het bufferen van mplayer duurt even, maar daarna kan je tijdens het afspelen met alle vier de pijltjes toetsen voor- of achteruit “spoelen” in de stream.&lt;/p&gt;
&lt;p&gt;Als je zo’n stream zou willen opslaan op disk onder Linux moet je eens kijken naar het pakket &lt;a class=&#34;extlink&#34; href=&#34;http://savannah.nongnu.org/projects/mimms/&#34; target=&#34;_new&#34;&gt;mimms&lt;/a&gt;. &lt;/p&gt;
&lt;pre&gt;
mimms -o journaal.wma mplayer mms://streams.omroep.nl/nos/radio1nieuws/NOS_Nieuws.wma
&lt;/pre&gt;
&lt;p&gt;Uiteraard moet je het copyright van het aangebodene in de gaten houden, niet alles mag opgeslagen worden.&lt;br/&gt;
Het is met mimms ook mogelijk om video streams op te nemen.&lt;/p&gt;
&lt;p&gt;Om zelf makkelijk stream URL’s te vinden terwijl je met je browser aan het klikken bent is&lt;br/&gt;
&lt;a class=&#34;extlink&#34; href=&#34;http://freshmeat.net/projects/streamsniff/&#34; target=&#34;_new&#34;&gt;streamsniff&lt;/a&gt; bijzonder handig.&lt;br/&gt;
streamsniff kan je als root gewoon opstarten en vervolgens met &lt;a href=&#34;https://www.oiepoie.nl/firefox&#34;&gt;firefox&lt;/a&gt; (of desnoods IE) op websites klikken waar multimedia content staat.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Truuk&lt;/b&gt;&lt;br/&gt;
Om te zoeken welke shoutcast streams er zijn om via Internet radio te luisteren kan je op de volgende&lt;br/&gt;
&lt;a class=&#34;extlink&#34; href=&#34;http://www.google.nl/search?hl=nl&amp;amp;q=site%3Ashoutcast.omroep.nl+Title&#34; target=&#34;_blank&#34;&gt;Google Query&lt;/a&gt; klikken.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Tip&lt;/b&gt;&lt;br/&gt;
Zelf luister ik graag naar &lt;a class=&#34;extlink&#34; href=&#34;http://www.radioparadise.com&#34; target=&#34;_blank&#34;&gt;Radio Paradise&lt;/a&gt;, lekkere muziek zonder reclames.&lt;br/&gt;
Ze hebben diverse streams om online te luisteren, een daarvan is een 64 kbps AAC stream die vergelijkbaar qua kwaliteit is met 128 kbps mp3. Om deze stream onder Linux te luisteren kan je VLC (VideoLan Client) gebruiken:&lt;/p&gt;
&lt;pre&gt;
vlc http://www.radioparadise.com/musiclinks/rp_64aac-2.m3u
&lt;/pre&gt;
</description>
    </item>
    
  </channel>
</rss>
