Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
May 12, 2014
Chris
PHP
Comments Off on “Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem

“Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem

PreviousNext
php

This little projects is basically super-simple, but somehow really really clever and definitly a time-saver: Belt is a typical Composer-loaded dependency that adds a lot of useful functions “to PHP”. Some of these functions are more or less duplicates of already existing one in native PHP, buuuut they solve the common unsteady needle / haystack vs. haystack /needle parameter-order problem in PHP (and narrow to the beautiful Java / JavaScript function/method naming convention). A very interesting project, hopefully with a great future! Let’s see some examples (some examples show callable code, some show method definitions):

// returns the max value of an array
Belt::max([1, 2, 3]); // => 3

// checks if arguments are equal
Belt::isEqual("yeah", "nope"); // => false

// flattens a multi-dimensional array
Belt::flatten([1, [2, [3]]]) // => [1, 2, 3]

// create an array containing a range of elements, optional with steppings
Belt::range(1, 10, 2); // => 1, 3, 5, 7, 9

// returns an array containing the unique items in both arrays
union($array1, $array2)

// execute $closure only once and ignore future calls [interesting stuff!]
once(Closure $closure)

// only execute $closure after the exact $number of failed tries
after($number, Closure $closure)

// escape all HTML entities in a string
escape($string)

// invoke a $closure $number of times
times($number, Closure $closure)

// iterate through $collection using $iterator
each(array $collection, Closure $iterator)

// convert $value to an array
toArray($value)

// group values in $collection by $iterator's return value
groupBy(array $collection, Closure $iterator)

// determine whether the given object has a key
has($object, $key)

// copy all properties from $source to $destination
extend($source, $destination)

// fill in any missing values using $defaults
defaults($object, $defaults)

// determine whether the given value is a float or an integer
isNumber($value)

Link: Belt on GitHub

belthaystackmethodnamesnaming conventionsneedlePHP
Share this
hearthbleed-ssl-bug

The SSL Heartbleed bug explained in 30 seconds

Another excellent comic by xkcd (a site that publishes dev/op/web-related comics, usually nailing things right to the head): This time

php

How to prevent PHP sessions being shared between different apache vhosts / different applications

When you run multiple applications on one server, you might run into the session-sharing problem: All your applications share the

How to get a single table out of a massive MySQL .sql database backup file (mysql dump splitter)

Imagine the following situation: Somebody backs up an entire MySQL database – a very large one – with common tools.

How to fix the ugly font rendering in Google Chrome

Update, August 2014: Google has rolled out Chrome 37, which finally fixes this issue nativly. Yeah! For historical reasons the

php

Is there a JSFiddle for PHP ? Yes !

It’s awesome how UNknown these little and extremely powerful tools are: There are some online tools that let you paste

Experimenting with HHVM at Etsy (Link)

Extremely interesting blog post of Etsy on how they try out HHVM / HipHop: https://codeascraft.com/2015/04/06/experimenting-with-hhvm-at-etsy/

How major web companies (and banks) handle passwords quite wrong

There’s a very interesting “movement” in password handling going on for a long time, the basic idea is to encourage

php

[Link] How to create, read, update and delete (CRUD) with PDO, MySQLi and MySQL the right way (prepared statements)

Mike Dalisay has written an excellent tutorial on the CORRECT USAGE of basic CRUD functions (create, read, update, delete) with

The architecture of StackOverflow

One of the most interesting talks these weeks, and a rare insight into one of the most active pages on

organizing css

Jonathan Snook – CSS is a Mess – How to organize CSS in big projects (54min video talk)

1/4

Categories

Search

js javascript
JavaScript Testing Tactics (21min video by Justin Searls)
vagrant
How to setup a (or multiple) server/LAMP-stack inside a virtual machine for local development with Vagrant and PuPHPet
unreal-4-engine
Tim Sweeney talks about the future of game graphics (and which hardware we need to “clone” reality)
digitalocean coupon
DigitalOcean VPS coupon codes for december 2013 and early 2014
php
appserver.io – A New Way of Magento Enterprise Infrastructure (26min video talk)
The architecture of StackOverflow
DEF CON 18 – When your computer got stolen and you can still SSH into it: “Pwned by the 0wner” (22min conference talk)
php
Postmodern PHP: appserver.io, a multithreaded application server for PHP, written in PHP
vagrant
How to setup a local server (in a virtual machine) with Vagrant in PHPStorm
How to install/setup latest version of PHPMyAdmin on Ubuntu 12.04 LTS (Precise Pangolin)
phpstorm 7.0 php
How to debug code on a remote server (or in vagrant box) with PHPStorm
(Links) How to fix an extremely slow Symfony inside a Vagrant box
dev coding cards deck
Nice gifts for devs: Nerdy playing-cards decks
Hacking ATMs – A conference talk about the current security state of Windows XP driven cash machines
composer
[Link] How to require versions of PHP, HHVM / HipHop, GD, curl, openssl etc. with Composer

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy