Shared posts

27 Feb 07:17

Elegant Function Timer Method Decorator in CoffeeScript

CoffeeScript is so badass. Given its transpiling and symbiotic nature, we can borrow our favorite conventions from our favorite languages and let the ugly, optimized JavaScript runtime version get compiled behind the scenes.

This is great news for people like myself who entered the programming game via Ruby (and/or were spoiled by it) and now struggle to efficiently read and write code if it is not simple and concise and has that human-readable touch. In today’s landscape of endless mountains of JavaScript, any help to mask its shortcomings and break out of “callback hell” is a welcomed improvement to my workflow and code structure.

Method Decorators

In this vain, I have struggled with the lack of a good pattern for decorating methods - doing things before, after, or around functions. For the Rubyist on Rails, you can think of the handiness of ActionController’s filter methods and ActiveRecord’s callbacks. But alas, JavaScript makes it syntactically tricky with its function scoping and closures to properly pass arguments and callback functions around in a peaceful manner.

Then I discovered Reginald Braithwaite’s awesome method decorators and combinators:

method-decorators.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
this.before =
  (decoration) ->
    (base) ->
      ->
        decoration.apply(this, arguments)
        base.apply(this, arguments)

this.after =
  (decoration) ->
    (base) ->
      ->
        decoration.call(this, __value__ = base.apply(this, arguments))
        __value__

this.around =
  (decoration) ->
    (base) ->
      (argv...) ->
        __value__ = undefined
        callback = =>
          __value__ = base.apply(this, argv)
        decoration.apply(this, [callback].concat(argv))
        __value__

Definitely read Reginald’s post for more of an overview on these. But for now, onto the practical example.

The Timer

I’ve been mainly working on native-wrapped HTML5 mobile apps lately and I wanted a way to easily profile any function and log the milliseconds it takes to execute. It turns out I was able to do this as a small extension to this.around.

1
2
3
4
5
6
@timer = (name) ->
  around (fn) ->
    t = new Date().getTime()
    fn()
    ms = new Date().getTime() - t
    console.log("#{name} - #{ms.toString()}ms")

Give the timer a name and it applies an around filter to your returned function, which checks the difference between the milliseconds before and after the function call and prints it to the log. Your expected value of this and any named arguments will be maintained in your decorated method. For example, say you wanted to profile how long it takes a Backbone View to render.

dashboard.coffee
1
2
3
4
5
6
7
class Dashboard extends Backbone.View
  # ...
  render: timer("dashboard render") (collection) ->
    @$el.html @template items: (collection or @collection).toJSON()
    @

# example console log: dashboard render - 24ms

Easy peasy. This doesn’t account for deferred events like ajax callbacks, but it does let me analyze the client-side operations that I’m most interested in optimizing.

26 Feb 17:57

Photo



24 Feb 19:02

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki

by Christopher Jobson

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

Out of Disorder: Topographical Maps Carved from Electrical Tape and Intricate Thread Sculptures by Takahiro Iwasaki thread textiles sculpture

When first approaching the artwork of Japanese artist Takahiro Iwasaki it’s entirely possible you might miss it altogether. Not only are his small buildings and electrical towers excruciatingly small and delicate, but they also rest on absurdly mundane objects: rolls of tape, a haphazardly wrinkled towel, or from the bristles of a discarded toothbrush. Only on close inspection do the small details come into focus, faint hints of urbanization sprouting from disorder. My favorite pieces are his topographical maps that have been carefully cut from thick rolls of gray and blue electrical tape. Many of these objects were on view as part of the Constellations show at Cornerhouse in Manchester back in 2011 and at C24 Gallery last year. However Iwasaki currently has a new collection of much larger works at the 7th Asia Pacific Triennial of Contemporary Art at GOMA in Queensland, much of which you can see over at designboom. (via artscharity.org, cornerhouse, c24 gallery, karl steel)

23 Feb 03:09

Opinion: Why Your Collection Needs Eurogames

Yes, we’re still working on something. You’d better be patient, it’s still some way away.

In the meantime, Quinns continues his dirty scribbling for the big videogame sites. He’s doing good work, though! Look here! Over on Kotaku he’s written about why big ol’ licensed games aren’t the beginning and end of board gaming. A balanced diet needs Eurogames, for their fibre and slow-release energy. It goes a bit like this:

"You look over at them, and see your friend pushing around a perfect scale model of a Nebula Class science vessel, just like you guys did last week and the week before. With every round the novelty wears off a little more. You see your friends now, moving their fleets like dissatisfied toddlers pushing their food around. They’ve seen all the cards. They know all the exploits. One of them is crying. You try and stand up. You think you have a token up your bum."

No, I don’t know, either. Go read!

23 Feb 03:03

http://www.lememe.com/archives/30390

