Skip to content

Commit

Permalink
feat: wayback rescue old unhappy far-off things (cringe blog posts fr…
Browse files Browse the repository at this point in the history
…om 2012)
  • Loading branch information
crookm committed Jan 1, 2024
1 parent 9b14673 commit d1a1007
Show file tree
Hide file tree
Showing 10 changed files with 540 additions and 4 deletions.
7 changes: 3 additions & 4 deletions archetypes/posts.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
---
title: {{ replace .Name "-" " " | title }}
slug: {{ .Name }}

description: |
This is a lede
This is a lede
categories: Something
tags:
- one
- two
- one
- two

date: {{ .Date }}
draft: true
Expand Down
31 changes: 31 additions & 0 deletions content/posts/2012/an-introduction-is-in-order-this-is-me.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: An Introduction Is In Order, This Is Me

description: |
A post rescued from an old blog of mine from the Wayback Machine. I was 14 when I wrote this, so it's a bit cringy.
This was my first ever blog post as 'me'.
categories: Personal

importSource: hlx
importDate: 2024-01-01T23:00:00+13:00

date: 2012-11-06T12:00:00+13:00
---

I’m not too good with introductions, but I’ll give it my best.

I recently made this blog to share my knowledge with programming, and to bitch about my personal life.

I feel I should warn you, I do not plan on enabling comments on any posts. I simply do not want to reply to low quality questions, or deal with any spam.

I will try to post as much as I can, but no promises...

I am quite savvy with PHP, HTML, JavaScript, and I’m learning a bit of Java and Pearl. Though Java looks really difficult, I may put that off a while.

I am interested in games like Minecraft, Skyrim, and crazy Japanese games. My favourite game at the moment is LSD: Dream Emulator.

I have had experiences as a Moderator on a large Minecraft server called "CityCraft" (citycraft.co.uk). I decided to leave because of the rude-mannered children that occupy the server. The only decent people that I could talk to were the other staff members.

I’ll take this opportunity to say a bit about what I may be posting here. I plan to release code snippets, free downloads, and tutorials.
59 changes: 59 additions & 0 deletions content/posts/2012/convert-images-to-ascii-with-php.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Convert Images to ASCII With PHP

description: |
A post rescued from an old blog of mine from the Wayback Machine. I was 14 when I wrote this, so it's a bit cringy.
I'm not convinced I did this all by myself, probably bodging from across the internet - but yeah it's interesting.
categories: Development
tags:
- php

importSource: hlx
importDate: 2024-01-01T23:00:00+13:00

date: 2012-11-30T12:01:00+13:00
---

Some forums, bulletin boards, blogs, and other text platforms allow basic BBcode but are strict against images. With this simple PHP script, you can convert any JPG image to HTML (or BBcode) text.

```php
<?php

function getext($filename) {
$pos = strrpos($filename,'.');
$str = substr($filename, $pos);
return $str;
}

$image = 'image.jpg';
$ext = getext($image);
if($ext == ".jpg"){
$img = imagecreatefromjpeg($image);
}
else{
echo'Wrong File Type';
}

$width = imagesx($img);
$height = imagesy($img);

for($h=0;$h<$height;$h++){
for($w=0;$w<=$width;$w++){
$rgb = imagecolorat($img, $w, $h);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if($w == $width){
echo '<br>';
}else{
echo '<span style="color:rgb('.$r.','.$g.','.$b.');">#</span>';
}
}
}

?>
```

**NOTE**: Like all GD-based scripts, this needs a really decent server to adequately run without interference.
75 changes: 75 additions & 0 deletions content/posts/2012/getting-the-size-of-a-remote-file-in-php.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: Getting the Size of a Remote File in PHP

description: |
A post rescued from an old blog of mine from the Wayback Machine. I was 14 when I wrote this, so it's a bit cringy.
I was still new to PHP and programming in general, so I believed that complex code was better code.
categories: Development
tags:
- php

importSource: hlx
importDate: 2024-01-01T23:00:00+13:00

date: 2012-11-06T12:01:00+13:00
---

This script gets the external file size of anything. This script is really good for forum systems, or anything with a limit of file size.

Here:

