Skip to content

Instantly share code, notes, and snippets.

View ivuorinen's full-sized avatar

Ismo Vuorinen ivuorinen

View GitHub Profile
@ivuorinen
ivuorinen / mkvsubs.sh
Created January 30, 2015 07:31
MKV Subtitle extraction
#!/bin/bash
# Ismo Vuorinen <ismo@ivuorinen.net>, 2014
SCRIPTNAME=`basename $0`
# If no directory is given, work in local dir
if [ "$1" = "" ]; then
DIR="."
else
DIR="$1"
@ivuorinen
ivuorinen / entities.php
Created September 20, 2015 07:56
psr2-fixed, docblocked and 80-char width safe version
<?php
/**
* makeSafeEntities()
*
* Convert str to UTF-8 (if not already), then convert that to HTML named
* entities and numbered references.
* Compare to native htmlentities() function. Unlike that function,
* this will skip any already existing entities in the string.
*
* - mb_convert_encoding() doesn't encode ampersands, so use
@ivuorinen
ivuorinen / tunar-demo.php
Created November 26, 2010 09:35
PHP5 function to get recent plays from last.fm and caching the results for about of time.
<?php
require_once("tunar.php");
$tunar = tunar( "drifter9000" );
?><pre><?php print_r( $tunar ); ?></pre>
@ivuorinen
ivuorinen / quota.php
Created November 26, 2010 09:19
quota.php displays your quota and how much you've used of it. freaks out if no quota set up.
<?php
// Fetch the quota to temp file, grab the data and delete the file
system("quota -s > q.txt");
$raw_quota = file("q.txt");
unlink("q.txt");
$raw_quota = trim( $raw_quota[3] );
$raw_quota = str_replace(" ", " ", $raw_quota);
@ivuorinen
ivuorinen / files.php
Created November 26, 2010 09:24
directory insides as cute listing
<?php
/**
* directory insides as cute listing
*/
$me = __FILE__;
$dir = dirname($me);
$files = scandir($dir);
$req = $_SERVER['SERVER_NAME'].($_SERVER['REQUEST_URI']);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
{if segment_1}
{if segment_1 == 'archive'}
{segment_3}/{segment_2} &mdash; Arkistot &mdash;
{if:elseif segment_1 == 'about'}
Tietoja &mdash;
{if:elseif segment_1 == 'categories'}
{exp:query sql="SELECT cat_name FROM exp_categories WHERE cat_url_title = '{segment_3}'"}{cat_name}{/exp:query} &mdash; Kategoria &mdash;
{if:elseif segment_1 == 'notebook' OR segment_1 == 'photos' OR segment_1 == 'links' OR segment_1 == 'videos' OR segment_1 == 'quotes'}
{if segment_2}{exp:channel:entries limit="1" channel='{segment_1}'}{title}{/exp:channel:entries} &mdash;{/if}
{exp:channel:entries limit="1" channel='{segment_1}'}{channel}{/exp:channel:entries} &mdash;
@ivuorinen
ivuorinen / quota.php
Created April 29, 2011 08:28
Find out your quota usage and print cute bar. Not the most elegant way, but works for me.
<?php
// Fetch the quota to temp file, grab the data and delete the file
system("quota -s > q.txt");
$raw_quota = file("q.txt");
unlink("q.txt");
$raw_quota = trim( $raw_quota[3] );
$raw_quota = str_replace(" ", " ", $raw_quota);
@ivuorinen
ivuorinen / fingerpori.php
Created August 6, 2011 13:36
fingerpori emailer
<?php
$p = "http://www.hs.fi/fingerpori/";
$p = file_get_contents($p);
preg_match_all('/\<img id="strip([0-9]+)" src="http:\/\/www.hs.fi\/kuvat\/iso_webkuva\/([0-9]+).jpeg" align="center" border="0" alt="" title=""\>/', $p, $m);
$img = $m[0][0];
if( empty($img) ) {
preg_match_all('/\<img id="strip([0-9]+)" src="http:\/\/www.hs.fi\/kuvat\/iso_webkuva\/([0-9]+).gif" align="center" border="0" alt="" title=""\>/', $p, $m);
$img = $m[0][0];
@ivuorinen
ivuorinen / ongelma.txt
Created August 16, 2012 10:50
Verkkokaupan tuotteiden tilaukseen PHP-looppaus
$obj = 0->
title-> Koko
options-> l = L
xl = XL
xxl = XXL
1->
title-> Väri
options-> musta = Musta
vihrea = Vihreä
@ivuorinen
ivuorinen / robots.txt
Created April 15, 2013 09:18
Koko sivuston poistaminen Googlen ja muiden hakukoneiden listauksista
User-agent: *
Disallow: /