Skip to content

Instantly share code, notes, and snippets.

View andrest's full-sized avatar
๐Ÿถ
feeding dogs

Andres Tuul andrest

๐Ÿถ
feeding dogs
  • New York
View GitHub Profile
@andrest
andrest / order.js
Created January 12, 2015 20:10
Double JOIN on the same table
app.get('/plans/:plan_id', function (req, res) {
models.Plan.find({
where: {id: req.param('plan_id')},
include: [
{
model: models.Order,
as: "pending_orders"
},
{
model: models.Order,
app.get('/plans/:plan_id', function (req, res) {
models.Plan.find({
where: {id: req.param('plan_id')},
include: [
{
as: "completed_orders",
model: models.Order,
where: {state: "completed"}
},
{
[18670:1231/171313:INFO:CONSOLE(171)] ""SENSOR_0:0.15"", source: file:///tmp/.org.chromium.Chromium.gUnbNB/frameless_window.js (171)
[18670:1231/171313:INFO:CONSOLE(178)] ""SENSOR_1:106.77"", source: file:///tmp/.org.chromium.Chromium.gUnbNB/frameless_window.js (178)
[18670:1231/171313:INFO:CONSOLE(185)] ""SENSOR_2:2.47"", source: file:///tmp/.org.chromium.Chromium.gUnbNB/frameless_window.js (185)
[18670:1231/171313:INFO:CONSOLE(192)] ""SENSOR_3:1.45"", source: file:///tmp/.org.chromium.Chromium.gUnbNB/frameless_window.js (192)
[18670:1231/171318:INFO:CONSOLE(171)] ""SENSOR_0:1.07"", source: file:///tmp/.org.chromium.Chromium.gUnbNB/frameless_window.js (171)
[18670:1231/171318:INFO:CONSOLE(178)] ""SENSOR_1:106.74"", source: file:///tmp/.org.chromium.Chromium.gUnbNB/frameless_window.js (178)
[18670:1231/171318:INFO:CONSOLE(185)] ""SENSOR_2:2.18"", source: file:///tmp/.org.chromium.Chromium.gUnbNB/frameless_window.js (185)
[18670:1231/171318:INFO:CONSOLE(192)] ""SENSOR_3:-2.9"", source: file:///tmp/.org.chromiu
@andrest
andrest / broken index.html
Last active August 29, 2015 14:12
The page content gets arbitrarily cut off (somewhere after __DATA__). In write.js the corresponding HTML string (with __DATA__) is not broken. Yet when received by the browser the end is chopped off. What's going on? Fix: added a solution below.
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Booster Labs</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="/styles.css"/>
</head>
<body>
Andres at and-mbp in ~/Projects/react-router-mega-demo on master
$ ./script/dev
Running node-supervisor with
program 'app.js'
--watch '.'
--extensions 'node,js'
--exec 'node'
Starting child process with 'node app.js'
@andrest
andrest / creator_widget.js.jsx
Created December 22, 2014 11:47
When route '/creator' is selected and the user clicks on the button (see creator_widget.js.jsx below) he's taken back to '/'. Why and how to prevent this?
var React = require('react');
var CreatorBox = module.exports = React.createClass({
render: function() {
return (
<a href="#" className="btn btn-default" role="button">Button</a>
)
}
})
@andrest
andrest / gist:a64649f128af1bd368ee
Created December 15, 2014 09:44
checkout_controller_decorator.rb
Spree::CheckoutController.class_eval do
def before_address
# If the user has a default address, a callback takes care of setting
# that; but if he doesn't, we need to build an empty one here.
# Regardless of checkout steps, build a shipping address
@order.bill_address ||= Spree::Address.build_default
@order.ship_address ||= Spree::Address.build_default
end
// This is how it's called
<SubscriptionBuilder handleCartClick={this.props.handleCartClick} cart_workout={ this.state.cart_workout } cart_rest={ this.state.cart_rest }/>
.
.
.
var SubscriptionBuilder = React.createClass({
render: function() {
var cart_items = function(product, index) {
var SupplementBox = React.createClass({
render: function() {
var content;
if (this.props.selected_supplement == null || typeof this.props.selected_supplement.master === "undefined") {
content = function(){
return(
<div></div>
)
var phidget = require('phidget');
var bridge = new phidget.bridge();
var scale = bridge.attach(function (err) {
console.log('\n0 ----------------\n');
console.log(phidget.getValue(350222, function(data){ console.log(data) }));
console.log('\n1 ----------------\n');
console.log(phidget.getValue(4, function(data){ console.log(data) }));
console.log('\n2 ----------------\n');
console.log(phidget.getValue(-1, function(data){ console.log(data) }));
console.log('\n3 ----------------\n');