01 Mar

How I Made $6K With My eBook

For those that don’t know, I’ve written an ebook a couple months ago and decided to sell it online, as an experiment. It did pretty well. My expectations were very low and it was the first time I tried selling something online, so it ended up being a big success for me.

How did it do?

Gotta say, I’m very surprised with the results. I launched it on September 9th. So far I’ve sold 168 copies for a total of $6558.36. I’m still selling a few copies each month, mostly from the nice traffic I get for free from Google.

You want to sell your own thing too?

A lot of people asked me how I did it. So here it is:

  1. Created a quick landing page to test the market with a form to subscribe to a newsletter
  2. Launched a 2 day ad campaign on AdWords to drive traffic to my landing page (spent $100)
  3. Checked stats to see if there was interest (3 signups for the newsletter, 56 visits, 5% CR)
  4. Wrote the book in textile, converted it to HTML, then PDF
  5. Asked for reviewers on Twitter
  6. Reviewed, polished, reviewed, polished
  7. Reviewed and polished some more
  8. Redesigned the whole thing in Adobe InDesign (there must be a better way, I hope! This was painful)
  9. Improved the landing page according to stuff I read regarding sales letters and landing pages
  10. Got an account on e-junkie, using a coupon code, got 120 days for free
  11. Plugged e-junkie to my Paypal account
  12. Announced it on Twitter

A few tips if you plan on selling something similar:

  • Don’t sell just an ebook, package it with something else
  • Test your market first
  • Focus on a niche

If you have any questions, I’d be glad to answer them in the comments.

Help Me Promote My Book And Get 50% on Each Sale

As an experiment, I’ve moved from E-junkie to ClickBank to try some affiliate marketing. Simply put, affiliate marketing is: you send people to my site, they buy, you get a percentage of that sale (50% in my case). Pretty simple and works well for some products I’ve read, so hey, why not try it.

If you’d like to help me promote Create Your Own Programming Language, see the special affiliates page I’ve created will all the info you need to get started.

23 Feb

How to Apply to a Job

Here’s the cover letter I sent for applying to my previous job.

#!/usr/bin/env ruby
I = []; fit = [:your, :offer, ' http://www.standoutjobs.com/jobs.php?id=1409']
just = checkout = %w(macournoyer cv)
its = you = me = 1_000_000_000 #$
class Array
  def can i, help = :you; true end 
  def me love = ruby
    $my = self; love='creating world'.class.new 'stuff'
  end
  def see _for = :yourself
    `open http://#{$my.join '.com/'}/`
  end
  alias :am :to_a 
  alias :in? :include?
end

I.fill(0).each { |criterion| } && I.am.uniq! and :passionate

its.upto(you) do |i| fit.in? :StandoutJobs
   just.send :me, :an => 'email' 
end; %w(e ll).see if I.can :help => you

=begin
[... snip ...]

Marc-André Cournoyer
http://macournoyer.com

Run this ruby script to get my résumé
=end

I see lots of people complaining job offers all look the same. But how about your CV / cover letter?

17 Feb

Hey Yo Marc, Make Me A Server

As some of you might know, we started doing consultancy at my company, Sauté, to finance our startup, Talker. Things are going great at Talker, but the route to profitability is a long one. Since we’re bootstrapping this, we have to find other sources of revenues.

Finding nice gigs with a decent rate in Montreal is hard. So that’s why I’m trying something a little different: focusing on a niche I know a lot about, with a specific offer: custom made servers.

I Build Servers, Just For You

You know Thin right? Well, I often get requests for adding very specific stuff to it, or customize it for a specific need. I’ve always refused to do so, because Thin is an HTTP server, nothing else. As the name implies, it should stay thin. But what I’m launching now, is a service to build custom servers that will fit your specific needs.

If you need a:

  • web server with custom extensions or optimizations
  • chat server
  • proxy with specific routing rules
  • efficient API server
  • server that can scale horizontally
  • or simply help building your backend architecture

… then, my Hey yo Marc, make me a server service was made for you.

Help Me Spread The Word

I need your help on this. Please tweet it, tell your mom, or whatever. I will appreciate it greatly. Thanks!

14 Feb

What Snowboarding Taught Me About Life and The Secret Of Pushing Yourself

About 10 years ago I was addicted to snowboarding. I was convinced I’d became a professional snowboarder. I read every magazine and watched every video I could find. Meticulously inspecting each images as if it was going to teach me the secrets of spinning 720 degrees in mid-air. I was very serious about it.

I could do a couple nice tricks, although very simple, 360, 180s, grabs and all. But one day I decided I was gonna try a frontside rodeo 540 (front flip + 540), which was a big thing at the time. I watched several videos in slow motion to learn the initial motion required to spin it.

