Skip to content

Instantly share code, notes, and snippets.

View ivuorinen's full-sized avatar

Ismo Vuorinen ivuorinen

View GitHub Profile
@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"
@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>
{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 / email.php
Created November 16, 2011 14:29
rot13 php obfuscation
<script type="text/javascript">document.write(
"<?php
// We run str_rot13 to email link to conceil it from spam bots
// then we make it clear for browsers using javascript.
// If client doesn't have javascript installed, hide css: .ebg13 (= obfuscated .rot13)
echo str_rot13( "<a class='rot13' href='mailto:" . $email . "'>" . $email . '</a>' );
?>".replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
</script>
<noscript>firstname.lastname@example.com</noscript>
@ivuorinen
ivuorinen / email_obfuscation.php
Created December 2, 2011 19:30
Email Obfuscation Shortcode for WordPress
<?php
/*
Plugin Name: Email Obfuscation Shortcode
Plugin URI: https://gist.github.com/1424515
Description: Shortcode for including emails into content and keeping spambots clueless. [obf email="email@example.com" noscript="what's shown to bots/people without javascript"]
Version: 0.1
Author: Ismo Vuorinen
Author URI: http://github.com/ivuorinen
*/
@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 / debug.php
Last active January 5, 2018 07:33
debug() to aid in your development
<?php
/**
* debug
* a magical function to use in your code
*
* @author Ismo Vuorinen <https://github.com/ivuorinen>
*
* @param mixed $thing The thing you want to see
* @param bool $echo Should we return or echo the output [default: false]