Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jakcharlton's full-sized avatar

Jak Charlton jakcharlton

View GitHub Profile
@jakcharlton
jakcharlton / paginate.rb
Created October 16, 2010 21:28
will_devise and mongoid ... how to sort
@posts.paginate(:page => params[:page],
:per_page => 20,
:sort => [['added', :asc]])
match 'post/by_tag/:tag',
:to => 'posts#by_tag',
:as => 'posts_by_tag',
:tag => /[A-Za-z0-9\-_\.]*/
if last_vote_date.nil? || last_vote_date.utc < 1.day.ago
self.last_vote_date = Time.now
self.votes_per_day = 1
else
self.votes_per_day += 1
end
if self.votes_per_day <= 10
self.reputation += 1
end
@jakcharlton
jakcharlton / tests.rb
Created October 26, 2010 03:21
Can't quite get this looking cleaner by using "subject" and "specify"
require 'spec_helper'
describe User, ".add_reputation via voting" do
before(:each) do
@user = User.new
@user.reputation.should == 1
end
it "adds one rep" do
@user.add_reputation(:voting)
1) DestinationsController GET index assigns all destinations as @destinations
Failure/Error: get :index
bad argument(expected URI object or URI string)
# ./spec/requests/destinations_controller.spec:14:in `block (3 levels) in <top (required)>'
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Dimebrain.TweetSharp.Extensions;
using Dimebrain.TweetSharp.Fluent;
using Dimebrain.TweetSharp.Model;
using NHibernate;
using NHibernate.Criterion;
@jakcharlton
jakcharlton / frag.js
Created May 23, 2011 03:26
How to turn to CoffeeScript
$(document).ready(function() {
$('.edit_area').editable('/fragments/1/save', {
loadurl : '/fragments/1/load_markup',
type : 'textarea',
cancel : 'Cancel',
submit : 'OK',
onblur : 'submit',
indicator : '<img src="/assets/rails.png">',
tooltip : 'Click to edit...'
});
@jakcharlton
jakcharlton / q.cs
Created May 25, 2011 06:48
EF mapping
public class Order
{
public int OrderId {get; private set;}
public List<Orderlines> Orderlines {get; private set;}
}
public class Orderline
{
public string Item {get; private set;}
public int Quantity {get;private set;}
@jakcharlton
jakcharlton / blerg.coffee
Created May 25, 2011 09:14
How do I return 'data' as the result of save_it ?
# How do I return 'data' as the result of save_it ?
save_it = (edited_value, s) ->
$.post(url_to_save_to, {value: edited_value}, (data) -> data)
@jakcharlton
jakcharlton / timeit.cs
Created June 7, 2011 04:17
A quick and simple timer class to wrap
using (new TimeIt()) { command.Execute(); }
public class TimeIt : IDisposable
{
private readonly TextWriter output;
private readonly Stopwatch watch;
public TimeIt() : this(Console.Out) {}
public TimeIt(TextWriter output)