After a big snowfall I went to the mountain and decided to try it. There I was, waiting to drop-in to a pretty big jump, about to throw myself head-under-feet. To this day, I still remember the feeling I had before riding up the jump. I swear I nearly peed my pants, I was so scared. By I kept repeating to myself that I could do it. So I did. I dropped in, full speed. Threw my head forward while looking to my left, to initiate the spinning and flipping motion, grabbed my board with my right hand, waiting to spot my landing. Next thing I knew, I stomped it and rode away, flawlessly. I still remember this day, and I will for the rest of my life as the best snowboarding day I ever had.

From that time on, I wasn’t scared anymore and stomping that trick became second nature for me. I remember talking to people in the park telling me they’d never try that kind of trick because they were not good enough. But I knew it was not about being good, it was all about having the guts to push your limits. Once you’ve pushed that limit, it is gone.

29 Sep

Leaving Standout Jobs & Starting My Own Thing

It’s been a while …

Yes, I’ve been at Standout Jobs for about two years now and things aren’t going great in the HR space. Although I think the product we built is great and the team is amazing, things are slowing down and we’re not needed anymore. I’ll be leaving on the October 6th.

Throughout the years I’ve created several open source projects and some websites, searching for an idea to start my own thing. I’ve had the desired to build a startup for more then three years but never thought I was ready.

Today I am.

Announcing Talker

I’ve been disappointed by Campfire and other group chat applications for quite a while. All those applications are stuck in the past and haven’t evolved, taking advantage of new technologies and computer power we have today. Group chat was such an important tool at Standout Jobs that I’m convinced any improvement on that side will sky rocket the productivity of any team using it.

So I’ve teamed up with Gary Haran to build something great.

If you find our idea interesting, please signup for the beta and wish us luck!

04 Jun

Pusher & Async With Thin

Pusher (aka Rack::Comet)

I’ve been playing around with Orbited, APE and the like, but they all have lots of code and kind of reinvent the wheels in some ways (reimplementing an HTTP server, daemon, etc). So just for fun, I’ve hacked a simple AJAX push server (aka Comet) on top of Thin using the new Async Response feature.

To be honest, after revisiting Orbited a couple times, it’s pretty cool! It’s easily extensible, based on Twisted. Use this if you want something serious.

Async Response in Thin

So, all this to talk to you about Thin Async Response feature. Coded by James Tucker a while ago and merged in Thin in version 1.2 (released around March 16th).

Async response is the way to do scalable concurrency. The downside is that you have to design your code accordingly, based on events. And you remember not to use any blocking calls, right?

class AsyncApp
  AsyncResponse = [-1, {}, []].freeze
    
  def call(env)
    body = DeferrableBody.new
    
    # Get the headers out there asap, let the client know we're alive...
    EM.next_tick { env['async.callback'].call [200, {'Content-Type' => 'text/plain'}, body] }
    
    # Semi-emulate a long db request, instead of a timer, in reality we'd be 
    # waiting for the response data. Whilst this happens, other connections 
    # can be serviced.
    # This could be any callback based thing though, a deferrable waiting on 
    # IO data, a db request, an http request, an smtp send, whatever.
    EM.add_timer(1) do
      body.call ["Woah, async!\n"]
      
      EM.next_tick do
        # This could actually happen any time, you could spawn off to new 
        # threads, pause as a good looking lady walks by, whatever.
        # Just shows off how we can defer chunks of data in the body, you can
        # even call this many times.
        body.call ["Cheers then!"]
        body.succeed
      end
    end
    
    AsyncResponse # Tells Thin to not close the connection and continue it's work on other request
  end
end

A DeferrableBody is a response body that can be rendered iteratively.

class DeferrableBody
  include EventMachine::Deferrable

  def call(body)
    body.each do |chunk|
      @body_callback.call(chunk)
    end
  end

  def each(&blk)
    @body_callback = blk
  end
end

Works With Rails Too!

You can use it inside Rails too, with throw :async to simulate returning AsyncResponse in the previous example.

But Tastes Better in Sinatra

James also built this nice wrapper for Sinatra, called async-sinatra:

require 'sinatra/async'

class AsyncTest < Sinatra::Base
  register Sinatra::Async

  aget '/' do
    body "hello async"
  end

  aget '/delay/:n' do |n|
    EM.add_timer(n.to_i) { body { "delayed for #{n} seconds" } }
  end
end

Scale To The Moon

Using that in combination with other EventMachine based libraries, you’re sure to scale to the moon running your website on a Pentium II.

  • em-mysql – Don’t block while querying your DB
  • em-http-request – Don’t block while querying other websites

