Caffeinated http://blog.caseybrant.com Casey Brant's blog posterous.com Tue, 20 Mar 2012 12:59:00 -0700 Sample Cakefile http://blog.caseybrant.com/sample-cakefile http://blog.caseybrant.com/sample-cakefile

Cake is the build tool for CoffeeScript. It's nifty, but the documentation is a little sparse. Here's an example Cakefile that does everything you need for a basic Coffee project:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{exec} = require 'child_process'


task 'test', 'Runs all Jasmine specs in spec/ folder', ->
  test()

task 'compile', 'Compiles coffee in src/ to js in bin/', ->
  compile()

task 'stitch', 'Stitches all app .js files', ->
  stitch()

task 'compress', 'Runs UglifyJS on stitched file in order to compress it', ->
  compress()

task 'build', 'Does the full build magic', ->
  test -> compile -> stitch -> compress()

task 'develop', 'Only compile and stitch, don\'t test or compress', ->
  compile -> stitch()


test = (callback) ->
  console.log "Running Jasmine specs"
  exec 'jasmine-node --coffee spec/', (err, stdout, stderr) =>
    console.log stdout + stderr

    # hack to work around jasmine-node's bad return vals:
    throw "Tests fail. Build fails. You fail." if ~stdout.indexOf "Expected"

    callback?()


compile = (callback) ->
  exec 'coffee -o bin/ -c src/', (err, stdout, stderr) ->
    throw err if err
    console.log "Compiled coffee files"
    callback?()


stitch = (callback) ->
  stitch = require 'stitch'
  fs = require 'fs'

  myPackage = stitch.createPackage paths: [__dirname + '/bin', __dirname + '/vendor']
  myPackage.compile (err, source) ->
    fs.writeFile 'app.js', source, (err) ->
      throw err if err
      console.log "Stitched js files"
      callback?()


compress = (callback) ->
  exec 'uglifyjs --overwrite app.js', (err, stdout, stderr) ->
    throw err if err
    console.log "Compressed app.js"
    callback?()

 

Project Structure

In this example, I'm using a project structure something like this:

Coffee_structure

That's all inside a "static" directory in a Django project, but it shouldn't matter what kind of server you're using. Coffee files are in src/, Jasmine specs are in spec/, and compiled JavaScript goes into bin/.

 

Dependencies

To run everything, you'll need Node (which you should have already if you're using CoffeeScript) and a few other things installed via npm:

  • stitch
  • uglifyjs
  • jasmine-node

You can run npm install -g <NAME> to intall each of these system-wide.

 

Cake Tasks

Cakefiles are composed of tasks, which are defined at the top of the Cakefile like this: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
task 'test', 'Runs all Jasmine specs in spec/ folder', ->
  test()

task 'compile', 'Compiles coffee in src/ to js in bin/', ->
  compile()

task 'stitch', 'Stitches all app .js files', ->
  stitch()

task 'compress', 'Runs UglifyJS on stitched file in order to compress it', ->
  compress()

task 'build', 'Does the full build magic', ->
  test -> compile -> stitch -> compress()

task 'develop', 'Only compile and stitch, don\'t test or compress', ->
  compile -> stitch()

Each of these tasks calls a function that performs the correct action. For example, the "compile" task calls this function:

1
2
3
4
5
compile = (callback) ->
  exec 'coffee -o bin/ -c src/', (err, stdout, stderr) ->
    throw err if err
    console.log "Compiled coffee files"
    callback?()

The reason I break the tasks out into functions like this is to make it easy to chain them together. Because Node runs processes asynchronously, I use callbacks in the functions instead of simply calling a sequence of tasks. If I just used "invoke", the full build would happen even if a Jasmine spec fails. Also, I just really like the way the full build task looks:

1
2
task 'build', 'Does the full build magic', ->
  test -> compile -> stitch -> compress()

 

Developing with Cake

Running cake with no arguments yields a list of tasks defined in the Cakefile.

Cake_tasks

Each step of the build has its own task, but I really only use three of them on a regular basis:

  • While coding, cake test lets me easily run Jasmine specs without waiting for compilation of CoffeeScript.
  • While testing small UI tweaks, cake develop lets me package things quickly for running in the browser without waiting for Uglify or Jasmine. 
  • When I'm ready to deploy, cake build runs all the steps.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Sat, 11 Feb 2012 15:51:00 -0800 twitter.com UI fix http://blog.caseybrant.com/twittercom-ui-fix http://blog.caseybrant.com/twittercom-ui-fix

