Skip to content

Instantly share code, notes, and snippets.

View jtompkins's full-sized avatar

Joshua Tompkins jtompkins

View GitHub Profile
class LinkedList {
static fromString(str) {
return [...str].reduce((acc, next) => acc.shift(next), new LinkedList())
}
constructor(initial) {
this.head = initial ? new ListNode(initial) : null
}
shift(value) {

Keybase proof

I hereby claim:

  • I am jtompkins on github.
  • I am jtompkins (https://keybase.io/jtompkins) on keybase.
  • I have a public key ASCxAEngryCvn9I-QmqIvdm5Y5HCGwFB9sRDu0oDABDy8Ao

To claim this, I am signing this object:

@jtompkins
jtompkins / todo.rb
Last active November 4, 2016 02:07
A sample of the new Rbdux API.
require 'rbdux'
Rbdux::configure do
store Rbdux::Stores::MemoryStore.with_state do
visibility: :hide_completed,
todos: []
end
actions do
define :toggle_visibility
@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
@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 / 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: "*"
}

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 / 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) {
@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