Skip to content

Instantly share code, notes, and snippets.

View farmdawgnation's full-sized avatar
:shipit:

Matt Farmer farmdawgnation

:shipit:
View GitHub Profile
@farmdawgnation
farmdawgnation / example1.rb
Created November 17, 2012 04:31
Examples for Blog Post on 11/16
class ParentThing < ActiveRecord::Base
include SecureThingBehavior
# Make the storage location of all our secure things accessible
# along with whatever else you need.
attr_accessible :secure
end
class ThingA < ParentThing
attr_secure :meeting_location, :meeting_passcode
def test1
[1,2,3,4,5].each do |item|
next if item == 3
puts item
end
end
def test2
[1,2,3,4,5].each do |item|
@farmdawgnation
farmdawgnation / Contact.scala
Last active December 10, 2015 02:58
The ContactSerializer for use with the Constant Contact API I'm developing.
case class ContactPhones( home_phone:Option[String] = None, work_phone:Option[String] = None,
cell_phone:Option[String] = None)
case class ContactName( first_name:Option[String] = None, middle_name:Option[String] = None,
last_name:Option[String] = None)
case class Contact(email_addresses:List[EmailAddress], action_by:String, id:Long = 0,
status:Option[Status.Value] = None, prefix_name:Option[String] = None,
name:Option[ContactName] = None, job_title:Option[String] = None,
department_name:Option[String] = None, company_name:Option[String] = None,
phone:Option[ContactPhones] = None, fax:Option[String] = None,
addresses:List[Address] = List(), notes:List[Note] = List(),
@farmdawgnation
farmdawgnation / gist:5074718
Last active December 14, 2015 10:49
A Lift response transformer and some CoffeeScript helpful for facilitating cross-domain AJAX requests in Lift.
// If we receive a jQuery JSONP call and we don't call the callback, add in a bogus
// call to the callback function.
LiftRules.responseTransformers.append { response =>
response.toResponse match {
case resp @ InMemoryResponse(data, headers, _, _) =>
{
for(callback <- S.param("callback")) yield {
val dataStr = new String(data)
if (! dataStr.contains(callback)) {
@farmdawgnation
farmdawgnation / animals-2.scala
Last active December 16, 2015 18:20
Examples for Lift and Mongo Post
import net.liftweb.mongodb._
import BsonDSL._
trait Animal {
def makeNoise(): String
}
case class Dog(name: String, breed: String) extends Animal {
def makeNoise() = {
"Woof"
@farmdawgnation
farmdawgnation / gist:5666802
Created May 28, 2013 23:01
Some of the specs for the Anchor Tab API.
describe("GET /api/v1/embed/*") {
it("should return 200 and a jscmd for a valid tab id") {
runApiRequest("/api/v1/embed/" + validTab._id.toString, None, _.parameters = List("callback" -> "123")) { response =>
response match {
case Full(JavaScriptResponse(jscmd, _, _, code)) =>
code should equal (200)
case somethingUnexpected => fail(somethingUnexpected.toString)
}
}
@farmdawgnation
farmdawgnation / iptablesload
Created December 22, 2013 04:57
IP Tables Load.
#!/bin/sh
iptables-restore < /etc/iptables.rules
ip6tables-restore < /etc/ip6tables.rules
exit 0
@farmdawgnation
farmdawgnation / BinarySearch.cpp
Last active January 1, 2016 16:39
Hilariously primitive implementations of Binary Search Tree and Linked List I found on an old CD-ROM from High School. Written in Visual-C++. Circa 2005.
#include "StdAfx.h"
#include ".\binarysearch.h"
#include <stdlib.h>
#include <stdio.h>
BSNode::BSNode() {
this->lessThan = NULL;
this->greaterThan = NULL;
}
@farmdawgnation
farmdawgnation / server.sh
Created January 18, 2016 22:13
A little lightweight server management script I wrote
#!/bin/bash
command -v aws >/dev/null 2>&1 || { echo >&2 "I require the AWS cli, but it is not installed."; exit 1; }
command -v jq >/dev/null 2>&1 || { echo >&2 "I require jq, but it is not installed."; exit 1; }
#export AWS_ACCESS_KEY_ID=ACCESS_KEY_HERE_IF_NOT_ALREADY_IN_ENVIRONMENT
#export AWS_SECRET_ACCESS_KEY=SECRET_KEY_HERE_IF_NOT_ALREADY_IN_ENVIRONMENT
#export AWS_DEFAULT_REGION=REGION_HERE_IF_NOT_ALREADY_IN_ENVIRONMENT
INSTANCE_ID=INSTANCE_ID_HERE
version: 2
myservice:
image: ubuntu:15.10
environment:
- DOCKER_TLS_VERIFY
- DOCKER_HOST
- DOCKER_CERT_PATH