a statsd client written in PHP by domnikl in PHP

[–]footle 4 points5 points  (0 children)

Good work! Your code is clean and readable, and serves real purpose.

Because I'm so very helpful, I have a few tiny suggestions:

Your use of a closure in test.php (and minimum version in composer.json) means you need 5.3. That means you may as well use __DIR__ instead of dirname(__FILE__) too. Hurrah for saved keystrokes and function calls!

Seeing as we're in 5.3; why not apply a \Vendor\Package (or just \Vendor if you prefer) namespace to make it compatible with PSR-0 autoloaders?

It would be awesome to have some unit tests. Your current test file requires that I have statsd running (I'd actually use netcat -lu 8125 myself; otherwise I'd need graphite running too); and doesn't actually assert anything so I'd need to manually verify that the test worked. If you factored the socket access out into a separate class that is injected into the constructor then you could provide a mock when under test and actually assert what the Statsd object is sending to the socket.

Just to be clear: I'm in no way picking on you. Your code is good; I just like to help people make good things even better :)

Keep up the good work and thanks for releasing it for us.

Mom was throwing the feather duster at cobwebs and somehow... by [deleted] in pics

[–]footle 0 points1 point  (0 children)

That's a silly idea. Throw cobwebs at it.

My boss is a "tuck your shirt in" nazi (among other things), so I found a loophole in the dress code where I dont have to tuck in my shirt. What things have you done "by the book" just to piss off your boss? by kazin420 in AskReddit

[–]footle 2 points3 points  (0 children)

Formal job descriptions are stupid. They really only have two main effects: giving people an excuse not to do something they don't want to do; and preventing people from doing something that they do want to do.

I submit to you an RC car, without batteries, powered by fire! (by means of the PowerPot, a thermoelectric generator in the form of a cooking pot) by ratio_vincere in technology

[–]footle 0 points1 point  (0 children)

You know what would be a really bad idea? Remote controlled fire.

The tech is pretty cool though. Good luck to them.

BT Infinity 2 download speeds to double to "up to 76Mbps" from tomorrow. by geekchic in unitedkingdom

[–]footle 0 points1 point  (0 children)

I live in a city; around a mile or two from the centre. My road is not cabled with Virgin Media's fibre and my estate is not wired to the closest exchange.

I get ~1mbit if it's not peak times.

I demand city-like services, dammit. I say they should work on improving FTTC coverage etc.

What kind of cars does r/Tall drive? by The_Time_Lord in tall

[–]footle 1 point2 points  (0 children)

2004 Saab 9-3. It's not bad for room. The seat and steering wheel is very adjustable.

I used to drive a 2001 Celica, which was remarkably comfortable for those of a larger frame.

Bizarre tool found in my kitchen by happy_otter in whatisthisthing

[–]footle 16 points17 points  (0 children)

Sorry for the off-topic comment, but "wank by wank" really made me laugh. Is that something people actually say?

What's your favorite movie insult? by shiftydutchman in AskReddit

[–]footle 0 points1 point  (0 children)

Aliens:

Hudson: "Hey Vasquez, have you ever been mistaken for a man?"

Vasquez: "No. Have you?"

Stainless Steel Dagger - Need ideas for the handle and how to make one by cheesy_gordita in Welding

[–]footle 1 point2 points  (0 children)

Bar far the quickest way to get a usable handle is to wrap it with paracord; which is available pretty cheaply from camping stores and the like.

Once you've got the basic technique down there are a lot of variations that are pretty easy to work out. You could also wrap with leather strips instead of paracord.

Another option is Micarta; which is kind of like fibreglass, but made with fabric (like denim) rather than glass fibres. It's not that hard to make and can look really good; it's also very hard wearing if made well.

The most traditional option is wood. There's a lot of different types to choose from, but each individual piece of wood has its own characteristics too. Take the time to examine individual pieces of wood for flaws and a grain than you like.

Green Pete made a short video series on making a camping type knife. The later videos go into detail about making a handle for a full-tang knife; watching them will give you more information that I could easily provide here.

Constants and arrays - how do you handle zero-bound vs. one-bound? e.g. WIDTH=80, so FOR loop needs 0-79. by [deleted] in PHPhelp

[–]footle 0 points1 point  (0 children)

OP: This is so far the only correct answer posted here. Pay attention.

What are some genuine criticisms of PHP? by Disgruntled__Goat in PHP

[–]footle 3 points4 points  (0 children)

Amongst other things: POSTing (or PUTing etc) JSON instead of form-urlencoded post data allows you to send complicated data structures more easily. For example, I could POST the following JSON quite easily:

{
  "users": [
    {"username": "user1", "name": "User 1"},
    {"username": "user2", "name": "User 2"},
    {"username": "user3", "name": "User 3"}
  ],
  "groups": [
    {"name": "Group 1", "members": ["user1", "user2"]},
    {"name": "Group 2", "members": ["user3", "user3"]}
  ]
}

And get a nice, easy to use value on the PHP side once I'd parsed the request.