Big thanks to James for implementing this feature!

20 Mar

tinyrb: Tinier & Bigger

More Ruby

When I first announced tinyrb there was no Float, no Module, no Proc or Bloc, no Array, Hash, IO, Range, Metaclass. Frankly it was not really Ruby. But now, most of those are in, except Float and IO, and Proc is halfway there (see proc branch). Lets just say that it’s running a lot more code.

New Grammar

The first big problem I hit was the parser, initially written in Ragel and Lemon it was not flexible enough. I since rewrote it using peg/leg. I’m having some trouble with {...} because of the ambiguity between Hash and blocks. But other then that, it works like magic. The downside of using a PEG parser is poor error reporting and less secure as it is prone to infinite recursion. The later might become a problem, but maybe it’s just a bug in peg/leg.

Upvals, Cheap Proc

One of the problems with most Ruby implementation is that using a Proc might end up costing more memory that you think. The reason is that a part of the stack frame (or another structure where local variables are stored) must be saved to allow you to access local variables from the outer scope later inside your Proc.

def add(x)
  proc { |y| x + y }
end
add2 = add(3)
add2.call(4) # => 7

You see, the context of add must be saved because we access the local variable x that is defined outside of the Proc. If you create lots of Procs, that might become a problem and it’s not very “tiny”.

Once again, the solution can be found inside Lua. And it is named upval! An upval (or upvalue) is a local variable from an outer scope, like x from inside the Proc in the previous example. I’ll spare you the implementation details but it has 2 advantages.

First, accessing an upval only requires dereferencing a pointer. As compared to other VMs that save the full stack frame. They need to browse the frames array to find where the local variable is defined each time. (Let me know if I’m wrong, but I’ve checked Rubinius (push_local_depth instruction) and YARV (getdynamic instruction) source).

Second, when the enclosing scope of a Proc goes out of scope, for example when we leave the add method in the previous example, we just copy the value of the local inside the upval. value will point to closed in the TrUpval struct. No need to copy and save a bunch of frames, just update a pointer.

typedef struct {
  OBJ *value; /* points to a local or closed */
  OBJ closed; /* value when closed */
} TrUpval;

Please note this is not fully implemented yet, I’m working on the “closing” of upvalues at the moment.

Compact bytecode

Another thing I ported from Lua is the way it stores local variables on the stack. For the VM, it means local variables are no different then any other values you pass around (return values, arguments, etc). The advantage of this approach is that it makes the bytecode a lot smaller when using local variables. This is only possible in register based VM like Lua, tinyrb and Parrot.

For tinyrb’s VM, local variables are just named registers. So the code a = b = 1 is compiled to the following.

; block definition: 0xc2f00 (level 0)
; 1 registers ; 0 nested blocks
; 0 args 
.local  b        ; 0
.local  a        ; 1
.value  1        ; 0
[000] loadk        0   0   0 ; b = 1
[001] move         1   0   0 ; a = b
[002] return       0   0   0
; block end

In YARV, it requires twice more instructions.

0002 putobject        1
0004 dup              
0005 setlocal         b
0007 dup              
0008 setlocal         a
0010 leave

Well, that doesn’t mean tinyrb is faster, but it needs to run half the code as the other Ruby VMs to do the same thing with local variables. Also, the code takes half the space in memory too of course. So we’re on the right track.

FFI

Wayne Meissner, the creator of the FFI gem and FFI stuff inside JRuby, has been working on FFI integration. This is probably the most exciting things you can use tinyrb for at the moment. Wayne also started implementing some more corelibs in Ruby using FFI. I hope to use this to implement more of tinyrb in Ruby.

Garbage Collector

I’ve been using the Boehm GC as a way to move development faster. I think it’s more important to get some core features in first. And I wasn’t sure which type of GC would fit tinyrb best. But being “tiny” code wise and memory wise, refcount seems the best match. While refcount is often viewed as a poor solution, it’s the most efficient one in terms of memory consumption as far as I know. As soon as an object is no longer used, it is freed from memory. Oppositely, VMs using mark and sweep algorithms must allocate a large quantity of memory up front and generally can’t give it back to the OS.

Hopefully for me, some people mentioned on the IRC channel they’ll be working on a GC for tinyrb as part of their master thesis. I hope this works!

That Was A Lot of Text

At first, I wasn’t sure about the focus of the project. It was just a learning experience. But now I think there’s a need for a small and efficient Ruby VM that use very little memory. Expect to see more development in those directions.

27 Feb

tinyrb Interview

Pat Eyler, of On Ruby, interviewed me about tinyrb.

tinyrb update

tinyrb is running more and more Ruby code each day. Someone is even hacking on FFI integration!

