String equality tester
_Bool strequals(char* a, char* b) { if (!a || !b) return 0; do {if (*a != *b) return 0; } while (*a++ && *b++); return 1; }
11397 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
_Bool strequals(char* a, char* b) { if (!a || !b) return 0; do {if (*a != *b) return 0; } while (*a++ && *b++); return 1; }
function isSameString( s1, s2 )
{
alert( "s1: " + s1.toString() );
alert( "s2: " + s2.toString() );
if ( s1.toString() == s2.toString() )
{
return true;
}
else
{
return false;
}
}
between?: func [ value bound-1 bound-2 /exclusive /local low-bound high-bound ][ set [low-bound high-bound] sort reduce [bound-1 bound-2] either exclusive [ all [(value > low-bound) (value < high-bound)] ][ ;-- Inclusive comparison all [(value >= low-bound) (value <= high-bound)] ] ]
limit: func [ "Make sure val falls between lower and upper bounds, inclusive" val lower upper ][ max min val upper lower ]
$a = new Exception("foo"); try { throw $a; //Line 1 } catch (Exception $e) { throw $a; //Line 10; }
<?php class DumbException extends Exception { /** * Cleanup anything we need before serialisation * * @return string[] An array of member varible names to serialize * @see http://php.planetmirror.com/manual/en/language.oop5.magic.php */ public function __sleep() { return array('string','code'); } /** * Compare against another DumbException for equality. * * Since two exceptions can be !== because the trace / line / file * information is different, we need to do this. */ public function cmp(DumbException $e) { return (serialize($e) == serialize($this)); } } print '<pre>'; $a = new DumbException(); $b = new DumbException(); try { try { throw $b; } catch (Exception $e) { throw $a; } } catch (Exception $e) { var_dump($a === $b); var_dump($a == $b); var_dump($b === $e); var_dump($b == $e); var_dump($a === $e); var_dump($a == $e); var_dump($b->cmp($e)); var_dump($a->cmp($e)); } print '</pre>'; ?>
# with os.path.walk def delete_backups(arg, dirname, names): for name in names: if name.endswith('~'): os.remove(os.path.join(dirname, name)) os.path.walk(os.environ['HOME'], delete_backups, None) # with os.path, if (like me) you can never remember how os.path.walk works def walk_tree_delete_backups(dir): for name in os.listdir(dir): path = os.path.join(dir, name) if os.path.isdir(path): walk_tree_delete_backups(path) elif name.endswith('~'): os.remove(path) walk_tree_delete_backups(os.environ['HOME']) # with path dir = path(os.environ['HOME']) for f in dir.walk(): if f.isfile() and f.endswith('~'): os.remove(f)
# pygame's typical beginning import pygame from pygame.locals import * # pys60 import e32, graphics from appuifw import *
# pygame window = pygame.display.set_mode((468, 60)) # pys60 app.screen = 'full' # or 'normal', 'large'
# pygame screen = pygame.display.get_surface() # pys60 app.body = canvas = Canvas(None, key.handle_event) # you need to create key (a Keyboard instance) before this
# pygame monkey_image = pygame.image.load(file_name) # pys60 monkey_image = graphics.Image.open(file_name)
# pygame screen.blit(monkey_image, (0,0)) pygame.display.flip() # pys60 canvas.blit(monkey_image, target=(0,0)) # we may add a buffer, which will need buffer.blit(image) # and canvas.blit(buffer) for equivalent steps
# pygame sound = pygame.mixer.Sound(fullname) sound.play() # pys60 import audio sound = audio.Sound.open(fullname) sound.play()