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 / 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'
@jefflunt
jefflunt / gist:c382083c7b8853974437
Last active August 29, 2015 14:01
Handling hashes
> text = 'some text'
=> "some text"
> hash_options = {rant_id:1,date:11/04/2014,top:text,number:12}
=> {:rant_id=>1, :date=>0, :top=>"some text", :number=>12}
NOTE that 'date' gets set to zero, because it's being interpreted as, "11 divided by 04 divided by 2014"
Also this:
> hash_options = rant_id:1,date:11/04/2014,top:text,number:12
@jefflunt
jefflunt / foobar
Last active August 29, 2015 14:06
"""
The FooBar Card Game!
The game is simple:
1. Start a deck of cards
2. Shuffle the deck
3. Every player has a "hand" - a list of cards they are holding
4. Deal all cards from the deck as evenly as possible to all players
5. Score the cards - the player with the highest score WINS!"
@jefflunt
jefflunt / animals
Last active August 29, 2015 14:06
animal-module
def cow():
"""See: http://en.wikipedia.org/wiki/Cattle"""
return {
'sound': 'moo',
'legs': 4,
'covering': 'hair'
}
def horse():
"""See: http://en.wikipedia.org/wiki/Horse"""
@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 - 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 / 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 / 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.