Skip to content

Instantly share code, notes, and snippets.

View jtompkins's full-sized avatar

Joshua Tompkins jtompkins

View GitHub Profile
// taken from http://www.dreamincode.net/code/snippet154.htm
//
// Find the weaknesses, and clean up the code.
// Find at least 3 things you can make better!
//
// Test numbers (return true):
// 4111111111111111
// 378282246310005
// 5555555555554444
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
function(container) {
var index;
function log(){
console.log(index);
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
function(container) {
var index;
function log(){
console.log(index);
@jtompkins
jtompkins / gist:3927218
Created October 21, 2012 15:08
Just a little project I'm working on...
var b = new QueryBuilder();
var select = b.Select(columns: "id, name, price", from: "products", as: "p");
var select2 = b.Select(columns: "id, discount, name", from: "sales", as: "s");
b.Join(left: select, right: select2, on: new { s: "productId", p: "Id", operation: Operations.Equals });
//or
b.LeftOuterJoin(left: select, right: select2, on: new { s: "productId", operation: Operations.Equals, p: "Id });
select.Where(column: "name", operation: Operations.Equals, value: "josh");
@jtompkins
jtompkins / Messenger.coffee
Created February 17, 2014 19:39
A simple message dispatcher in Coffeescript. This is a very naive implementation and probably doesn't do everything you'd want a message dispatcher to do. On the other hand, it's under 30 lines of code.
class Messenger
constructor: ->
@subs = {}
register: (type, caller, func) =>
return unless type? and caller? and func?
@subs[type] = [] unless @subs[type]?
existing = null
@jtompkins
jtompkins / inline.js
Created February 17, 2014 19:46
This is code I regret writing. It's inline in the page, it pollutes the global namespace, it switches randomly between underscore.js and jquery, and it uses both badly.
<script type="text/javascript">
function createColumn() {
return $('<div class="column"></div>');
}
function createBlock() {
return $('<div class="block"></div>');
}
function isLarge(tile) {

Keybase proof

I hereby claim:

  • I am jtompkins on github.
  • I am jtompkins (https://keybase.io/jtompkins) on keybase.
  • I have a public key whose fingerprint is 7EDE 61F3 187D 39F1 14A1 55A8 B452 25A8 1076 E60D

To claim this, I am signing this object:

@jtompkins
jtompkins / fp-simfrost.rb
Last active August 29, 2015 14:19
RubyQuiz #117 - SimFrost
# A weird, mostly ugly, kind of functional-programming-ish solution
# to RubyQuiz #117:
# http://rubyquiz.com/quiz117.html
STATES = {
vacuum: " ",
vapor: ".",
frost: "*"
}
@jtompkins
jtompkins / todo.rb
Last active July 12, 2016 15:40
TodoMVC - for the command line! ...in Ruby!
require_relative '../../lib/action'
require_relative '../../lib/store'
Todo = Struct.new(:text, :completed)
class CommandProcessor
def parse_command(text)
command_array = text.split(' ')
case command_array[0]
@jtompkins
jtompkins / class_syntax.rb
Last active September 8, 2016 03:45
Some examples of the various possibilities for Codependent configuration.
class ARepository
extend Codependent::Helper
singleton :a_repository, in_scope: :a_test_scope do
with_constructor { ARepository.new }
depends_on :logger, :another_repository
end
attr_accessor :logger, :another_repository
end