Skip to content

Instantly share code, notes, and snippets.

View daniel-bytes's full-sized avatar
💭
👾

Daniel Battaglia daniel-bytes

💭
👾
View GitHub Profile
@daniel-bytes
daniel-bytes / product_update.rb
Last active January 5, 2018 22:01
Mutation to update an existing product
module Products
class Update < Mutations::Command
required do
model :product
integer :adjust_inventory
end
def validate
if adjust_inventory == 0
return add_error(:adjust_inventory, :invalid, 'Inventory adjustment factory cannot be zero')
@daniel-bytes
daniel-bytes / product.rb
Last active January 8, 2018 15:45
Product model with AASM state machine
class Product
include Mongoid::Document
include Mongoid::Timestamps
include AASM
field :name, type: String
field :state, type: String
field :price, type: Integer
field :inventory, type: Integer, default: 0
@daniel-bytes
daniel-bytes / gist:8270692
Created January 5, 2014 16:56
serialosc start method
void SerialOsc::start(Listener *listener)
{
this->listener = listener;
if (listener == nullptr || listenSocket != nullptr) {
return;
}
for (int i = 0; i < portsToScan; i++) {
int tempPort = listenPort + i;
class MonomeDemo
: public SerialOsc::Listener
{
public:
MonomeDemo(SerialOsc *osc)
: osc(osc)
{
osc->start(this);
}
@daniel-bytes
daniel-bytes / gist:8270297
Created January 5, 2014 16:27
serialosc_example main function
int main(int argc, const char* argv[])
{
std::string input;
SerialOsc osc("test", 13000);
MonomeDemo device(&osc);
while (input != "q") {
std::cout << "type 'q' to quit." << std::endl;
std::getline(std::cin, input);
}