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 / 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);
}
class MonomeDemo
: public SerialOsc::Listener
{
public:
MonomeDemo(SerialOsc *osc)
: osc(osc)
{
osc->start(this);
}
@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;
@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 / 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')
class StateTransitionEvent
include Mongoid::Document
include Mongoid::Timestamps::Created
field :entity_type, type: String
field :entity_id, type: BSON::ObjectId
field :entity_attributes, type: Hash
field :event, type: String
field :from, type: String
field :to, type: String
def publish_event(event, prefix: '')
routing_key = build_routing_key(event, prefix)
payload = build_event_payload(event)
channel_pool.with do |channel|
channel.
topic(eventbus_exchange, durable: true).
publish(payload, routing_key: routing_key)
end
end

Keybase proof

I hereby claim:

  • I am daniel-bytes on github.
  • I am danielbytes (https://keybase.io/danielbytes) on keybase.
  • I have a public key ASDCF74YZgZPz3I55FBxL-8uimfBWg5Lq0xwFBFPq0-hbAo

To claim this, I am signing this object:

@daniel-bytes
daniel-bytes / Engine_GendyTutorial.sc
Last active September 23, 2018 16:07
Engine_GendyTutorial
Engine_GendyTutorial : CroneEngine {
var rez_x=100, rez_y=0.5, fill=50;
var <synth;
*new { arg context, doneCallback;
^super.new(context, doneCallback);
}
alloc {
SynthDef(\GendyTutorial, {|inL, inR, out, rez_x=100, rez_y=0.5|
@daniel-bytes
daniel-bytes / gendy-tutorial.lua
Created September 23, 2018 16:23
gendy-tutorial
engine.name = "GendyTutorial"
function init()
-- map our supercollider controls to norns parameters
params:add_control("x", controlspec.new(100,2000,"lin",0,0,""))
params:set_action("x", function(x) engine.x(x) end)
params:add_control("y", controlspec.new(0.01, 1.0,"lin",0,0,""))
params:set_action("y", function(x) engine.y(x) end)