Skip to content

Instantly share code, notes, and snippets.

@hmcq6
hmcq6 / Terrain.html
Created April 5, 2017 00:06
Terrain Generator. stolen from http://www.playfuljs.com/realistic-terrain-in-130-lines/ updated to ES6
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>Terrain Demo - PlayfulJS</title>
</head>
<body style='background: #000'>
<canvas id='display' width='1' height='1' />
<script>
// fdee_new_form.js
class FDEENewForm {
constructor(formSelector, inputSelector) {
this.$form = $(formSelector);
this.$form.on('ajax:beforeSend', this.$form.isValid /*(_xhr, _settings)*/)
.on('ajax:success', (_data, status, _xhr) => window.location = status.link)
.on('ajax:error', (_xhr, status, _error) => {
$.each(status.responseJSON, (field, messages) => {
FDE.Form.showError($(`input${inputSelector}_${field}`, this.$form), messages);
});
@hmcq6
hmcq6 / add.js
Last active March 1, 2017 19:55
// = require common
FDE.DrugClass.NewDrugClass = {
_selectors: {
submit: '.submit',
form: '#new_drug_class',
model: 'drug_class'
},
add() {
;
if (!FDE) {
let FDE = {};
}
FDE.Manufacturer = {
formSelector: '.manufacturer-form',
_handleErrors(_event, data, _error, _status) {
$.each(data.responseJSON, function(field, message) {
function sortNum(clickedIndex, sortDir) {
return function(x, y) {
const xVal = parseFloat(cellValue(x, clickedIndex)),
yVal = parseFloat(cellValue(y, clickedIndex));
return (xVal - yVal) * sortDir;
}
}
function sortString(clickedIndex, sortDir) { // sort rows
return function(x, y) {
'use strict';
const fs = require('fs');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const DRGBootstrapSASSPlugin = require('drg-bootstrap-sass');
const prod = process.argv.indexOf('-p') !== -1;
const CSS_OUTPUT_TEMPLATE = prod ? 'app/assets/stylesheets/[name]-[hash].css' : 'stylesheets/[name].css';
const JS_OUTPUT_TEMPLATE = prod ? 'app/assets/javascripts/[name]-[hash].js' : 'javascripts/[name].js';
@hmcq6
hmcq6 / components.timed-table.js
Last active January 10, 2017 16:25
3000 row table test
import Ember from 'ember';
export default Ember.Component.extend({
arr: [[]],
lastAttrUpdate: 0,
didUpdateAttrs() {
this._super();
this.set('lastAttrUpdate', performance.now());
},
didRender() {
@hmcq6
hmcq6 / components.child-component.js
Last active December 14, 2016 15:05
Evented Pattern
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement() {
this._super(...arguments);
this.changeColor();
this.get('eventedObject').on('default', function() {
this.changeColor();
}.bind(this));
},
@hmcq6
hmcq6 / controllers.application.js
Created December 8, 2016 01:04
DIY Dynamic Keys
import Ember from 'ember';
export default Ember.Controller.extend({
arr: [
{ id: 3, name: 'a' },
{ id: 1, name: 'b' },
{ id: 2, name: 'c' }
],
filterKey: 'name',
filterValue: 'c',
@hmcq6
hmcq6 / controllers.application.js
Last active November 17, 2016 17:17
Form + Text Input = Pain
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
noop: function() {}
}
});