```php
<?php

// NOTE FROM THE FUTURE:
// > This code is actually insecure, do not use it -
// bonus points if you can find the vulnerabilities.
// > It is kept here as a record of my progress as a programmer.

$url = "https://mattcrook.io/favicon.ico"; // Put the URL you want to get the filesize of here

function getRemoteFileSize($urll){
$parsed = parse_url($urll);
$host = $parsed["host"];
$fp = @fsockopen($host, 80, $errno, $errstr, 20);
if(!$fp){
return false;
}else{
@fputs($fp, "HEAD $urll HTTP/1.1\r\n");
@fputs($fp, "HOST: $host\r\n");
@fputs($fp, "Connection: close\r\n\r\n");
$headers = "";
while(!@feof($fp)){
$headers .= @fgets ($fp, 128);
}
}
@fclose ($fp);
$return = false;
$arr_headers = explode("\n", $headers);
foreach($arr_headers as $header){
$s = "Content-Length: ";
if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) {
$return = trim(substr($header, strlen($s)));
break;
}
}
if($return){
$size = round($return / 1024, 2);
$sz = "KB";
if ($size > 1024) {
$size = round($size / 1024, 2);
$sz = "MB";
}
$return = "$size $sz";
}
return $return;
}

echo "Total filesize: " . getRemoteFileSize($url) .""; // Final

?>
```

Hope this helps out :)
70 changes: 70 additions & 0 deletions content/posts/2012/overlay-watermarks-on-images-in-php.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: Overlay Watermarks on Images in PHP

description: |
A post rescued from an old blog of mine from the Wayback Machine. I was 14 when I wrote this, so it's a bit cringy.
categories: Development
tags:
- php

importSource: hlx
importDate: 2024-01-01T23:00:00+13:00

date: 2012-11-07T12:01:00+13:00
---

Hi,

This PHP script will overlay an image on an image. This is useful for photography galleries and blogs.

```php
<?php

// NOTE FROM THE FUTURE:
// > Working with files is risky business, it is best to make use
// of a service dedicated to this sort of thing.
// > It is kept here as a record of my progress as a programmer.

function add_watermark($image) {
$overlay = 'OVERLAY_IMAGE_HERE.png';

$w_offset = 0;
$h_offset = 0;

$extension = strtolower(substr($image, strrpos($image, ".") +1));

switch ($extension) {
case 'jpg':
$background = imagecreatefromjpeg($image);
break;
case 'jpeg':
$background = imagecreatefromjpeg($image);
break;
case 'png':
$background = imagecreatefrompng($image);
break;
default:
die("Image type not supported");
}

$base_width = imagesx($background);
$base_height = imagesy($background);
imagealphablending($background, true);

$overlay = imagecreatefrompng($overlay);

imagesettile($background, $overlay);

// Make the image repeat
imagefilledrectangle($background, 0, 0, $base_width, $base_height, IMG_COLOR_TILED);
header('Content-type: image/png');
imagepng($background);
}

echo add_watermark('IMAGE_FILE_HERE.png'); // Insert an image here.

?>
```

**NOTE**: This script does not cache files. I may post a tutorial later about caching dynamic files.
80 changes: 80 additions & 0 deletions content/posts/2012/php-calculator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: PHP Calculator

description: |
A post rescued from an old blog of mine from the Wayback Machine. I was 14 when I wrote this, so it's a bit cringy.
categories: Development
tags:
- php

importSource: hlx
importDate: 2024-01-01T23:00:00+13:00

date: 2012-11-06T12:02:00+13:00
---

Today I have conjured a small php calculator script, coded in PHP. There are no limits, and I made sure its a little less hackable :)

Well here it is.

```php
<?php

function clean($input){ // Clean the input
$input = strip_tags($input);
$input = htmlentities($input);
return $input;
}

$submit = clean($_POST['submit']);
$value1 = clean($_POST['value1']);
$value2 = clean($_POST['value2']);
$action = clean($_POST['action']);
if($_POST['submit']){ // If they click the button, do this
if($action === 'plus'){
$result = $value1+$value2; // If the user selected an addition sum
}
else if($action === 'min'){
$result = $value1 - $value2; // If the user selected a subtraction sum
}
else if($action === 'keer'){
$result = $value1 * $value2; // If the user selected a multiplication sum
}
else if($action === 'delen'){
$result = $value1 / $value2; // If the user selected a division sum
}
else if($action === 'procent'){
$result = $value1 % $value2; // Work with percentages
}
}

// Below is the HTML stuff, that the user will see.
?>
<html>
<head>
<title>Calculator</title>
</head>
<body>
<form method="POST" action="calculator.php">
<p>
<input type="text" name="value1" value="fill something in here" onFocus="if(this.value == 'fill something in here') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'fill something in here';}" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name="action">
<option value="plus">+</option>
<option value="min">-</option>
<option value="keer">*</option>
<option value="delen">/</option>
<option value="procent">%</option>
</select>
<input type="text" name="value2" value="fill something in here" onFocus="if(this.value == 'fill something in here') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'fill something in here';}" />
&nbsp;&nbsp; </p>
<br />
<br />
<input type="submit" name="submit" value="Calculate!" />
</form>
<br />
<?php echo $result; ?>
</body>
</html>
```

0 comments on commit d1a1007

Please sign in to comment.