CategoryDevelopment

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

Raspberry Pi Wildlife Camera – Part 1

For someone who spends most of his time behind a computer screen, I love wild camping. Honestly, can’t get enough of it! The problem with it is though is that unless you’re going from place to place and setting up a new camp, things can get a little boring just sat around doing nothing. Granted, you can sit a whittle wood for a while, but there’s only so many spoons you can make!

Continue reading

© 2017 Shaun Gill

Hosted by Five50Up ↑