Skip to content

Instantly share code, notes, and snippets.

var canvas = document.getElementById("c");
var context = canvas.getContext("2d");
// Draw a circle
context.beginPath();
context.arc(75,75,50,0,Math.PI*2,true);
context.stroke();
@baxter
baxter / collect.rb
Created December 5, 2010 19:20
Code snippets related to building strings in Ruby
parameters.collect do |key, value|
"#{key}=#{value}"
end
# => ["ns0=1", "title=Special:Search", "redirs=1", "advanced=1", "fulltext=Advanced+search", "search=Ruby"]
def counter(start=0, increment=1)
lambda do
original = start
start += increment
original
end
end
result = counter(2, 3)
@baxter
baxter / safe_object.rb
Created April 26, 2011 12:20
Safe object
class SafeObject
def send(*args)
puts "Are you sure? (Y/N)"
if gets.chomp == 'Y'
super(*args)
else
puts "Very wise."
end
end
end
@baxter
baxter / gist:984701
Created May 21, 2011 17:22
each_with_object
# Why does the first one work but not the second one?
(1..10).each_with_object([]) {|i, a| a << i*2 }
=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
(1..10).each_with_object([]) {|i, a| a += [i*2] }
=> []
@baxter
baxter / gist:1029562
Created June 16, 2011 15:56
Goto considered offensive
goto your ass
@baxter
baxter / gist:1089493
Created July 18, 2011 13:21
Emoticons and their meanings

Emoticon explanations

Too many applications provide their own emoticons. This is not acceptable. When I type the following characters this is what I mean.

  • :) – This made me smile.
  • :D – This really made me smile. My mouth is open. Please don't throw things at it.
  • :E – E is one better than D, therefore I just smiled so hard that my face broke.
  • ;) – I said something cheeky and hilarious.
  • :P – I said something that probably wasn't serious.
@baxter
baxter / turtles.js
Created August 27, 2011 19:46
It's turtles all the way down.
> var turtle = {};
> turtle;
{}
> turtle.turtle = turtle;
{ turtle: [Circular] }
> turtle.turtle.turtle;
{ turtle: [Circular] }
> turtle.turtle.turtle.turtle;
{ turtle: [Circular] }
>
From Linus Torvalds <>
Date Thu, 8 Mar 2012 15:40:26 -0800
Subject Re: [PATCH] sysfs: Optionally count subdirectories to support buggy applications
On Thu, Mar 8, 2012 at 2:18 PM, Eric W. Biederman <ebiederm@xmission.com> wrote:
>
> Keeping compatibility is easy enough that it looks like it is worth
> doing, but maintaining 30+ years of backwards compatibility
Stop right there.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.