Twitter keeps making their UI worse. Fortunately, there is DotJS. Here’s one quick little improvement in the UI:

Step 1. Install DotJS

Step 2. Copy and paste this code into a file called “twitter.com.js” in your DotJS folder:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var username = "BaseCase"; // replace with your username

$('div.stream-item').first().css('background','#dedede');
$('div.stream-item:contains(username)').css('background','#eef');

$('div.new-tweets-bar').live('click', function(e) {
setTimeout(function() {
$('div.stream-item').css('background','#fff');
$('div.stream-item:contains(username)').css('background','#eef');
$('div.stream-items div.stream-item').first().css('background','#dedede');
}, 8000);
});

//kill the trending topics module (it doesn't load right away, so wait a bit first)
setTimeout(function() { $('div.trends').remove(); }, 10000);

Now you can easily see what your last read tweet is when you click the button to load recent ones.

UPDATE: seems like this only works some of the time, but it’s at least better than nothing.

UPDATE 2: Got it working more often. Also, highlight tweets by you or mentioning you.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Sun, 22 May 2011 13:41:40 -0700 Moving stuff from old blog http://blog.caseybrant.com/moving-stuff-from-old-blog http://blog.caseybrant.com/moving-stuff-from-old-blog

I've been meaning to move the worthwhile posts from my old blog over to this one for a while now, and I finally got started. It turns out that there was really only one worthwhile post over there. I'm pretty happy with this tutorial for screen, although I want to rework it a little bit to publish it here.

Here's the original post, hopefully soon to be revamped and over here.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Sun, 03 Apr 2011 09:30:52 -0700 Discovery http://blog.caseybrant.com/discovery http://blog.caseybrant.com/discovery For a geek, there's nothing quite like that moment when you find a practical application for something you learned just because it seemed cool.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Sat, 19 Mar 2011 19:59:00 -0700 Scene from the Lyric Opera http://blog.caseybrant.com/scene-from-the-lyric-opera http://blog.caseybrant.com/scene-from-the-lyric-opera

Old lady: Ugh, it's just such a shame.

Old man: I know what you mean. Going to the opera used to mean something.

Old lady: People would wear blacks and evening dresses. There was class. People had manners.

Old man: Yes, manners. Whatever happened to those?

Old lady: I'm not sure. Oh, it looks like the orchestra is finishing the overture.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Sat, 12 Feb 2011 05:29:00 -0800 Buy me this now http://blog.caseybrant.com/buy-me-this-now http://blog.caseybrant.com/buy-me-this-now

"The Gamerator" — combinator keg and arcade cabinet.

 

http://www.joystiq.com/2011/02/12/the-gamerator-an-arcade-cabinet-with-a-buil...

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Fri, 03 Sep 2010 08:51:00 -0700 The First Two Weeks Back at School After Like Three Years of Not Being Anywhere Near as Busy as You Are During School and Mostly Forgetting How to Deal With It (i.e., Being Busy): A Retrospective http://blog.caseybrant.com/the-first-two-weeks-back-at-school-after-like http://blog.caseybrant.com/the-first-two-weeks-back-at-school-after-like

Thank God for Labor Day weekend.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Wed, 28 Jul 2010 20:31:00 -0700 Minecraft http://blog.caseybrant.com/minecraft http://blog.caseybrant.com/minecraft

This evening I've been messing around with Minecraft. It's hard to describe succinctly, but it seems to be the ultimate sandbox-style game. Here are some videos of what some people have done with it:

You can get the game here. It's $13 and worth way more than that if you have even a little bit of imagination or curiosity. There are helpful information sites here and here.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Mon, 26 Jul 2010 07:22:00 -0700 StarCraft 2 comes out tomorrow http://blog.caseybrant.com/starcraft-2-comes-out-tomorrow http://blog.caseybrant.com/starcraft-2-comes-out-tomorrow

If you're (like me) too crappy to make it past the fourth Zerg mission of the original, read this synopsis instead to get all caught up.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Thu, 22 Jul 2010 19:02:00 -0700 Chipophone http://blog.caseybrant.com/chipophone http://blog.caseybrant.com/chipophone

Someone please get one of these for me.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Thu, 22 Jul 2010 06:16:00 -0700 Check it out http://blog.caseybrant.com/check-it-out-0 http://blog.caseybrant.com/check-it-out-0

