Skip to content

Instantly share code, notes, and snippets.

View Bestra's full-sized avatar
😃

Chris Westra Bestra

😃
  • GitHub
  • Columbus, OH
  • 23:40 (UTC -05:00)
  • X @_Bestra
View GitHub Profile
@Bestra
Bestra / parse_schema.exs
Created April 24, 2019 12:10
Parse a schema.rb file and make ecto schemas from it
defmodule Mix.Tasks.CreateSchemaFromRails do
use Mix.Task
defmodule EctoPrinter do
def build_string(module_name, %{name: table_name, body: body}) do
model_name =
table_name
|> String.trim_trailing("s")
|> Macro.camelize()
@Bestra
Bestra / element-collection.ts
Last active August 17, 2018 18:51
Angular page object decorators
/**
* Creates a getter for the given css selector
* that will return a native element
* @param selector A css selector string
*/
export function element(selector: string) {
return function(target: any, key: string) {
delete target[key];
Object.defineProperty(target, key, {
@Bestra
Bestra / controllers.application.js
Last active September 22, 2017 20:49
Rolodex Test Page
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'A Really Simple Rolodex',
newEntry: null,
entries: Ember.computed.alias('model'),
showForm: false,
actions: {
addEntry() {
@Bestra
Bestra / components.if-dynamic.js
Last active August 4, 2017 20:55
Dynamic property names
import Ember from "ember";
export default Ember.Component.extend({
staticValue: Ember.computed("condition", "scenario", function() {
let key = this.get("condition");
return this.get("scenario").get(key);
}),
init() {
this._super(...arguments);
@Bestra
Bestra / add-super-calls.js
Last active March 7, 2017 15:14
codemod for adding this._super() calls to component lifecycle hooks
/**
To use this file you'll need to have `jscodeshift` (https://github.com/facebook/jscodeshift)
installed, which you can get through npm or yarn.
You can invoke it as follows:
`jscodeshift -t add-super-calls.js ~/path/to/js/files/`
You can pass `-d` to do a dry-run.
*/
const hookNames = [
'init',
'didInitAttrs',
@Bestra
Bestra / controllers.foods.js
Last active June 20, 2022 06:06
Debugging Route Hook
import Ember from 'ember';
export default Ember.Controller.extend({
queryParams: ['foodId'],
foodId: null,
});
@Bestra
Bestra / components.accordion-item.js
Last active July 17, 2019 01:56
Generic Accordion
// components/accordion-item.js
import Ember from 'ember';
export default Ember.Component.extend({
item: null,
activeItem: null,
isExpanded: Ember.computed('activeItem', 'item', function() {
return this.get('activeItem') === this.get('item');
import Ember from 'ember';
export default Ember.Component.extend({
item: null,
openItem: null,
isOpen: Ember.computed('item', 'openItem', function() {
return this.get('item') === this.get('openItem');
}),
classNames: ['item'],
// components/accordion-item.js
import Ember from 'ember';
export default Ember.Component.extend({
item: null,
activeItem: null,
isExpanded: Ember.computed('activeItem', 'item', function() {
return this.get('activeItem') === this.get('item');
@Bestra
Bestra / components.accordion-item.js
Last active September 17, 2016 11:38
List with Add
// components/accordion-item.js
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'div',
item: null, // passed-in
isExpanded: Ember.computed('activeItem', 'item', function() {
return this.get('activeItem') === this.get('item');
})