Home Entrance Wiki Search Login Register

Welcome, Guest. Please login or register.
March 06, 2023, 02:30:05 am
Forum activity rating: Five Star Posts: 102/24hrs Show Unread Posts | Unread Replies | Own Posts | Recent Posts
News: :4u: ~~~~~~~~~~~  :4u:

Show Posts

* Messages | Topics | Attachments

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - TAS_1K

Pages: 1 [2]
16
Code
( macros )

%RTN { JMP2r }
%/2 { #01 SFT2 }
%RECT-W { .Screen/width DEI2 #00a0 SUB2 }
%RECT-H { .Screen/height DEI2 #00c0 SUB2 }
%RECT-MARGIN { #0050 }
%MOUSE { .mouse/x LDZ2 .mouse/y LDZ2 }
%-- { #0001 SUB2 }
%++ { #0001 ADD2 }

( devices )

|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]

( zero page )

|0000
	@canvas	 [ &x $2 &y $2 &w $2 &h $2 ]

( program )

|0100
	;text1 .canvas/x LDZ2 #0035 ;draw-text JSR2
BRK

@draw-letters ( letters length* x* y* color -- )
	(
		assign parameters to local variables
	)
	,&color STR  ( ws: letters length x y )
	.Screen/y DEO2 ( ws letters length x )
	,&x STR2    ( ws: letters length )
	,&length STR2 ( ws: letters )
	(
		reverse loop over each letter to draw them		
	)
	&loop ( ws: letters )
		,&length LDR2 ( ws: letters length )
		#0001 SUB2   ( ws: letters length )
		#0008 MUL2   ( ws: letters xoffset )
		,&x LDR2 ADD2
		.Screen/x DEO2 ( ws: letters )
		;draw-letter JSR2
		(
			decrease length, loop if > 0
		)
		,&length LDR2 #0001 SUB2
		DUP2 ,&length STR2
		#0000 GTH2 ,&loop JCN
	RTN
	BRK
BRK
( local )
&color $1
&x	$2
&y	$2
&length $2

@draw-letter ( letter -- )
    (
	  	the letter 'a' starts at offset #61 of the ascii table.
    )
    #61 SUB ( ws: char )
    (
		to get the offset, multiply char by 8.
		first, pad with 00 to get a short.
    )
	#00 SWP
	#0008 MUL2
	(
		add the font addr to offset and draw letter.
	)
	;font ADD2 .Screen/addr DEO2
	#05 .Screen/sprite DEO
	&draw-space
	RTN
BRK

(
	push all letters into the ws.
)
@draw-text ( addr* x* y* -- a... )
	(
		load length, add length and count to rs
	)
	STH2 STH2
	LDAk ( ws: addr* len / rs: )
	#00 ( ws: addr* len 00 / rs: )
	&loop
		STH2  ( ws: addr* / rs: len counter )
		DUP2  ( ws: addr* addr* / rs: len counter )
		INC2
		#00   ( ws: addr* addr* 00 / rs: len counter )
		STHrk 	( ws: addr* addr* 00 counter / rs: len counter )
		ADD2 LDA
		ROT ROT ( ws: c addr* / rs: len counter )
		STH2r  ( ws: c addr* len counter / rs: )
		INC
		DUP2
		NEQ ,&loop JCN
	POP2
	LDA #00 SWP
	STH2r STH2r
	#01 ;draw-letters JSR2
	RTN
BRK
&addr

@text1 20 "hello 20 "world

@font
	007e 0202 7e42 427e
	0040 4040 7e42 427e
	007e 4040 4040 407e
	0070 4844 4444 4870
	007c 4040 7040 407c
	007c 4040 7040 4040
	007c 4040 4e42 427e
	0042 4242 7e42 4242
	0000 1010 1010 1010
	003c 0808 0808 0870
	0044 4850 6050 4844
	0040 4040 4040 407c
	006c 5242 4242 4242
	0078 4444 4444 4444
	0038 4444 4444 4438
	007c 4444 7c40 4040
	0038 4444 4454 4834
	007c 4444 7c50 4844
	003c 4040 3804 0478
	007c 1010 1010 1010
	0044 4444 4444 4438
	0044 4444 4444 2810
	0044 4444 4444 5428
	0042 4224 1824 4242
	0044 4444 3c04 047c
	007c 0408 1020 407c
	0000 0000 0000 0000


 :happy:

Good lord. I don't think anyone's going to top this. Is this Assembly?


17
❤︎ ∙ Greetings and Introductions / Hey everyone
« on: January 26, 2022, 05:34:07 pm »
You can call me TAS_1K, or TAS, or TAS_1000. I'm not sure how I found my way here... I think I was browsing reddit, which led to GitHub, which led to some other site that led to Neocities, where I found another site and then this one.

Ironically it was during my morning standup meeting at work (I'm a programmer) and I noticed a topic where someone asked for help with a PHP question. Since I know PHP, I figured I would try to lend a hand, and here I am.

A little bit about me:

- I've been a programmer for the past fourteen years, and it's pretty much what I do most all day, every day. Between things like house chores, feeding my cat, etc.
- My name comes from a band that was active in Kelowna, BC around 2001. Their music was used in an early version of Club Penguin. When I was a kid, Club Penguin is essentially what got me into programming, and the internet in general. I learned PHP by hacking away at some of the first private server software for Club Penguin.
- I don't have any websites up currently, but I've been threatening to put a blog up for a while. I just never find time to actually write anything.

I'm happy to be here.


18
☔︎ ∙ Help & Tutorials / Re: php heck: making a search engine
« on: January 26, 2022, 05:21:37 pm »
Code
<form action="" method="POST">
 <label for="search-terms">enter search terms</label>
 <input type="text" name="search-terms" id="search-terms" value=''>
 <input type="submit" name="submit" value="Search"/>
</form>

<?php
// Comment out PHP error reporting
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);

$images = [];
$search_terms = [];
$termsWithoutResult = [];

if ($_SERVER['REQUEST_METHOD'] === 'POST':wink: {
 if ($_POST['search_terms']) {
  $original_search = $_POST['search-terms'];

  $altered_search = strtolower($original_search);
  $altered_search = trim($altered_search);
 
  $search_terms = explode(" ", $altered_search);
  $search_terms_amount = count($search_terms);
 }

 function doSearch($terms) {
  $directories = ["img/", "test/"];
  $filetypes = ["jpg", "jpeg", "bmp", "png", "gif"];

  if (count($terms) === 0) {
   return [];
  }

  $output = [];

  foreach ($directories as $dir) {
   $iterator = new DirectoryIterator($dir);

   foreach ($iterator as $file) {
    if ($file->isDot()) {
     continue;
    }

    $name = strtolower($file->getFilename());
    $extension = strtolower($file->getExtension());

    $term = getTermMatchingFilename($name, $terms);

    if ($term !== false && in_array($extension, $filetypes, true)) {
     $output[$term] = [
       'original_name' => $name,
       'extension' => $extension
     ];
    }
   }
  }

  return $output;
 }

 function getTermMatchingFilename(string $filename, array $terms) {
  foreach ($terms as $term) {
   if ($filename === $term || strpos($term, $filename) !== false) {
    return $term;
   }
  }

  return false;
 }

 $images = doSearch($search_terms);

 $termsWithoutResult = array_filter($search_terms, function ($term) use ($images) {
  return array_key_exists($term, $images);
 });
}
?>

<?php if (count($termsWithoutResult)): ?>
 <?php printf('No results for the following term(s): %s', implode(', ', $termsWithoutResult)); ?>
<?php endif; ?>

<?php foreach ($images as $term => $files): ?>
 <?php printf('%d results for %s', count($files), $term); ?>

 <?php foreach ($files as $file): ?>
  <div class="search-result">
   <div class="img-result">
    <img src="<?php echo $dir . $file['original_name']; ?>">
   </div>
   <div class="title-result">
    <p><?php echo $file['original_name']; ?></p>
   </div>
   <br>
  </div>
 <?php endforeach; ?>
<?php endforeach; ?>

I did a couple things here - first off, since you're always referencing the $images and $search_terms variables in your output, I added some defaults for those for cases where the page is first requested, which will be a GET request usually.

When it is a POST request, we'll first check for the existence of the search_terms field just to be sure it exists. If so we'll go ahead with unpacking that string into an array.

Then the bulk of the logic's been moved into the doSearch() function. It uses something called a guard clause to return early if for some reason we got something like an empty string and there are no terms in the array. In that case it just gives you an empty array - if there are no terms to search, there's no images to match.

Then it goes on to loop over all the directories you've specified. I removed the is_dir() check because presumably since you control the array of directories, these should always exist. If they might not always exist though, then that check can go back up to the beginning of the foreach loop.

Next we create a DirectoryIterator and loop over it. If we're dealing with a dot file, we skip to the next one - in case you're unfamiliar, these files are something in UNIX filesystems, basically it is a reference to the current directory (.) and the parent directory (..).

Otherwise we'll get the name and extension similar to how you did before, and check if the name and extension belong to the terms and extensions arrays respectively. If so we add the current file to our output array.

Finally once we've iterated over everything, it returns the output array. So whenever a POST request is made we'll call this function and get an array of some sort.

Haven't tested this code yet so let me know if you run into any errors and I'm happy to help or fix anything I might have foobared in the process. It's still pretty early so I might've missed something.

edit: Made some more changes, mainly around filename matching and how the "number of results" or "there are no results for blank" bits are output.


Pages: 1 [2]


Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021, Simple Machines | SMFPacks Super Quote Forum Guide | Rules | RSS | WAP2


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery!