Programming

Passing an Array to bind_params

function make_refs_array($arr) {
    $ret = array();
 
    foreach($arr as $key => $value) {
        $ret[$key] = &$arr[$key];
    }
 
    return $ret;
}
 
function run_query() {
    $sql_query .= 'INSERT INTO table_table_table SET firstname=?, lastname=?;';
 
    $params = array('Max', 'Mustermann');
 
    if(!($stmt = $db->prepare($sql_query))) {
        print "\n$sql_query\n";
        echo $db->error . "\n";
        return True;
    }
 
    $params = array_merge(array(str_repeat('s', count($params))), $params);
 
    $bound = call_user_func_array(array(&$stmt, 'bind_param'), make_refs_array($params));
 
    if(!$bound) {
        var_dump($params);
        print "\n$sql_query\n";
        echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
        return True;
    }
 
    if (!$stmt->execute()) {
        print "\n$sql_query\n";
        echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
        return True;
    }
}

Why Typo3 Developers Drink

Concatenating multiple comparisons with AND, OR or NOT is not possible in f:if.

From the Fluid documentation

<div class="row">
    <f:if condition="{content_3}">
    <f:then>
        <f:if condition="{content_4}">
        <f:then>
            <f:if condition="{content_5}">
            <f:then>
                <div class="col-md-4">
                    {content_3 -> f:format.raw()}
                </div>
                <div class="col-md-4">
                    {content_4 -> f:format.raw()}
                </div>
                <div class="col-md-4">
                    {content_5 -> f:format.raw()}
                </div>
            </f:then>
            <f:else>
                <div class="col-md-6">
                    {content_3 -> f:format.raw()}
                </div>
                <div class="col-md-6">
                    {content_4 -> f:format.raw()}
                </div>
            </f:else>
            </f:if>
        </f:then>
        <f:else>
            <f:if condition="{content_5}">
            <f:then>
                <div class="col-md-6">
                    {content_3 -> f:format.raw()}
                </div>
                <div class="col-md-6">
                    {content_5 -> f:format.raw()}
                </div>
            </f:then>
            <f:else>
                <div class="col-md-12">
                    {content_3 -> f:format.raw()}
                </div>
            </f:else>
            </f:if>
        </f:else>
        </f:if>
    </f:then>
    <f:else>
        <f:if condition="{content_4}">
        <f:then>
            <f:if condition="{content_5}">
            <f:then>
                <div class="col-md-6">
                    {content_4 -> f:format.raw()}
                </div>
                <div class="col-md-6">
                    {content_5 -> f:format.raw()}
                </div>
            </f:then>
            <f:else>
                <div class="col-md-12">
                    {content_4 -> f:format.raw()}
                </div>
            </f:else>
            </f:if>
        </f:then>
        <f:else>
            <f:if condition="{content_5}">
            <f:then>
                <div class="col-md-12">
                    {content_5 -> f:format.raw()}
                </div>
            </f:then>
            <f:else>
            </f:else>
            </f:if>
        </f:else>
        </f:if>
    </f:else>
    </f:if>
</div>

Stupid Emacs Tricks 1 โ€“ Searching in LessCSS with CSS selectors

(defun less-search (search-string)
  "Search a LessCSS buffer for an expression such as
\".content .inner .banner img\",
matching both full expressions as well as nested ones.
 
This means that it should match anything in the form:
 
.content .inner {
    .banner {
        img {
 
        }
    }
}
 
TODO: handle the case of .block.banner matching .block { &.banner { ... } }
TODO: handle looping like a normal search function
TODO: interactive search??"
  (interactive "sSearch: \n")
  (let ((search-components (split-string search-string " "))
        (end-point (point-max))
        (found-point nil))
    (save-excursion
      (goto-char (point-min))
      (setq found-point (dolist (item search-components ret)
                                        ; Search is here limited to a
                                        ; range that starts as the
                                        ; whole buffer and gets
                                        ; gradually restricted by the
                                        ; matched elements.
                          (unless (equal end-point (point-max))
                            (save-excursion
                              (forward-list)
                              (setq end-point (point))))
                          (let ((search-point (search-forward item end-point t)))
                            (unless search-point
                              (error "Search failed"))
                            (setq ret search-point)))))
    (when found-point
      (goto-char found-point))
    found-point))