Skip to content

Instantly share code, notes, and snippets.

Sean Devine barelyknown

Block or report user

Report or block barelyknown

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@barelyknown
barelyknown / query-all-mixin.js
Created Nov 28, 2017
Example mixin that queries for all records using Ember data, one page at a time.
View query-all-mixin.js
import Mixin from '@ember/object/mixin';
import { inject } from '@ember/service';
import { get } from '@ember/object';
import { task } from 'ember-concurrency';
const PAGE_LIMIT = 10;
// Mixin anywhere you'd like to query for all records that match
// a filter, one page at a time. This can be helpful anywhere you need
// need all records loaded, but don't want to hit the server with long
// running requests.
View comparison_validator.rb
class ComparisonValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if options[:allow_blank] && value.blank?
return if options[:allow_nil] && value.nil?
unless comparison_attribute = options[:attribute]
raise ArgumentError, "missing attribute option"
end
unless operator = options[:operator]
@barelyknown
barelyknown / contributor_first_names.csv
Created Sep 2, 2016
The first names of contributors to The Information as of September 1, 2016.
View contributor_first_names.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
first_name
Aaron
Aaron
Abhilash
Adam
Adam
Adam
Adam
Adam
Aditya
View optimize-roster-3.js
function setSolution(solution) {
// for each player
for (var row = 1; row <= PLAYERS.getNumRows(); row++) {
var playerId = PLAYERS.getCell(
row,
PLAYERS_PLAYER_COLUMN
).getValue();
// set the selected column based on the optimization solution
PLAYERS.getCell(
View optimize-roster-2.js
function addSalaryCapConstraint(engine) {
// add a constraint for the overall salary cap
var salaryCapConstraint = engine.addConstraint(0, SALARY_CAP);
// for each player
for (var row = 1; row <= PLAYERS.getNumRows(); row++) {
var player = PLAYERS.getCell(
row,
PLAYERS_PLAYER_COLUMN
).getValue();
View optimize-roster-1.js
function addPositionConstraints(engine) {
// for each position
for (var row = 1; row <= POSITIONS.getNumRows(); row++) {
var position = POSITIONS.getCell(
row,
POSITIONS_POSITION_COLUMN
).getValue();
var positionSpots = POSITIONS.getCell(
row,
POSITIONS_SPOTS_COLUMN
View optimize-roster-0.js
function addVariables(engine) {
// for each player
for (var row = 1; row <= PLAYERS.getNumRows(); row++) {
var player = PLAYERS.getCell(
row,
PLAYERS_PLAYER_COLUMN
).getValue();
var projectedPoints = PLAYERS.getCell(
row, PLAYERS_PROJECTED_POINTS_COLUMN
).getValue();
View optimize-roster.js
function optimizeRoster() {
// this sets engine to an instance of Google's LP/MIP solver
var engine = LinearOptimizationService.createEngine();
// clear previous selections from the Players worksheet
clearPreviousSelections();
// add the variables (players and their salaries)
// to the optimization problem
addVariables(engine);
@barelyknown
barelyknown / authenticate-in-ember-using-a-url-parameter-4.js
Created Dec 1, 2015
authenticate-in-ember-using-a-url-parameter-4.js
View authenticate-in-ember-using-a-url-parameter-4.js
import ApplicationController from './application';
ApplicationController.reopen({
unsetToken: Ember.observer('token', function() {
if (this.get('token')) {
Ember.run.next(this, function() {
this.set('token', null);
});
}
})
@barelyknown
barelyknown / authenticate-in-ember-using-a-url-parameter-3.js
Created Dec 1, 2015
authenticate-in-ember-using-a-url-parameter-3.js
View authenticate-in-ember-using-a-url-parameter-3.js
// app/routes/application.js
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin, {
session: Ember.inject.service('session'),
isTokenAuthenticating: null,
model(params) {
You can’t perform that action at this time.