by daniel

22 Feb 21:03

Adam Friedman

by Caroline Kurze

Modern societies attempt to understand and explain the mysteries of nature through various tangible human lenses such as science, technology, painting, literature, photography, etc. But try as we might, our interpretations, theories, reproductions, and commentaries of the natural world will never truly do it justice. Through our various strategies, we impose and accept ‘rules’ of nature as factual knowledge and through these arbitrary conceptual binaries, we deny its’ overwhelming mystery.

Adam Friedman recognizes himself guilty of this as well. He paints symbols and tropes that we comprehend as landscape; mountains, sunsets, etc. But he is also curious what happens when we view nature through a lens that breaks the rules of our understanding. In his work, rules of perspective, distance, and light are bent. Space can become a solid object and places are folded on top of one another. Millions of years are compacted into a single instant and rocks become fluid. Friedman strives to present a moment that defies human intervention in the landscape, and pays homage to the potential in the inexplicable.

All images © Adam Friedman

19 Feb 05:56

http://www.lememe.com/archives/30181

by daniel

19 Feb 05:54

Random image from fukung.net: f51f58d1ac40b5e1a88c84183b6b7430.jpg

17 Feb 03:26

Photo

by ohmyscience


17 Feb 01:53

Photo

by ohmyscience


17 Feb 01:51

How To Play The Keyboard

by Justin McGrath
17 Feb 01:39

Photo



16 Feb 20:57

Grendel Formant Filter – Voltage Language

by Surachai

Demonstrating synthesis of vowel sounds using the Grendel Formant Filter Eurorack module. This 100% analog filter allows voltage-controlled selection of English vowels from a 2-dimensional map. The map corresponds to the International Phonetic Alphabet vowel chart, a.k.a. the vowel trapezium.

In this video, an analog joystick with X and Y CV outputs is used to control the filter module. Two channels of MIDI-CV converter may also be used. The module is designed to accept CV sources with 5 volt range. Either -2.5 .. +2.5 volts or 0.. +5 volts can be used for optimum control. Wider CV ranges (up to +/- 10V) will not cause damage, but should be attenuated for best articulation.

Visualizations were made with a Tektronix TDS 350 digital oscilloscope in XY display mode, 1 volt per division.

The Grendel Formant Filter is made by Rare Waves (Austin TX)

- Eric Archer

16 Feb 06:50

http://www.lememe.com/archives/30147

by daniel

16 Feb 06:50

All Criterion movies free this weekend

by Sarah Pavis

In a deal last year, Criterion movies went from one paid online service to another (Netflix to Hulu Plus).

However from now through Monday February 18th, all Criterion movies are free on Hulu for anyone in the US. No sign-up or log-in required.

Some recommendations: Yojimbo, Schizopolis, Hoop Dreams, and Zazie dans le métro.

Update: The free weekend has ended and most Criterion movies are back behind the Hulu Plus paywall but there are still a handful of Criterion movies available to watch for free on regular-Hulu including Hoop Dreams as well as Zatoichi, Quadrophenia, and The Long Voyage Home

Tags: Criterion Collection   Hulu   movies
16 Feb 06:50

Photo

by ohmyscience


16 Feb 06:49

Evening has come while I was glancing at the dawn

by but does it float
Etchings by Konstantin Kalynovych Title: Novalis via Book Graphics Will 50 Watts
16 Feb 06:29

Photo







15 Feb 18:09

http://www.lememe.com/archives/29934

by daniel

13 Feb 21:27

Photo



11 Feb 03:04

Random image from fukung.net: 8e3b34f53ba91a2875203fbf02defd22.jpg

11 Feb 02:49

...taking midnight out of our pockets, we shall light a fire

by but does it float
Collages by Bryan Olson Title: Henri Pichette via Delicious Dimension Will 50 Watts
11 Feb 02:47

trippy

by ohmyscience


trippy

11 Feb 02:45

130207



130207

10 Feb 17:42

scinerds: Cosmos: A Space-Time Odyssey Cosmos: A Space-Time...

by ohmyscience






scinerds:

Cosmos: A Space-Time Odyssey

Cosmos: A Space-Time Odyssey is an upcoming American documentary television series. It is a follow-up to Cosmos: A Personal Voyage, which was presented by Carl Sagan. The new series’ presenter will be Neil deGrasse Tyson.

The executive producers are Seth MacFarlane and Ann Druyan, Sagan’s widow. It was originally announced that it would premiere in the 2012–13 United States network television schedule, but a Twitter update from Neil deGrasse Tyson in June 2012 indicates a Spring 2014 release. Episodes will premiere on Fox and also air on National Geographic Channel on the same night.

Development

