AuthorShaun

Hack This Site: Programming 2

Quite enjoyed this one, not something I do everyday

<?php
	// Set width of image
	$x = 100;
	$y = 30;

	$col = 0;
	$row = 0;
	
	$index = 0; 
	$last = 0;
	
	$string = '';
	
	$trans = array(
				".-" => "a",
                "-..." => "b",
                "-.-." => "c",
                "-.." => "d",
                "." => "e",
                "..-." => "f",
                "--." => "g",
                "...." => "h",
                ".." => "i",
                ".---" => "j",
                "-.-" => "k",
                ".-.." => "l",
                "--" => "m",
                "-." => "n",
                "---" => "o",
                ".--." => "p",
                "--.-" => "q",
                ".-." => "r",
                "..." => "s",
                "-" => "t",
                "..-" => "u",
                "...-" => "v",
                ".--" => "w",
                "-..-" => "x",
                "-.--" => "y",
                "--.." => "z",
                "-----" => "0",
                ".----" => "1",
                "..---" => "2",
                "...--" => "3",
                "....-" => "4",
         "....." => "5",
       "-...." => "6",
        "--..." => "7",
        "---.." => "8",
        "----." => "9"
	);
	// Set image
	$im = imagecreatefrompng("download.png");
	
	// for every row...
	while($row < $y):
		// iterate over cols...
		while($col < $x):
			$rgb = imagecolorat($im, $col, $row);
			
			if($rgb == 1):
				$string .= chr($index - $last);
				$last = $index;
			endif;		
			$index++;
			$col++;
		endwhile;
		// reset col
		$col = 0;
		$row++;
	endwhile;
	
	$chrs = explode(" ",$string);
	
	foreach($chrs as $chr):
		echo $trans[$chr];
	endforeach;
	
?>

Hack This Site: Programming 1

Quick and dirty solution…

<form method="post" action="">
	<textarea name="words"><?php echo $_POST['words'];?></textarea>
	<br>
	<input type="submit">
</form>
<?php
if($_POST):
	$dict = file('wordlist.txt');
	$list = array();
	$res  = array();
	
	foreach ($dict as $word):
		$word = str_replace("\n", "", $word);
		$word = str_replace("\r", "", $word);
		$tmp = str_split($word);
		sort($tmp);
		$tmp = implode('', $tmp);
		$list[$tmp] = $word;
	endforeach;
	
	$input	= $_POST['words'];
	$words	= explode("\n", str_replace("\r", "", $input));
	
	foreach($words as $word):
		$tmp = str_split($word);
		sort($tmp);
		$tmp = implode('', $tmp);
		echo $list[$tmp].",";
	endforeach;
	
endif;

Codefights: Kill K-th Bit

function killKthBit($n, $k) {
  return $k > strlen(decbin($n)) ? $n : (substr(decbin($n), -$k, 1) == 0 ? $n : bindec(substr_replace(decbin($n), '0', -$k, 1))) ;
}

How to extend WI-FI signal

My home office is in an old converted coal shed and all of my connectivity out here is achieved using powerline network adapters, so everything is wired through ethernet. WiFi is limited and can be pretty much classed as limited at best and my wife has moaned that she gets poor signal on her phone when she comes in here, and to be honest I want signal out in the garden so that I can connect Spotify up!

So the challenge; extend WiFi for free recycling old parts….

Continue reading

What happened to 100 Happy Days?

Well first of all, I forgot I had this blog! I’m a developer not a writer so this was never really at the front of my mind to be honest! Secondly, when I did remember I kind of had a thought that if I have to go each day looking to find something that made me happy, then can I really think of myself as happy? An epiphany¬†moment? Maybe…

Continue reading

© 2017 Shaun Gill

Hosted by Five50Up ↑