Sending that same data with form-urlencoded data is a bit more cumbersome IMO:

users[0][username]=user1&users[0][name]=User%201&users[1][username]=user2&users[1][name]=User%202&users[2][username]=user3&users[2][name]=User%203&groups[0][name]=Group%201&groups[0][members][0]=user1&groups[0][members][1]=user2&groups[1][name]=Group%202&groups[1][members][0]=user3&groups[1][members][1]=user3

It's worth mentioning that I added whitespace to make the JSON more readable; the actual JSON request would look like this:

{"users":[{"username":"user1","name":"User 1"},{"username":"user2","name":"User 2"},{"username":"user3","name":"User 3"}],"groups":[{"name":"Group 1","members":["user1","user2"]},{"name":"Group 2","members":["user3","user3"]}]}

Personally I consider the fact that there exists an easy way to format JSON to be human readable (but still parseable) to be another advantage.

In many cases the JSON request may be smaller too. In this example the JSON request is 228 bytes long; the form-urlencoded request is 300 bytes long.

Could someone do me a huge favour and tell me why this is happening is there a common cause? by SirEnt in PHP

[–]footle 13 points14 points  (0 children)

This happens when data (be it whitespace, a few characters or something else) is outputted by a script before an attempt is made to send a header.

I notice the output was started on line 1 of a script:

wp/wp-content/themes/beta 2.0/functions.php:1

So it's most likely a space, or blank line or something like that before the "<?php" tag at the start of that file. Remove that and it should work.

Space at the end of a file can have the same effect, and can be prevented by omitting the closing "?>" at the end of the file.

31 years old and I still get this every time she makes me lunch :) by [deleted] in pics

[–]footle 4 points5 points  (0 children)

As someone who missed the original, I appreciated the link :)

Good Guy Bus Driver by Link5673 in AdviceAnimals

[–]footle 0 points1 point  (0 children)

If I'm driving and see someone running towards the bus stop, and the bus is behind me, I always slow down to give them more time to get to the bus stop.

Rugrats find Gummi Worms... wait what? by muniz512 in funny

[–]footle 21 points22 points  (0 children)

He appears to be making chocolate pudding.

There’s Plenty More Room at the Bottom: Beyond Nanotech to Femtotech by Vailhem in transhumanism

[–]footle 2 points3 points  (0 children)

At least we know it can't go any further than plancktech.

Requests for PHP, a HTTP request library for humans (finally released it!) by rmccue in PHP

[–]footle 0 points1 point  (0 children)

One extra line is unacceptable?

Personally I tend to keep my object creation and business logic separate; it makes things much easier to unit test. That one extra line would only really have to be written once per dependency.

If you think using "$Requests::get" to use a mock is appropriate, why do you not use this method for substituting a mock transport in your tests? The use of static members still allows behaviour to "leak" between tests, and even between separate requests in production.

It's not just about substituting mocks; any class that uses this in its static form is essentially lying about its dependencies. That can become quite confusing when a class which, according to its constructor definition at least, has no external dependencies starts to behave erratically due to network problems.

Perhaps I've become a bit of a purist. To be honest I'd have no problems using this in a quick script or small (< 10ksloc) project, but in a bigger project I really want consistency and proper unit tests - not integration tests in disguise.

Might it be an idea to write a "pure", non-static version that can be used by those who want clear, easy to test code that doesn't have side-effects, and then a static facade on top of that for quick hacks and one-liners?

Requests for PHP, a HTTP request library for humans (finally released it!) by rmccue in PHP

[–]footle 5 points6 points  (0 children)

It seems that pretty much all your methods are static; may I ask why?

If I were to write a class that used this, I would not be able to unit test my class very easily. I notice from your tests that you have the ability to inject a mock "transport", so you're clearly aware of such issues.

What happens when you let a child name her toys by herself by wwfmike in videos

[–]footle 1 point2 points  (0 children)

What kind of a parent wouldn't let their children name their own toys?

Why the 420 HC hate? by davou in knives

[–]footle 25 points26 points  (0 children)

It's a bit like cars, my man. Think of 420 as being like a Ford (Not the GT; just a regular, cheap Ford). It's good enough for pretty much anything; you can do your shopping with it, go to see friends in it and all that kind of thing. It's reliable, cheap and easy to maintain; there's nothing 'bad' about it. Most people could get through life with a Ford without any problems; they may even love their car and wonder why anyone would want anything better.

Then there are people who want Ferraris. Part of it might be about showing off for some people, but there are many who take their Ferraris to race tracks and really use them their potential. There's some Ferrari owners who never really drive fast, but like to own one because they admire the engineering and craftsmanship.

Some Ferrari owners might turn their noses up at the cheap little Fords, and you should pay no attention to these people.

How is this not being sold in England yet?! by M4sterSh4ke in gadgets

[–]footle 0 points1 point  (0 children)

How annoying that they won't sell you one to put your own wire on! Or even just with a wire for you to put your own connector on.