Skip to content

Instantly share code, notes, and snippets.

View mrnugget's full-sized avatar

Thorsten Ball mrnugget

View GitHub Profile
$(function() {
// Writes to 'target' how many chars are left to type in 'input'
function text_counter(input, target) {
var max = input.attr("maxlength");
input.focus(function() {
target.removeClass('invisible');
var left = max - this.value.length;
target.text("You have " + left + " characters remaining");
});
input.blur(function() {
@mrnugget
mrnugget / INSTRUCTIONS.md
Created March 25, 2012 13:21
Make MacVim use the correct $PATH with rbenv
\documentclass[a4paper,12pt]{article}
\usepackage{libertine}
\renewcommand*\oldstylenums[1]{{\fontfamily{fxlj}\selectfont #1}}
%\renewcommand{\baselinestretch}{1.4}
\usepackage{setspace}
\usepackage{type1cm}
\setstretch{1,50}
\usepackage{geometry}
\usepackage[ngerman]{babel}
# While looking at a page, I create a comment in the background:
irb(main):005:0> Time.now
=> 2012-04-07 16:27:49 +0200
irb(main):006:0> new_comment = Comment.create!(user: User.first, song: Song.last, text: "Hello3")
User Load (0.3ms) SELECT "users".* FROM "users" LIMIT 1
Song Load (0.2ms) SELECT "songs".* FROM "songs" ORDER BY "songs"."id" DESC LIMIT 1
(0.1ms) begin transaction
SQL (0.5ms) INSERT INTO "comments" ("created_at", "song_id", "text", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?) [["created_at", Sat, 07 Apr 2012 14:27:51 UTC +00:00], ["song_id", 95], ["text", "Hello3"], ["updated_at", Sat, 07 Apr 2012 14:27:51 UTC +00:00], ["user_id", 1]]
(2.7ms) commit transaction
irb(main):001:0> Time.now
=> 2012-04-07 16:44:04 +0200
irb(main):002:0> Comment.create!(user: User.last, song: Song.last, text: "Comment")
User Load (0.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
Song Load (0.2ms) SELECT "songs".* FROM "songs" ORDER BY "songs"."id" DESC LIMIT 1
(0.1ms) begin transaction
SQL (5.5ms) INSERT INTO "comments" ("created_at", "song_id", "text", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?) [["created_at", Sat, 07 Apr 2012 16:44:23 CEST +02:00], ["song_id", 95], ["text", "Comment"], ["updated_at", Sat, 07 Apr 2012 16:44:23 CEST +02:00], ["user_id", 1]]
(2.8ms) commit transaction
=> #<Comment id: 36, user_id: 1, text: "Comment", created_at: "2012-04-07 14:44:23", updated_at: "2012-04-07 14:44:23", song_id: 95>
# IRB
'0'.respond_to?(:to_datetime) # => false
# rails console
'0'.respond_to?(:to_datetime) # => true
describe "includes Publishable" do
before(:each) do
@now = DateTime.now
DateTime.stub!(:now).and_return(@now)
end
it "accepts '1' or 1 as valid arguments and sets published_at to a DateTime object" do
NewsItem.new(published_at: '1').published_at.should_not be_nil
NewsItem.new(published_at: 1).published_at.should == @now
@mrnugget
mrnugget / markdowntest.md
Created April 14, 2012 12:51
MarkDown Testting

H2

  • Item 1
  • Item 2
  • Item3

Blockquotes

The next few lines should be a blockquote

# Before:
class Admin::BaseController < ApplicationController
before_filter :authenticate_admin!
layout 'admin'
protected
def build_locales_for(object)
available_languages.keys.sort.each do |locale|