The original 13-part Cosmos: A Personal Voyage first aired in 1980 on the Public Broadcasting System, and was hosted by Carl Sagan. The show was considered highly significant since its broadcast; Dave Itzkoff of the New York Times described it as “a watershed moment for science-themed television programming”. The show has been watched by at least 400 million people across 60 different countries.

Following Sagan’s death in 1996, his widow Ann Druyan, the co-creator of the original Cosmos series along with Steven Soter, a producer from the series, and astronomer Neil deGrasse Tyson, sought to create a new version of the series, aimed to appeal to as wide an audience as possible and not just to those interested in the sciences. They had struggled for years with reluctant television networks that failed to see the broad appeal of the show.

Seth MacFarlane had met Druyan through Tyson at an event that connected Hollywood directors with scientists in 2009, and learned of their interest to recreate Cosmos. MacFarlane was influenced by Cosmos as a child, believing that Cosmos served to “[bridge] the gap between the academic community and the general public”. MacFarlane had considered that the reduction of effort for space travel in recent decades to be part of “our culture of lethargy”. MacFarlane, who at the time has several animated shows on the Fox Network, was able to bring Druyan to meet the heads of Fox programming, Peter Rice and Kevin Reilly, and helped to get the greenlighting of the show.

MacFarlane admits that he is “the least essential person in this equation” and the effort is a departure from work he’s done before, but considers this to be “very comfortable territory for [himself] personally”. He and Druyan have become close friends, and Druyan stated that she believed that Sagan and MacFarlane would have been “kindred spirits” with their respective “protean talents”. In June 2012, MacFarlane provided funding to allow about 800 boxes of Sagan’s personal notes and correspondences to be donated to the Library of Congress.

04 Feb 23:36

Photo



04 Feb 07:52

Buke and Gase / General Dome [2013]

by who

[ Brassland Records / HWY-029 ]

Houdini Crush
Hiccup
In the Company of Fish
General Dome
Hard Times
Sturtle
Twisting the Lasso of Truth
You Do Yours First
Split Like a Lip, No Blood on the Beard
Cyclopean
Contortion in Training
My Best Andre Shot
Metazoa

RG UL
04 Feb 07:47

http://www.lememe.com/archives/29899

by daniel

04 Feb 07:46

santablainey: Look what someone did to our mystery section....

by ohmyscience


santablainey:

Look what someone did to our mystery section. LOOK AT IT.

01 Feb 07:14

Richard Feynman and the Space Shuttle Challenger investigation

by Jason Kottke
Thepalmcivet

this entire doc is A+

The Space Shuttle Challenger disintegrated shortly after liftoff 27 years ago today. Physicist Richard Feynman had a hand in determining the reason for the disaster.

I'm an explorer, ok? I get curious about everything and I want to investigate all kinds of stuff.

Here's Feynman's appendix to The Presidential Commission on the Space Shuttle Challenger Accident in which he dissents with the majority opinion of the commission. His conclusion:

If a reasonable launch schedule is to be maintained, engineering often cannot be done fast enough to keep up with the expectations of originally conservative certification criteria designed to guarantee a very safe vehicle. In these situations, subtly, and often with apparently logical arguments, the criteria are altered so that flights may still be certified in time. They therefore fly in a relatively unsafe condition, with a chance of failure of the order of a percent (it is difficult to be more accurate).

Official management, on the other hand, claims to believe the probability of failure is a thousand times less. One reason for this may be an attempt to assure the government of NASA perfection and success in order to ensure the supply of funds. The other may be that they sincerely believed it to be true, demonstrating an almost incredible lack of communication between themselves and their working engineers.

In any event this has had very unfortunate consequences, the most serious of which is to encourage ordinary citizens to fly in such a dangerous machine, as if it had attained the safety of an ordinary airliner. The astronauts, like test pilots, should know their risks, and we honor them for their courage. Who can doubt that McAuliffe was equally a person of great courage, who was closer to an awareness of the true risk than NASA management would have us believe?

Let us make recommendations to ensure that NASA officials deal in a world of reality in understanding technological weaknesses and imperfections well enough to be actively trying to eliminate them. They must live in reality in comparing the costs and utility of the Shuttle to other methods of entering space. And they must be realistic in making contracts, in estimating costs, and the difficulty of the projects. Only realistic flight schedules should be proposed, schedules that have a reasonable chance of being met. If in this way the government would not support them, then so be it. NASA owes it to the citizens from whom it asks support to be frank, honest, and informative, so that these citizens can make the wisest decisions for the use of their limited resources.

For a successful technology, reality must take precedence over public relations, for nature cannot be fooled.

Clear thought, clear writing. Feynman was perhaps the most efficient mechanism ever conceived for consuming complexity and pumping out simplicity. (via @ptak)

Tags: NASA   Richard Feynman   science   space   Space Shuttle