Skip to content

Instantly share code, notes, and snippets.

@codeincontext
codeincontext / gist:3482669
Created August 26, 2012 19:05
canvas demo
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<h1>canvas</h1>
<canvas width="400" height="400" id="canvasElement"></canvas>
@codeincontext
codeincontext / gist:3190716
Created July 27, 2012 22:12
how much have you spammed your friends today?
require 'rubygems'
require 'twitter'
require 'active_support/core_ext'
timeline = Twitter.user_timeline("skattyadz", count: 200, include_rts: true)
puts timeline.select{|t| t.created_at > 1.day.ago}.count
@codeincontext
codeincontext / deletweet.rb
Created July 23, 2012 20:47
Keep a log of every tweet deleted by people you follow
require 'daemons'
require 'tweetstream'
$output_file = '???/deleted_tweets.txt'
Daemons.run_proc(
'deletweet',
log_output: true,
dir_mode: :script
) do
@codeincontext
codeincontext / gist:3046692
Created July 4, 2012 10:45
How long does it take you to retweet things from Hacker News?
<!DOCTYPE html>
<html>
<head>
<title>How Old Was That?</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
var username = "";
$.xhrPool = [];
@codeincontext
codeincontext / gist:3033933
Created July 2, 2012 15:56
Konami code using the Gamepad API
<!DOCTYPE html>
<html>
<head>
<title>Gamepad Shit</title>
<script type="text/javascript"></script>
<style type="text/css"></style>
</head>
<body>
<h1>Gamepad Shit</h1>
require 'twitter'
Twitter.configure do |config|
config.consumer_key = 'xxx'
config.consumer_secret = 'xxx'
config.oauth_token = 'xxx'
config.oauth_token_secret = 'xxx'
end
threads = []
@codeincontext
codeincontext / gist:2772254
Created May 22, 2012 23:14
Toying with this pattern for complex JS objects (replicating 'class' and 'instance' methods/variables)
// Constants
Solar = {
START_HEALTH: 100,
RADIUS: 10,
COLOR: "FF0",
RECYCLE: 50,
RANGE: 50,
ENERGY_PRODUCED: 0.5,
STORAGE: 25,
COST: 200,
Handlebars.Utils.isEmpty = function(value) {
if (typeof value === "undefined") {
return true;
} else if (value === null) {
return true;
} else if (value === false) {
return true;
} else if (value === '') {
return true;
} else if (value === 'null') {

The researcher believes that well written code should be self-documenting. Ruby code can be so similar to pseudo-code that descriptive commenting would only paraphrase the contents of the line, and could in fact make code less clear.

Below are some code samples from the project to demonstrate the self-descriptive nature of code.

validates_presence_of :password, :on => :create

This line tells the current model that it should validate the presence of a password when it is created.

This is a snippet from sessions_controller.rb, first uncommented, and then with 'descriptive' comments:

require 'timeout'
files_to_watch = %w{FYP.txt template.tex FYP.bib}
guard :shell do
files_regex = Regexp.new(files_to_watch.join("|"))
watch(files_regex) { regenerate }
end
def regenerate