
PHP in a Tweet - EmanueleMinotto
http://www.emanueleminotto.it/php-in-a-tweet
======
whalesalad
I enjoy PHP like I enjoy going home to see my family for the holidays. It's
fun for a bit, the nostalgia makes me feel warm and fuzzy, and the familiarity
of everything is very comforting. You quickly realize though that the grass
really is a lot greener on the other side. You remember why you moved out of
your parent's place and went out on your own.

It's hilarious looking at how cryptic these one-liners are, particularly when
I consider that with languages like Ruby and Python you can do a LOT with a
tiny little line if code.

As a side-note, one of my favorites is summing an array in Ruby:

    
    
      x = [1, 2, 3, 4, 5]
      x.inject &:+
      => 15

~~~
sevenproxies
In PHP

    
    
       array_sum([1, 2, 3, 4, 5]);

~~~
tel
In case this was a serious entry... which I honestly can't tell.

The problem with array_sum is not that it's too long but instead that it's
combined two rather specific bits of functionality into a fixed (if common)
form, while the Ruby code separates the ideas of "folding" and "addition"
allowing for many orthogonal creations.

To pick another favorite, in Haskell you could write

    
    
        Foldable.foldl1 (+)
    

which sums any foldable thing—anything which has elements which can be
combined together one-by-one. So it'll apply to Trees or Sets or Dictionaries
(well, Maps) just as easily while also allowing things like (+) to be replaced
by other binary operators.

~~~
afrdofdwnvtes
Well how about this then.

    
    
        foreach(array(1,2,3,4,5) as $x) $i=$i+$x; echo $i;

~~~
tel
The array_reduce answers get closer to what I was looking for. This might be a
"one line" answer, but it requires two special forms, assignment, sequencing
operators (;), and two fresh variables.

------
crucialfelix
people have been creating 140 character music pieces in the supercollider
music language for a while. its very tricky to make something that lasts and
evolves and has structure and keeps your interest.

here are some great ones:

[http://fredrikolofsson.com/f0blog/?q=node/478](http://fredrikolofsson.com/f0blog/?q=node/478)

play{a=SinOscFB;sum({|i|a.ar(a.ar(a.ar(a.ar(i+1,1/9,999),1/9,a.ar(1/9,1,1/9)),a.ar(0.1,3),i+2
_999),a.ar(1 /9,1/9),1/9)}!9)!2}//#SuperCollider

r{loop{x={GVerb.ar(MoogFF.ar(ClipNoise.ar_0.4,LFPar.kr({0.3.rand}!2,0,600,990)),9,9,1)}.play(s,0,19);3.wait;x.release}}.play//#SuperCollider

audio examples on the page above

~~~
crucialfelix
this one is amazing:

play{a=LFPulse;b=(1..4);Mix(a.ar(a.ar(a.ar(a.ar(b/32)+1/8)+1 _b)+(Mix(a.ar(b
/64))+a.ar(4/b)_(a.ar(a.ar(b/8)) _2+b))_ 100))/8!2}//#SuperCollider

audio:

[http://fredrikolofsson.com/f0blog/files/audio/tweet0020.mp3](http://fredrikolofsson.com/f0blog/files/audio/tweet0020.mp3)

"this tweet is also totally deterministic and without any randomness. here a
lot of nested square wave oscillators creates the complexity. basically there
are 4 channels/voices mixed down to one and then duplicated in left and right
channel. there are three levels deep nesting of frequency modulation with
another set of square waves mixed and added."

~~~
_quasimodo
Reminds me of those:

[http://www.youtube.com/watch?v=GtQdIYUtAHg](http://www.youtube.com/watch?v=GtQdIYUtAHg)

[http://www.youtube.com/watch?v=qlrs2Vorw2Y](http://www.youtube.com/watch?v=qlrs2Vorw2Y)

[http://www.youtube.com/watch?v=tCRPUv8V22o](http://www.youtube.com/watch?v=tCRPUv8V22o)

:)

~~~
crucialfelix
Yeah I remember those ! In fact I did some bit shift melody stuff myself in
supercollider based on those and some other code.

One of the sc people released an iPhone app that let's you write bitshift
based melodies.

The early stuff that supercolliders creator James McCartney did really set the
style for short, mathematically elegant music. It's really a great language
for it. You can do operations on arrays, and do interesting multichannel
expansion.

------
eksith
At the risk of arousing some people's ire, I really like these tidbits that
try to squeeze maximum functionality (albeit a bit dangerous) into a minimum
span of characters. It feels a bit like the underhanded C contest in a way
since there are so many magnificent ways to self-destruct doing this, but at
the same time it's a fun challenge.

A while ago, I put together a dirt-simple URL shortener
[https://twitter.com/eksith/statuses/275709375665037312](https://twitter.com/eksith/statuses/275709375665037312)

A bit of background: [http://eksith.wordpress.com/2012/12/03/id-
obfuscation](http://eksith.wordpress.com/2012/12/03/id-obfuscation)

~~~
draegtun
You might find Rebmu interesting, its a Rebol dialect designed for code
golfing -
[https://github.com/hostilefork/rebmu](https://github.com/hostilefork/rebmu)

Here's a fun(!) presentation of Rebmu given by Dr. Rebmuthalamonious
Golfstanipetrovitch (!!) given at the recent Rebol/Red conference -
[http://www.youtube.com/watch?v=iDKaz1iB9wQ](http://www.youtube.com/watch?v=iDKaz1iB9wQ)

Enjoy! :)

~~~
eksith
That was wonderful. Thank you! :D

------
purge
Don't invite Perl to this party

~~~
erikig
Too late, and she brought JavaScript too...

~~~
contingencies
Wow, Perl's seen better days but I think they're a good match for each other.
Perl's fascinated by JavaScript's objectivity and popularity, and JavaScript's
wearing Perl for retro effect like some kind of fashion item. The two of them
are like darkness and light. No prize for guessing who brought the drugs...

------
draegtun
Unfortunately it's only available via WayBackMachine now but there was a fun
_Webapp in a 140 character tweet_ challenge back in the day (2009!) -
[http://web.archive.org/web/20111221094809/http://f055.net/ar...](http://web.archive.org/web/20111221094809/http://f055.net/article/final-
wrap-up-of-the-140-characters-webapp-challenge/)

------
stdclass
There was something similar with JavaScript called 140byt.es [1]

[1] [http://140byt.es/](http://140byt.es/)

------
iguana
I see your PHP and raise you this Perl:

[http://pastebin.com/7UqSFWz7](http://pastebin.com/7UqSFWz7)

------
clienthunter
I raise PHP _and_ MySQL in a Tweet.

[http://bit.ly/1hA9mZn](http://bit.ly/1hA9mZn)

------
aaronem
I'm really conflicted on what opinion to have of this. On the one hand, these
PHP constructs are even worse than most of what you see in that language, but
on the other hand, constraining PHP sources to a maximum length of 140
characters should help reduce the scope of the contagion.

------
joeframbach
The first one isn't very good. The slashes are optional anyway.
[http://bits.blogs.nytimes.com/2009/10/12/the-webs-
inventor-r...](http://bits.blogs.nytimes.com/2009/10/12/the-webs-inventor-
regrets-one-small-thing)

------
notJim
A friend of mine has an MVC library where each component fits in a tweet:
[https://github.com/jeremeamia/tweetmvc-
core/blob/master/twee...](https://github.com/jeremeamia/tweetmvc-
core/blob/master/tweetmvc.php)

