Skip to content

Instantly share code, notes, and snippets.

View esmevane's full-sized avatar

Joseph McCormick esmevane

View GitHub Profile
@esmevane
esmevane / .rubocop.yml
Last active April 27, 2016 19:43
[ YAML / Rubocop / Style ]: Rubocop configuration
AllCops:
Exclude:
- db/**/*
Style/FileName:
Enabled: false
StringLiterals:
Enabled: false
@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
@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 / jekyll-json.rb
Last active February 23, 2017 07:53
[ Jekyll / Ruby / Json ]: Generate json out of Jekyll posts
require 'json'
module Jekyll
module JsonContent
class Index < Jekyll::Page
attr_reader :page
def initialize site, base, dir, page
@site = site
@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 / 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 / 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
burrito-tropical=# select * from labels;
id | message_id | account_id | content | created_at | updated_at
-----+------------+------------+--------------------------------+------------+------------
441 | | | {1} | |
442 | | | {Inbox,Unread} | |
443 | | | {Inbox} | |
444 | | | {Request,Inbox,Papaya,Burrito} | |
445 | | | {Request,Inbox,Papaya,Burrito} | |
446 | | | {Request,Inbox,Papaya,Burrito} | |
447 | | | {Request,Burrito} | |
@esmevane
esmevane / movie-database-more-refactoring.rb
Created September 29, 2013 01:18
[ Ruby ] Example refactorings
class Choice
attr_reader :actions, :command
def initialize options = Hash.new
@actions = options.fetch(:actions) { Actions::List.new }
@command = options.fetch(:command) { :default }
end
def call movies
actions.for_choice(self).call movies
@esmevane
esmevane / singleton_example.coffee
Created September 3, 2013 23:28
[ CoffeeScript ] Singleton example with private functions
SingletonExample =
do ->
privateFunction = -> "I'm so hidden"
publicFunction = -> alert privateFunction()
publicFunction: publicFunction
SingletonExample.publicFunction()
alert SingletonExample.privateFunction()