On using Agents for helping with code creation

November 6, 2025

I see (use) code generated from Agents the same way as shorts: watch the good, talk about the best and everything else is unregistered noise.

Why we test software ?

November 24, 2022

To paraphrase uncle Bob from the “Clean Code” lectures: It is impossible to prove mathematically that software works, it can only be tested that it is not broken yet.

Something to think about.

How to show packed sprites with CSS and scale them

July 11, 2022

Example:

 

 


Reactjs component and calculations:

import React from 'react';

type props = {
    width: number,
    height: number,
    frame: { x: number, y: number, w: number, h: number },
    textureUrl: string,
    background?: string,
};

class TextureImageResizeComponent extends React.Component<props> {

    render() {
        let {
            width,
            height,
            background,
            frame,
            textureUrl,
        } = this.props;


        if (width === 0) {
            width = frame.w;
        }

        if (height === 0) {
            height = frame.h;
        }

        return (
            <div style={{
                width: width,
                height: height,
                position: 'relative',
                background: background,
            }}>
                <div style={{
                    backgroundImage: 'url(' + textureUrl + ')',
                    width: frame.w,
                    height: frame.h,
                    backgroundPosition: '-' + frame.x + 'px -' + frame.y + 'px',
                    backgroundRepeat: 'no-repeat',
                    display: 'inline-block',
                    transform: 'scale(' + (width / frame.w) + ', ' + (height / frame.h) + ')',
                    top: 0,
                    left: 0,
                    marginTop: ((height - frame.h) / 2),
                    marginLeft: ((width - frame.w) / 2),
                    position: 'absolute',
                }}>

                </div>
            </div>
        );
    }
}

export default TextureImageResizeComponent;

Easy swapping PHP variables

February 18, 2022

Using list() function to swap variables values without adding more variables.

$url = 'blog:5';
list($type, $id) = explode(':', $url);
// in case that the url is 5:block
if (!is_numeric($id)) {
    list($type, $id) = [$id, $type];
}

MySQL select rows where the sum of the rows is at least a value

January 7, 2020

Example table:

CREATE TABLE a
  (`id` int, `value` decimal(5,2))
;
	
INSERT INTO a
  (`id`, `value`)
VALUES
  (1, 5),
  (2, 1.25),
  (3, 3.7),
  (4, 17.3)
;

Goal – getting the rows in which the sum of value is 9.5

SET @counter := 0;

SELECT
  a.*,
  IF(@counter <= 9.5, 1, 0) AS included,
  (@counter := @counter + a.value) AS valueSum

FROM a
HAVING included = 1

The result:

id value included valueSum
1 5.00 1 5.00
2 1.25 1 6.25
3 3.70 1 9.95

Simple JavaScript seconds counter

November 19, 2019
/**
 * @author Ivan Gospodinow
 * @site http://ivangospodinow.com/?p=471
 *  
 * @param {callback} onUpdate
 * @return {callback} onStop
 */
export function countSeconds(onUpdate) {
    const start = new Date();
    const interval = setInterval(() => {
        onUpdate(parseInt((new Date().getTime() - start.getTime()) / 1000));
    }, 1000);

    return () => {
        clearInterval(interval);
    };
}

 
Usage:

/**
let seconds = 0;
let stopCounter = countSeconds(function(counter) {
  seconds = counter;
});

setTimeout(stopCounter, 5 * 1000);
console.log(seconds);
// 2

Software and teams

October 16, 2019

“Big teams create big software slowly” by Kevlin Henney

How is Game of Thrones going to end ?

April 16, 2019

Everybody dies and winter covers all of Westeros.

PHP multidimensional array to form hidden inputs

March 22, 2019
/**
 * Corvert array data to hidden inputs
 * to pass as form data
 *
 * Example: [data => [sub1 => 1, sub2 => 2]]
 * 
 * 
 *
 * @author Ivan Gospodinow
 * @see http://ivangospodinow.com/?p=455
 * @param array $array
 * @param [array | string] $exclude
 * @return string
 */
function arrayToHiddenInput(array $array, $exclude = null)
{
    $hiddens = [];
    $strParams = urldecode(http_build_query($array));

    if (!empty($strParams)) {
        $params = explode('&', $strParams);
        foreach ($params as $param) {
            list($name, $value) = explode('=', $param);

            if (is_array($exclude) && in_array($name, $exclude)) {
                continue;
            } else if ($name == $exclude) {
                continue;
            }

            $hiddens[] = sprintf(
                '',
                $name,
                $value
            );
        }
    }

    return implode(PHP_EOL, $hiddens);
}

Example:

echo arrayToHiddenInput(['data' => ['sub1' => 1, 'sub2' => 2]]);

Result:


Simple as that

Ethereum, Smart Contracts is a scam, sorry

December 2, 2017

Well, for 2 years online and zero working real live services, I have to call it – scam.

Code execution is limited to 15 seconds, which makes integration with 3rd party services not possible, thus falls most claims.

https://ethereum.stackexchange.com/questions/2598/is-code-execution-time-limited-by-the-block-time


Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /home/c2kblate/sites/ivangospodinow.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048
 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org