Skip to content

Instantly share code, notes, and snippets.

@jamesmenera
jamesmenera / Direct Select
Last active January 7, 2020 02:01
Hacky way to add a placeholder/ empty value on flutter direct-select package
// Create a few methods to build the direct select that take additional options to add the placeholder
// and account for the changed index of doing this
// These are the following 3 methods
DirectSelectItem<String> _getDropDownMenuItem(value) {
return DirectSelectItem<String>(
key: ValueKey(new DateTime.now()),
itemHeight: 60,
value: value,
itemBuilder: (context, value) {
import Ember from 'ember';
const {
Component
} = Ember;
export default Component.extend({
tagName: 'grid-data-column',
classNames: ['grid-data-column']
});
import Ember from 'ember';
export default Ember.Component.extend({
attrCnt: 0,
didReceiveAttrs(...args) {
this._super(...args);
this.incrementProperty('attrCnt');
}
import Ember from 'ember';
export default Ember.Controller.extend({
date: null
});
import DS from 'ember-data';
import Ember from 'ember';
let attr = DS.attr,
belongsTo = DS.belongsTo,
hasMany = DS.hasMany;
export default DS.Model.extend({
firstName: attr(),
lastName: attr(),
// 1. Write a class to support the following code:
Person = function(name){
this.name = name;
console.log('name');
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
// Part 1.
// Implement a function prototype extension that caches function results for
// the same input arguments of a function with one parameter.
//
// For example:
// Make sin(1) have the result of Math.sin(1), but use a cached value
// for future calls.
//
// Part 2.
// Use this new function to refactor the code example.
@jamesmenera
jamesmenera / gist:5111655
Last active December 14, 2015 15:58
Homework 1
// Exercise 1 - OO || !OO
// Define a data structure for cars (make and color), and a function
// that logs a string like "I'm a red Mercedes" to the console.
// Make two versions: a functional version, and a object-oriented version.
//Two solutions, one with a constructor only, and one using prototypes
// Example call for functional version:
var logCar = function(car) {
console.log('I\'m a ' + car.color + ' ' + car.make);
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
var index = (function log(){
console.log(index);
}
function iterate(){
log();
// taken from http://www.dreamincode.net/code/snippet154.htm
//
// Find the weaknesses, and clean up the code.
// Find at least 3 things you can make better!
//
// Test numbers (return true):
// 4111111111111111
// 378282246310005
// 5555555555554444