Skip to content

Instantly share code, notes, and snippets.

@davelnewton
davelnewton / Main.java
Created September 8, 2011 23:32
Basic Java stuff
package ClassFiles;
public class Main {
public static void main(String[] args) {
System.out.println("Wat");
}
}
@davelnewton
davelnewton / timers.html
Created September 9, 2011 02:53
Speedy
<html>
<head>
<script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js">
</script>
</head>
<body>
Speed: <span id="speed"></span>
</body>
@davelnewton
davelnewton / gist:1205973
Created September 9, 2011 11:17
beautifuller
return false if real_account.nil?
date = date_from_str('2011-01-01')
return true if payments.has_finished? && real_account.created_before? date
Trade.has_payments(real_account.login, date)
@davelnewton
davelnewton / phase1.rb
Created September 16, 2011 02:01
Repeats validator that adds model methods
module Newton
module Validator
class RepeatsValidator < ActiveModel::EachValidator
def initialize(options)
@attributes = options[:attributes]
super
@how_count = options[:how_count]
@upto = options[:upto]
end
@davelnewton
davelnewton / Main.java
Created October 5, 2011 03:46
Velocity array access
package main;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
@davelnewton
davelnewton / ControllerFragment.rb
Created October 25, 2011 21:08
Quick voting refactoring
def vote_yes
vote(:up_vote)
end
def vote_no
vote(:down_vote)
end
private
@davelnewton
davelnewton / content_of_single_url.rb
Created November 6, 2011 23:14
Nokogiri results
# Get a URL's content to play with
content = contents[contents.keys.first]
# => [#<Nokogiri::XML::Element:0x48a9a86 name="p" children=[#<Nokogiri::XML::Text:0x48a9810 "The autobiography of Yohwan Lim, ">, #<Nokogiri::XML::Element:0x48a96ee name="i" children=[#<Nokogiri::XML::Text:0x48a9536 "Crazy As Me">]>, #<Nokogiri::XML::Text:0x48a931a " was released in Korea by BookRoad Publishers in October 25, 2004. This is my translation of the book, except the following four sections which were translated by BinaryStar of Teamliquid.net, which I have made minor changes: \"Hope on the Road Not Taken,\" \"Chapter One: The Game-crazed Kid,\" \"The Birth of the Emperor,\" and \"The Little Prince with Three Sisters.\"">]>, #<Nokogiri::XML::Element:0x48a9194 name="p" children=[#<Nokogiri::XML::Text:0x48a9022 "As of October 4, 2004:">]>, #<Nokogiri::XML::Element:0x48a8e92 name="p">, #<Nokogiri::XML::Element:0x48a8ce4 name="p" children=[#<Nokogiri::XML::Text:0x48a8af0 "The addition of e-sports organizations to major compani
@davelnewton
davelnewton / Orig.java
Last active September 27, 2015 23:07
Constructor vs. factories to enhance clarity an readability
// Most everything left out for clarity.
public class RPCRespond<Result> {
public RPCRespond() {
this.code = 0;
this.success = true;
this.result = null;
}
@davelnewton
davelnewton / 00_misuse.java
Created November 12, 2011 15:27
Stupid singleton is stupid
public class UsesLongRunningCtor {
/** Retrieves data and returns processed result. */
public String transformData() {
// LongRunningCtor "embedded"; direct reference, like a static utility class.
String rawData = LongRunningCtor.instance().fetch();
return rawData.replace("Raw", "Processed");
}
}
@davelnewton
davelnewton / menus.rb
Created November 17, 2011 03:09
Proc version of menu selection
#
# Not saying it's a good idea, but it's interesting.
#
# A Proc is just something you can call, with arguments.
p = Proc.new { |wat| puts wat }
p.call "ohai"
# => "ohai"