"Well, if we haven't gotten past venerating people who don't know anything, we've certainly reduced, I'd argue, the degree to which we stigmatize people for knowing a lot."

from Why The Next Big Pop-Culture Wave After Cupcakes Might Be Libraries

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Tue, 20 Jul 2010 13:26:00 -0700 Flip Face-off http://blog.caseybrant.com/flip-face-off-0 http://blog.caseybrant.com/flip-face-off-0

Andy owns two Flips (I dunno why. because he's Andy.) so he let me borrow one, and we're doing this video-making competition sort of thing. It's not really that much of a competition, more like a call-and-response project. Anyway, it's over here and I think we're gonna have some cool stuff up there by the time we decide to call it quits.

http://flipfaceoff.posterous.com

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Sun, 18 Jul 2010 06:45:00 -0700 First movie experience http://blog.caseybrant.com/first-movie-experience http://blog.caseybrant.com/first-movie-experience

Yesterday I was on a movie set for the first time! My acting teacher is involved with Using and asked a bunch of her students to participate. It was an interesting experience. There was a lot of waiting around. It felt like there was always something important happening, but it only ever involved a few people at a time.

I checked in at around 1:00, got some preliminary instruction from the extras coordinator, and then sat down until they needed me. At about 3:30, they got to the scene with extras and herded us over to the set. Once there, it was more waiting mixed with short bursts of intense focus. We got instructions from the director, did a couple of rehearsal runs, and then did (I think) 11 takes.

In between takes, the crew made tons of minor adjustments to the lights, camera positioning, actor direction, etc. All told, it took about an hour to get this one shot that I think will account for maybe 7 seconds of movie time. Even taking into account that this company (while still professional, don't get me wrong) isn't quite Hollywood-efficient, I can see why the shooting for a 2-hour movie takes so long.

What I learned yesterday is that I don't really have any desire to do any more extra-ing. Being on set was cool, but the long periods of waiting around with nothing to do reminded me too much of my old office job. Although...hm, now that I think about it, that feeling may have come from the fact that the shoot was in an office building and I was playing an office worker. So maybe I shouldn't rule it out.

I also got pretty interested in the other jobs on a movie set. The stuff everybody else was doing (especially the camera people) looked really cool, and I'd like to learn more about the tech side of movie-making.

I'm signed up for one more day of shooting today. This time I'm bringing my Kindle!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Fri, 09 Jul 2010 16:16:00 -0700 Shelob lives in my kitchen http://blog.caseybrant.com/shelob-lives-in-my-kitchen http://blog.caseybrant.com/shelob-lives-in-my-kitchen

Spider
The nasty stuff below is the pile of corpses generated by the spider's unslakable thirst for death.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Wed, 07 Jul 2010 07:22:00 -0700 A Cappella Zelda Theme http://blog.caseybrant.com/a-capella-zelda-theme http://blog.caseybrant.com/a-capella-zelda-theme

The band I Fight Dragons is pretty awesome.

I transcribed the vocal parts for that song:

Zelda
The notes are right I think, but I could do more to make the sheet music prettier. Here's the GitHub repository with the LilyPond source.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Thu, 24 Jun 2010 07:20:00 -0700 The Question Mark http://blog.caseybrant.com/the-question-mark http://blog.caseybrant.com/the-question-mark

I just wanted to let you know, real quick here: question marks pretty much just go at the end of questions. Or, I mean, like if you're doing some kind of Spanish thing they can go at the beginning of questions too. But the point is that it's always a question. Not like a statement or something. I guess we could do some examples. Would that help? OK, examples!

Good: Are you excited for the weekend?

Not Right: OMG like I am so excited for this weekend!?!

In the second example, you're using syntax to create some kind of verbal inflection that doesn't make any sense. I mean, I'm sure you know what you meant it to sound like -- well, actually, no I'm not.

Anyway, thanks for tuning in. Next week: How to Use the Ellipsis Every Four or Five Words.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant
Wed, 02 Dec 2009 19:15:50 -0800 Posterous http://blog.caseybrant.com/posterous-14928 http://blog.caseybrant.com/posterous-14928 Hey, this is a lot nicer than my Blogger setup. I should do something with this.

-cjb

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/322969/bearded.jpg http://posterous.com/users/3sIQh5fJhuHn Casey Brant basecase Casey Brant