But I’m stuck with some parsing issues at the moment and the grammar is getting uselessly more complex. I need to figure out if I should rewrite the grammar using Lemon again or find another solution. I’m thinking about doing what tinypy did and write the parser in Ruby. Any suggestion?

12 Feb

tinyrb

Yes, yes, finally a Ruby VM that fits in your backpocket, it’s there, it’s here. I mean, yay!

It all started 2 weeks ago. I was stocked by Potion and had been studying Lua and other VMs for a little while. So I dove in and hacked a little Ruby VM with bytecode and all.

It’s Tiny Because There’s Not A Lot in There

The primary goal is to keep it small. This way, lots of people can understand it and change it quickly. My objective is to keep the VM (the C part) under 64K. Right now, it’s 43K and 1541 LOC. Not sure it’s possible, but I’ll take this as a challenge.

But, some very basic things are missing: no Float, no Module, no Proc or Bloc, no Array, Hash, IO, basically, almost nothing. But most of the keywords and core objects are there: Class, Object, Fixnum, Symbol, String, def, class, if, unless, while, until, etc.

The lexer is written in Ragel and the parser in Lemon. I wish to support the commonly used stuff in Ruby but give up on the dark corners or things that are too complex. Right now the grammar is just 100 LOC, that’s nice. The rule is:

>Everything in tinyrb should run in the big Ruby.
>(except bugs and things that don’t comply to the principle of least surprise.)
>But not everything in the big Ruby should run in tinyrb.

It’s Kinda Fast, For Now At Least

I implemented a couple optimizations already, Monomorphic method cache is there, means method lookup is cached at the call site. Also, as a test, I inline 3 methods, Fixnum#+, Fixnum#-, Fixnum#<, which makes a pretty big difference. The interpreter loop uses direct threaded dispatch when available and falls back to while-switch for portability.

Of course, I ran a couple micro-benchmarks. Now you know what they say about benchmarks? So take those with a grain of salt. But I think it just shows that a “fast” interpreter doesn’t need to be huge, at least…

UPDATE well of course I did something wrong here, I forgot to run jruby w/ the -server option. So please consider this benchmark completely false and useless.

Classic fibonaci

MRI:      9.659s
tinyrb:   7.865s
JRuby:    6.755s
Rubinius: 6.006s
YARV:     2.393s

bm_vm2_method.rb

MRI:      17.136s
tinyrb:   12.155s
JRuby:    11.135s
Rubinius: 12.580s
YARV:     7.165s

memory usage for bm_vm2_method.rb

 PID COMMAND      %CPU   TIME   #TH #PRTS #MREGS RPRVT  RSHRD  RSIZE  VSIZE
3041 tinyrb      99.5%  0:03.54   1    13     25  412K   184K   940K    18M 
3045 java        99.8%  0:04.15  10   228    190   28M+  216K-   28M   705M 
3058 ruby19      99.8%  0:03.84   2    30     40  960K   184K  2452K    20M 

tinyrb is far from the fastest but it’s still very close to JRuby and Rubinius faster then MRI here and hey! it’s just 2 weeks old ok?

Hacking tinyrb 101

To compile it:

git clone git://github.com/macournoyer/tinyrb.git
cd tinyrb
make
make test # optional

This should produce a nice tinyrb file.

You can use tinyrb like you usually do with ruby, see the -h option for usage..

./tinyrb -e "puts 1"
./tinyrb test/loop.rb

You can see the generated bytecode using the -d option and you’ll get something like that:

; block definition: 0x6cf78 (level 0)
; 2 registers ; 1 nested blocks
; 0 args
.value  fib      ; 0
.value  34       ; 1
[000] def          0   0   0 ; fib => 0x6cf20
[001] self         0   0   0
[002] loadk        2   0   1 ; R[2] = 34
[003] boing        0   0   0
[004] lookup       0   0   0 ; R[1] = R[0].method(:fib)
[005] call         0   1   0 ; R[0] = R[0].R[1](1)
[006] return       0   0   0
; block end

I’ll talk more about the bytecode later.

Lets Talk About It At The Next Montreal.rb

If you wanna talk about tinyrb, come see my next talk about Ruby VMs at the next Montreal.rb.

Or join me on github, or #tinyrb on freenode.

23 Jan

Presenting at montreal.rb

About a year ago, I discovered a passion for VM and language design and red lots of code, research papers and coded my own Ruby VM and language.

So I’m very exited to speak about Ruby VMs at the next montreal.rb. I’ll try to make things as simple as possible but still get low level. I hope you’ll enjoy!

Make sure you RSVP if you’re in Montreal on Feburary 17^th^.