Skip to content

Instantly share code, notes, and snippets.

View esmevane's full-sized avatar

Joseph McCormick esmevane

View GitHub Profile
@esmevane
esmevane / burrito.rb
Created March 24, 2014 14:42
[ Ruby ] Make a burrito
class Burrito
attr_reader :fillings
def initialize(*fillings)
@fillings = fillings
end
def to_hash
{ burrito: { filling: fillings.map(&:to_s) } }
end
@esmevane
esmevane / factory-strategy.rb
Created March 25, 2014 16:43
[ Strategy Pattern / Factory Pattern / MiniTest ] - Example strategy + factory use, with light minitest integration
require 'minitest/autorun'
require 'minitest/pride'
class ListStrategy
attr_reader :dates, :foods
def initialize list
foods = list.map { |item| item.keys.map(&:to_s) }
@dates = list.map { |item| item.fetch(:date) }
@foods = foods.flatten.uniq - ['date']
@esmevane
esmevane / app.coffee
Created May 28, 2014 19:48
[ Node / Javascript / Socket.io / Express ]: Chat demo
express = require 'express'
socket = require 'socket.io'
{ Server } = require 'http'
app = express()
http = Server app
io = socket http
app.get '/', (request, response) -> response.sendFile 'index.html'
io.on 'connection', (socket) -> console.log 'User connected'
@esmevane
esmevane / message_queue.rb
Created July 14, 2014 21:36
[ Ruby / Bunny / RabbitMQ ]: Lightweight Resque interface made via MessageQueue
require 'bunny'
require 'json'
require 'pry'
class MessageQueue
attr_reader :channel, :service, :queue
def initialize(service, channel)
@channel = channel
@service = service
@esmevane
esmevane / word_tally.rb
Created March 19, 2015 15:01
[ Ruby / Map Reduce ]: Count words, quick / naive
none_shall_pass = """
Flash that buttery gold, jittery zeitgeist
Wither by the watering hole, Border patrol
What are we to Heart Huckabee
Art fuckery suddenly
Not enough young in his lung for the water wings
Colorfully vulgar poacher, out of mulch
Like I'm a pull the pulse out a soldier and bolt
Fine, sign of the time we elapse
When a primate climb up a spine and attach
# Orig
def items options = Hash.new
products = true_category.descendant_products.available.visible
if options[:vendor]
products = products.by_vendor options[:vendor]
end
if options[:factor]
@esmevane
esmevane / example.html
Created May 17, 2012 15:06
Click warning example
<html>
<head>
<title>Checkbox Complete Demo</title>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
</head>
<body>
<form action="#" class="no-submit">
<h1>Show/hide submit based on whether a checkbox is checked or not</h1>
<p>
<h2>The scenario</h2>
class Example.Views.Table extends Backbone.View
template: JST['example/table']
initialize: ->
_.bindAll @, 'addOne', 'addAll'
@collection.on 'add', @addOne
render: ->
@$el.html @template()
%a.toggle-advanced{ href: '#' }
%span +
%strong Click here for advanced options
@esmevane
esmevane / raskell.rb
Created August 15, 2012 14:15 — forked from andkerosine/raskell.rb
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@