Skip to content

Instantly share code, notes, and snippets.

View sj26's full-sized avatar
🤹‍♂️

Samuel Cochran sj26

🤹‍♂️
View GitHub Profile
@sj26
sj26 / smtp_to_web.rb
Created March 3, 2014 06:13
Post to a web service whenever an email is received
require "eventmachine"
require "httparty"
class SmtpServer < EventMachine::Protocols::SmtpServer
# We override EM's mail from processing to allow multiple mail-from commands
# per [RFC 2821](http://tools.ietf.org/html/rfc2821#section-4.1.1.2)
def process_mail_from sender
if @state.include? :mail_from
@state -= [:mail_from, :rcpt, :data]
receive_reset
@sj26
sj26 / ruby-2.0.0-p451-readline.patch
Created April 16, 2014 06:14
Ruby 2.0.0-p451 readline patch
diff -ur orig/ext/readline/readline.c fixed/ext/readline/readline.c
--- orig/ext/readline/readline.c 2014-03-18 13:53:31.866359527 +0100
+++ fixed/ext/readline/readline.c 2014-03-18 13:56:26.390247250 +0100
@@ -1883,7 +1883,7 @@
rl_attempted_completion_function = readline_attempted_completion_function;
#if defined(HAVE_RL_PRE_INPUT_HOOK)
- rl_pre_input_hook = (Function *)readline_pre_input_hook;
+ rl_pre_input_hook = (rl_hook_func_t *)readline_pre_input_hook;
#endif
@sj26
sj26 / ruby-2.1.1-p0-readline.patch
Created April 16, 2014 06:14
Ruby 2.1.1-p0 readline patch
From 4c4da3fc650a3595ecc06f49072f1ffae07db706 Mon Sep 17 00:00:00 2001
From: Thomas Dziedzic <gostrc@gmail.com>
Date: Sat, 1 Mar 2014 21:41:28 -0800
Subject: [PATCH] Fix undeclared identifier error by using the actual type of
rl_pre_input_hook
---
ext/readline/readline.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
App =
firstFunction: ->
doesSomething(or: other)
secondFunction: ->
somethingElse
usesClassesToo: ->
@behaviour = new App.RepeatedBehavoiur(or: other)
@anotherBehaviour = new App.RepeatedBehavoiur(and: another)
@sj26
sj26 / keybase.md
Created June 13, 2014 04:29
Keybase

Keybase proof

I hereby claim:

  • I am sj26 on github.
  • I am sj26 (https://keybase.io/sj26) on keybase.
  • I have a public key whose fingerprint is 2948 206E 98F5 A539 96F5 4211 1A36 ACA1 BDEC D23E

To claim this, I am signing this object:

require "stringio"
require "cucumber/formatter/pretty"
# Instafail-style output which displays dots for success and writes
# verbose failure information in a single block so multi-process
# output interleaves nicely.
class Instacuke < Cucumber::Formatter::Pretty
def initialize(*)
super
@actualio = @io
##################### Elasticsearch Configuration Example #####################
# This file contains an overview of various configuration settings,
# targeted at operations staff. Application developers should
# consult the guide at <http://elasticsearch.org/guide>.
#
# The installation procedure is covered at
# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>.
#
# Elasticsearch comes with reasonable defaults for most settings,
@sj26
sj26 / README.md
Last active August 29, 2015 14:05

@simpsora: any suggestions for a good way to parse multi-line messages in ruby? have command output which consists of blocks of 3 lines each, need to process each block together @sj26: maybe using scan and multiline regex?

$ ruby multiline.rb multiline.txt
["thing", "whatsit"]
["thang", "poppy"]
["thung", "scooby doo"]
["thong", "shaggy"]
@sj26
sj26 / lenient_csv.rb
Last active August 29, 2015 14:06
Ruby CSV parser support RFC 4180 double double-quote and unix-style backslash escaping
require "strscan"
class LenientCSV
def initialize(source)
@scanner = StringScanner.new(source)
end
def each
until @scanner.eos?
yield scan_row
@sj26
sj26 / user.rb
Last active August 29, 2015 14:07
Business rule validation
# CREATE TABLE users (id INT NOT NULL AUTO_INCREMENT, age INT UNSIGNED, PRIMARY KEY id)
class User < ActiveRecord::Base
# column gives us age / age=
validates :age, presence: true, may_serve_alcohol: true
end
class MayServeAlcoholValidator < ActiveModel::EachValidator
def validate_each(model, attribute, value)
if model[attribute].present? && model[attribute] < 18