Skip to content

Instantly share code, notes, and snippets.

View jefflunt's full-sized avatar
🌴
On vacation

Jeff Lunt jefflunt

🌴
On vacation
View GitHub Profile
@jefflunt
jefflunt / open_notification.rb
Created March 15, 2011 15:51
models/controllers for FeelGoodTrader.com notification system
class OpenNotification < ActiveRecord::Base
belongs_to :user
belongs_to :listing
validates_presence_of :user_id
validates_presence_of :listing_id
validates_uniqueness_of :listing_id, :scope => :user_id
validate :a_user_cannot_get_a_notification_for_their_own_listing
@jefflunt
jefflunt / gist:1043635
Created June 23, 2011 21:09
Sample XML for StackOverflow question
XML response for the main grid (translationsFeed):
<?xml version='1.0' encoding='utf-8'?><rows><page>1</page><total>1</total><records>10</records><row id='2'><cell><![CDATA[2]]></cell><cell><![CDATA[6]]></cell><cell><![CDATA[EN]]></cell><cell><![CDATA[Cheese]]></cell><cell><![CDATA[It's cheesy goodness!]]></cell><cell>2011-06-20 14:53:52</cell><cell>2011-06-23 12:28:39</cell><cell><![CDATA[No]]></cell></row><row id='1'><cell><![CDATA[1]]></cell><cell><![CDATA[]]></cell><cell><![CDATA[EN]]></cell><cell><![CDATA[Hello!]]></cell><cell><![CDATA[]]></cell><cell></cell><cell></cell><cell><![CDATA[No]]></cell></row><row id='5'><cell><![CDATA[5]]></cell><cell><![CDATA[]]></cell><cell><![CDATA[EN]]></cell><cell><![CDATA[How are you feeling today?]]></cell><cell><![CDATA[]]></cell><cell></cell><cell></cell><cell><![CDATA[No]]></cell></row><row id='4'><cell><![CDATA[4]]></cell><cell><![CDATA[]]></cell><cell><![CDATA[EN]]></cell><cell><![CDATA[How much does this cost?]]></cell><cell><![CDATA[]]></cell><cell></cell><cell
@jefflunt
jefflunt / summarized order.rb
Created May 15, 2013 18:24
Order model - after
class Order < ActiveRecord::Base
# This array includes the list of possible states that an Order can be in. These reflect the steps
# that an order goes through from placement to fulfilment.
#
# nil The initial state of any Order record
# checking_terminals Checking if the terminals involved in this order are online
# terminals_offline One of more of the printers/terminals for this order are offline
# charging Attempting to charge the customer's credit card via BrainTree
# failed_to_charge BrainTree returned an error
@jefflunt
jefflunt / summarized order.rb
Created May 15, 2013 18:24
Order model - before
class Order < ActiveRecord::Base
...
after_initialize :init
before_validation :can_be_placed?
before_save :process_transaction, :on => :create
validates :customer_id,
:company_id,
@jefflunt
jefflunt / gist:6098923
Last active December 20, 2015 08:09
Sample SSH config
# What ports, IPs and protocols we listen for
Port 22
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
UsePrivilegeSeparation yes
@jefflunt
jefflunt / syslog
Created August 16, 2013 16:06
PPTP debug log
pi@pi ~ $ tail -n 10000 /var/log/syslog
Aug 6 15:40:00 pi pppd[1479]: Connection terminated.
Aug 6 15:40:00 pi avahi-daemon[2868]: Withdrawing workstation service for ppp0.
Aug 6 15:40:00 pi pppd[1479]: using channel 1815
Aug 6 15:40:00 pi pppd[1479]: Using interface ppp0
Aug 6 15:40:00 pi pppd[1479]: Connect: ppp0 <--> /dev/pts/0
Aug 6 15:40:00 pi pptp[14671]: anon fatal[get_ip_address:pptp.c:437]: getaddrinfo(): Name or service not known
Aug 6 15:40:00 pi pppd[1479]: Script pptp [VPN SERVER IP] --nolaunchpppd --debug finished (pid 14670), status = 0x1
Aug 6 15:40:00 pi pppd[1479]: Modem hangup
Aug 6 15:40:00 pi pppd[1479]: Connection terminated.
@jefflunt
jefflunt / pptp-conf
Created August 16, 2013 16:41
pptp config file
[lines containing credentials and VPN server IP address excluded]
remotename PPTP
require-mppe-128
require-mschap-v2
refuse-eap
refuse-pap
refuse-chap
refuse-mschap
noauth
@jefflunt
jefflunt / game.rb
Created November 21, 2013 19:58
Bowling game scorer with visual score output and per-frame or aggregate scoring.
# Contains a list of rolls that a bowling player throws, and from that can tell
# you the score of the game in progress or finished, the visual score (with 'X'
# and '/', etc.), and the score of any frame within the game.
#
# Examples:
#
# > g = Game.new
# => []
#
# > g.roll(3)
@jefflunt
jefflunt / order.rb
Last active January 3, 2016 01:09
Writing tests for AR validations
class Order < ActiveRecord::Base
...
validates :customer_id,
:company_id,
:credit_card_id,
:tip,
:delivery_location,
presence: true
@jefflunt
jefflunt / Gemfile
Created February 23, 2014 23:36
Basic ruby script to pull active listings and match against a strategy every 300 milliseconds (max)
source "https://rubygems.org"
gem 'curb'